Skip to content

YAML based Model Definition

Constantin Pascal edited this page Apr 16, 2021 · 3 revisions

In situations where you don't want to add jEntityTest annotations to your models, or you don't have access to modify the models due to an external library used - you can define the models in yaml. Below is an example model defined (refer to the inline comments for explanations):

# entity class described by the model
entity: org.testmonkeys.jentitytest.test.integration.yaml.test.Person

# list of properties defined in the model
properties:
  id:
    # list of abort conditions to be applied to the property
    abortConditions:
      - strategy: IgnoreComparisonIfExpectedNull
  name:
    # list of validators to be applied to the property
    validators:
        # Strategy name (either short name or full class name)
      - strategy: ValidateRegex
        # strategy parameters definition
        parameters:
          regExp: ^[0-9A-Za-z!@.,;:'"?-]{1,10}\z

    # comparison strategy that will be used for this property
    comparisonStrategy:
      strategy: StringComparison
      parameters:
        caseSensitive: false
        trim: true
  createdAt:
    comparisonStrategy:
      strategy: DateTimeComparison
      parameters:
        delta: 1
        unit: MINUTES
  employmentRecord:
    comparisonStrategy:
      strategy: ChildEntityComparison
  knownAddresses:
    comparisonStrategy:
      strategy: ChildEntityListComparison

To load the model - use the following snippet as an example:

InputStream inputStream = this.getClass()
                .getClassLoader()
                .getResourceAsStream("yamlComparisonModels/person.yaml");
        
EntityComparatorContext.getInstance().defineComparisonModel(inputStream);
        
inputStream.close();

Clone this wiki locally