Model Validations

Latest release: 2.1.1


Validate your NS models.

Usage:

Contributing

See Creating rules for creating custom rules.

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="2.0.2"/>
  </expansionResources>

Command Line Usage

1. Grab the latest release version.

mvn -U dependency:copy "-Dartifact=net.democritus.model:model-validations:RELEASE:jar:jar-with-dependencies" "-DoutputDirectory=." "-Dmdep.stripVersion=true" "-Dmdep.stripClassifier=true"

2. Ask the CLI for help.

java -jar model-validations.jar --help

3. Run on your project with all report formats.

java -jar model-validations.jar `
    --expansionSettings conf/expansionSettings.xml `
    --stdout `
    --html target/validation-report.html `
    --junit target/validation-report.xml

4. 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>

    <exclude>
      <rule>FieldFinderForOppositeLinkFieldRule</rule>
      <!-- rule can produce multiple issues for the same element -->
      <issues>
        <!-- issue full message; exact match, no pattern/glob -->
        <!-- encode angle brackets or use CDATA -->
        <issue>&lt;Finder elements::Application::findByComponentEq&gt; is missing</issue>
      </issues>
    </exclude>

  </excludes>
</validation>

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

Jenkins Usage

Example stage in Jenkins.

stage('validate') {
  steps {
    // [recommended] when using `conf/expansionSettings.xml`
    modelValidations()
    
    // alternatively 
    modelValidations expansionSettings: 'conf/I-like-to-complicate-my-life-expansionSettings.xml'
  }
}

Maven Usage

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>2022.0.1</version>
  <configuration>
    <htmlReport>report.html</htmlReport>
    <junitReport>report.xml</junitReport>
  </configuration>
</plugin>

Output Formats

stdout

[validator] --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

JUnit-compatible XML report file.

[validator] --junit target/validation-report.xml

html

Custom html validation report.

[validator] --html target/validation-report.html