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:
- CLI
- Jenkins
- Maven Plugin
- Micro Radiant
Contributing
See Creating rules for creating custom rules.
Usage
There are several ways to run the model-validations:
- Maven
- µRadiant
- CLI
- Jenkins
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>
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
.
Since µRadiant version 1.8.0, the validations run in the model editor. Validation Issues will be shown as badges on the tabs and in the tree view.
You can select the validations
tab to list all issues for an element.
You can also run the model-validations jar directly. The jar has a command line interface which can be used to run the validations:
mvn -U dependency:copy "-Dartifact=net.democritus.model:model-validations:RELEASE:jar:jar-with-dependencies" "-DoutputDirectory=." "-Dmdep.stripVersion=true" "-Dmdep.stripClassifier=true"
java -jar model-validations.jar --help
java -jar model-validations.jar \
--expansionSettings conf/expansionSettings.xml \
--stdout \
--html target/validation-report.html \
--junit target/validation-report.xml
Example stage in Jenkins.
stage('validate') {
steps {
modelValidations pomFile: 'pom-expansion.xml'
}
}
Output Formats
When running from Maven or Command Line, you can select one or more output formats.
stdout
Prints issues to the terminal.
- Maven
- CLI
mvn expanders:validate-model -Dvalidation.print
java -jar model-validations.jar --stdout
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.
- Maven
- CLI
mvn expanders:validate-model -Dvalidation.junit=target/validation-report.xml
java -jar model-validations.jar --junit target/validation-report.xml
HTML
Generates a HTML validation report.
- Maven
- CLI
mvn expanders:validate-model -Dvalidation.html=target/validation-report.html
java -jar model-validations.jar --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.