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;
}
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;
}
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"));
}
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");
}
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);
}
}
Aggregations