Model Validations

Latest release: 1.0.1


Validate your NS models.

Usage:

  • CLI
  • Jenkins
  • (soon) Maven Plugin
  • (soon) Prime Radiant

Contributing

See <./docs/creating-rules.md> for creating custom rules.

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'
    
    // (optional) capture generated junit report
    junit 'target/validation/report.xml'

    // (optional) publish generated HTML report (until we have better integration)
    publishHTML target: [
        reportDir: "target/validation",
        reportFiles: "index.html",
        reportName: 'Model Validation Report',
        keepAll: true,
        alwaysLinkToLastBuild: true,
        allowMissing: true,
    ]
  }
}

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