Search in sources :

Example 1 with Bird

use of org.camunda.bpm.model.xml.testmodel.instance.Bird in project camunda-xml-model by camunda.

the class ModelElementInstanceTest method createModel.

private static Object[] createModel() {
    TestModelParser modelParser = new TestModelParser();
    ModelInstance modelInstance = modelParser.getEmptyModel();
    Animals animals = modelInstance.newInstance(Animals.class);
    modelInstance.setDocumentElement(animals);
    createBird(modelInstance, "tweety", Gender.Female);
    Bird donald = createBird(modelInstance, "donald", Gender.Male);
    Bird daisy = createBird(modelInstance, "daisy", Gender.Female);
    Bird hedwig = createBird(modelInstance, "hedwig", Gender.Male);
    donald.setTextContent("some text content");
    daisy.setTextContent("\n        some text content with outer line breaks\n    ");
    hedwig.setTextContent("\n        some text content with inner\n        line breaks\n    ");
    return new Object[] { "created", modelInstance, modelParser };
}
Also used : ModelInstance(org.camunda.bpm.model.xml.ModelInstance) Animals(org.camunda.bpm.model.xml.testmodel.instance.Animals) Bird(org.camunda.bpm.model.xml.testmodel.instance.Bird) TestModelParser(org.camunda.bpm.model.xml.testmodel.TestModelParser)

Example 2 with Bird

use of org.camunda.bpm.model.xml.testmodel.instance.Bird in project camunda-xml-model by camunda.

the class ModelElementInstanceTest method testReplaceWithElement.

@Test
public void testReplaceWithElement() {
    Bird timmy = modelInstance.newInstance(Bird.class);
    timmy.setId("timmy");
    timmy.setGender(Gender.Male);
    assertThat(animals.getAnimals()).contains(tweety).doesNotContain(timmy);
    tweety.replaceWithElement(timmy);
    assertThat(animals.getAnimals()).contains(timmy).doesNotContain(tweety);
}
Also used : Bird(org.camunda.bpm.model.xml.testmodel.instance.Bird) Test(org.junit.Test) TestModelTest(org.camunda.bpm.model.xml.testmodel.TestModelTest)

Example 3 with Bird

use of org.camunda.bpm.model.xml.testmodel.instance.Bird in project camunda-xml-model by camunda.

the class ModelElementInstanceTest method TestParentElement.

@Test
public void TestParentElement() {
    assertThat(tweety.getParentElement()).isEqualTo(animals);
    assertThat(donald.getParentElement()).isEqualTo(animals);
    assertThat(daisy.getParentElement()).isEqualTo(animals);
    assertThat(hedwig.getParentElement()).isEqualTo(animals);
    Bird timmy = modelInstance.newInstance(Bird.class);
    timmy.setId("timmy");
    timmy.setGender(Gender.Male);
    assertThat(timmy.getParentElement()).isNull();
}
Also used : Bird(org.camunda.bpm.model.xml.testmodel.instance.Bird) Test(org.junit.Test) TestModelTest(org.camunda.bpm.model.xml.testmodel.TestModelTest)

Example 4 with Bird

use of org.camunda.bpm.model.xml.testmodel.instance.Bird in project camunda-xml-model by camunda.

the class ModelValidationTest method shouldReturnResults.

@Test
public void shouldReturnResults() {
    List<ModelElementValidator<?>> validators = new ArrayList<ModelElementValidator<?>>();
    validators.add(new IllegalBirdValidator("tweety"));
    validators.add(new IsAdultWarner());
    ValidationResults results = modelInstance.validate(validators);
    assertThat(results.getErrorCount()).isEqualTo(1);
    assertThat(results.getWarinigCount()).isEqualTo(7);
    Map<ModelElementInstance, List<ValidationResult>> resultsByElement = results.getResults();
    assertThat(resultsByElement.size()).isEqualTo(7);
    for (Entry<ModelElementInstance, List<ValidationResult>> resultEntry : resultsByElement.entrySet()) {
        Bird element = (Bird) resultEntry.getKey();
        List<ValidationResult> validationResults = resultEntry.getValue();
        assertThat(element).isNotNull();
        assertThat(validationResults).isNotNull();
        if (element.getId().equals("tweety")) {
            assertThat(validationResults.size()).isEqualTo(2);
            ValidationResult error = validationResults.remove(0);
            assertThat(error.getType()).isEqualTo(ValidationResultType.ERROR);
            assertThat(error.getCode()).isEqualTo(20);
            assertThat(error.getMessage()).isEqualTo("Bird tweety is illegal");
            assertThat(error.getElement()).isEqualTo(element);
        } else {
            assertThat(validationResults.size()).isEqualTo(1);
        }
        ValidationResult warning = validationResults.get(0);
        assertThat(warning.getType()).isEqualTo(ValidationResultType.WARNING);
        assertThat(warning.getCode()).isEqualTo(10);
        assertThat(warning.getMessage()).isEqualTo("Is not an adult");
        assertThat(warning.getElement()).isEqualTo(element);
    }
}
Also used : Bird(org.camunda.bpm.model.xml.testmodel.instance.Bird) ArrayList(java.util.ArrayList) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

Bird (org.camunda.bpm.model.xml.testmodel.instance.Bird)4 Test (org.junit.Test)3 TestModelTest (org.camunda.bpm.model.xml.testmodel.TestModelTest)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ModelInstance (org.camunda.bpm.model.xml.ModelInstance)1 ModelElementInstance (org.camunda.bpm.model.xml.instance.ModelElementInstance)1 TestModelParser (org.camunda.bpm.model.xml.testmodel.TestModelParser)1 Animals (org.camunda.bpm.model.xml.testmodel.instance.Animals)1