Search in sources :

Example 46 with ModelElementInstance

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

the class ModelUtil method getModelElement.

/**
 * Returns the {@link ModelElementInstanceImpl ModelElement} for a DOM element.
 * If the model element does not yet exist, it is created and linked to the DOM.
 *
 * @param domElement the child element to create a new {@link ModelElementInstanceImpl ModelElement} for
 * @param modelInstance the {@link ModelInstanceImpl ModelInstance} for which the new {@link ModelElementInstanceImpl ModelElement} is created
 * @param modelType the {@link ModelElementTypeImpl ModelElementType} to create a new {@link ModelElementInstanceImpl ModelElement} for
 * @return the child model element
 */
public static ModelElementInstance getModelElement(DomElement domElement, ModelInstanceImpl modelInstance, ModelElementTypeImpl modelType) {
    ModelElementInstance modelElement = domElement.getModelElementInstance();
    if (modelElement == null) {
        modelElement = modelType.newInstance(modelInstance, domElement);
        domElement.setModelElementInstance(modelElement);
    }
    return modelElement;
}
Also used : ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance)

Example 47 with ModelElementInstance

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

the class AbstractReferenceAssert method hasTargetElement.

public S hasTargetElement(ModelElementInstance instance, ModelElementInstance targetElement) {
    isNotNull();
    ModelElementInstance actualTargetElement = actual.getReferenceTargetElement(instance);
    if (!targetElement.equals(actualTargetElement)) {
        failWithMessage("Expected reference <%s> to have target element <%s> but was <%s>", actual, targetElement, actualTargetElement);
    }
    return myself;
}
Also used : ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance)

Example 48 with ModelElementInstance

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

the class AlternativeNsTest method getUniqueChildElementByNameNsForAlternativeNs.

@Test
public void getUniqueChildElementByNameNsForAlternativeNs() {
    ModelElementInstance hedwig = modelInstance.getModelElementById("hedwig");
    assertThat(hedwig, is(notNullValue()));
    ModelElementInstance childElementByNameNs = hedwig.getUniqueChildElementByNameNs(TestModelConstants.NEWER_NAMESPACE, "wings");
    assertThat(childElementByNameNs, is(notNullValue()));
    assertThat(childElementByNameNs.getTextContent(), is("wusch"));
}
Also used : ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) TestModelTest(org.camunda.bpm.model.xml.testmodel.TestModelTest) Test(org.junit.Test)

Example 49 with ModelElementInstance

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

the class UnknownAnimalTest method testGetUnknownAnimalByType.

@Test
public void testGetUnknownAnimalByType() {
    ModelInstanceImpl modelInstanceImpl = (ModelInstanceImpl) modelInstance;
    ModelElementType unknownAnimalType = modelInstanceImpl.registerGenericType(MODEL_NAMESPACE, "unknownAnimal");
    List<ModelElementInstance> unknownAnimals = new ArrayList<ModelElementInstance>(modelInstance.getModelElementsByType(unknownAnimalType));
    assertThat(unknownAnimals).hasSize(2);
    ModelElementInstance wanda = unknownAnimals.get(0);
    assertThat(wanda.getAttributeValue("id")).isEqualTo("wanda");
    assertThat(wanda.getAttributeValue("gender")).isEqualTo("Female");
    assertThat(wanda.getAttributeValue("species")).isEqualTo("fish");
    ModelElementInstance flipper = unknownAnimals.get(1);
    assertThat(flipper.getAttributeValue("id")).isEqualTo("flipper");
    assertThat(flipper.getAttributeValue("gender")).isEqualTo("Male");
    assertThat(flipper.getAttributeValue("species")).isEqualTo("dolphin");
}
Also used : ModelElementType(org.camunda.bpm.model.xml.type.ModelElementType) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) ArrayList(java.util.ArrayList) ModelInstanceImpl(org.camunda.bpm.model.xml.impl.ModelInstanceImpl) Test(org.junit.Test)

Example 50 with ModelElementInstance

use of org.camunda.bpm.model.xml.instance.ModelElementInstance 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

ModelElementInstance (org.camunda.bpm.model.xml.instance.ModelElementInstance)55 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)8 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)8 ModelElementType (org.camunda.bpm.model.xml.type.ModelElementType)8 Process (org.camunda.bpm.model.bpmn.instance.Process)5 ModelInstanceImpl (org.camunda.bpm.model.xml.impl.ModelInstanceImpl)5 ModelReferenceException (org.camunda.bpm.model.xml.ModelReferenceException)4 DomElement (org.camunda.bpm.model.xml.instance.DomElement)4 List (java.util.List)3 Model (org.camunda.bpm.model.xml.Model)3 Deployment (org.camunda.bpm.engine.test.Deployment)2 Event (org.camunda.bpm.model.bpmn.instance.Event)2 SequenceFlow (org.camunda.bpm.model.bpmn.instance.SequenceFlow)2 BpmnShape (org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape)2 Case (org.camunda.bpm.model.cmmn.instance.Case)2 PlanItem (org.camunda.bpm.model.cmmn.instance.PlanItem)2 TestModelTest (org.camunda.bpm.model.xml.testmodel.TestModelTest)2 ModelElementValidator (org.camunda.bpm.model.xml.validation.ModelElementValidator)2 ValidationResult (org.camunda.bpm.model.xml.validation.ValidationResult)2