Skip to main content

Model Validations

Latest release: 3.7.0


Model-validations allow you to run automated validations on your model to find any issues or possibilities for improvements.

The validations are implemented with Rules which are checked on each element in your Model. The result are combined into a report, which can be an HTML report or a JUnit xml report.

Usage:

Contributing

See Creating rules for creating custom rules.

Usage

There are several ways to run the model-validations:

You can run the validations with the expanders-maven-plugin (version 2022.0.1 and up):

mvn -f pom-expand.xml expanders:validate-model -Dvalidation.html=report.html -Dvalidation.junit=report.xml -Dvalidation.print=true

You can also configure the plugin in the pom-expand.xml:

<plugin>
<groupId>net.democritus.maven.plugins</groupId>
<artifactId>expanders-maven-plugin</artifactId>
<version>2024.6.1</version>
<configuration>
<htmlReport>report.html</htmlReport>
<junitReport>report.xml</junitReport>
</configuration>
</plugin>
error rules

If any rule with priority error fails, the validate-model goal will fail. This is to stop builds of invalid projects, since these issues will probably cause expansion or compilation errors down the line.

This can be disabled by passing the argument -Dvalidation.failIfError=false.

Output Formats

When running from Maven or Command Line, you can select one or more output formats.

stdout

Prints issues to the terminal.

mvn expanders:validate-model -Dvalidation.print

produces

rules:
- deprecation:
- Deprecated:
- net.democritus.elements.validations.FieldIsStatusFieldRule:
reason: Status field will be determined using "isStatusField" option only. Fields with name "status" and type "String" should contain "isStatusField" option to preserve functionality.
description: Status field will be determined using "isStatusField" option only. Fields with name "status" and type "String" should contain "isStatusField" option to preserve functionality.
issues:
- <Field atodoComp::Duration::status> is missing "isStatusField" option
- <Field atodoComp::TaskAssignment::status> is missing "isStatusField" option

JUnit

Generates JUnit-compatible XML report file.

mvn expanders:validate-model -Dvalidation.junit=target/validation-report.xml

HTML

Generates a HTML validation report.

mvn expanders:validate-model -Dvalidation.html=target/validation-report.html

Rules provided by expansion-resources

The validation rules are packaged as expansion-resources. These resources need to be added to your expansionSettings.xml to use them to validate your model.

E.g. to add basic validations for a standard NS application:

  <expansionResources>
...
<expansionResource name="net.democritus.validations.model:prime-validations" version="3.7.0"/>
</expansionResources>

Filter Reports

If you want to suppress rules, specific elements, or specific issues.

Create conf/validation.xml file to define your excludes.

<validation xmlns="https://schemas.normalizedsystems.org/xsd/model-validations/1/0/0/validation">
<excludes>
<exclude>
<!-- glob against rule className -->
<rule>DataCommandHasLogRule</rule>
<!-- no elements specified, ignore all -->
</exclude>

<exclude>
<!-- glob against rule className -->
<rule>FieldCollectionRequiresBaseFieldRule</rule>
<elements>
<!-- DataRef; exact match, no pattern/glob -->
<element>expansionControl::ExpansionGoal::expansionTargetElements</element>
<element>expansionControl::ExpansionGoal::expansionTargetElementTypes</element>
</elements>
</exclude>

</excludes>
</validation>

Re-run validation. The file conf/validation.xml will be automatically picked up.