use of org.camunda.bpm.model.xml.validation.ModelElementValidator in project camunda-xml-model by camunda.
the class ModelInstanceValidator method validate.
@SuppressWarnings({ "unchecked", "rawtypes" })
public ValidationResults validate() {
ValidationResultsCollectorImpl resultsCollector = new ValidationResultsCollectorImpl();
for (ModelElementValidator validator : validators) {
Class<? extends ModelElementInstance> elementType = validator.getElementType();
Collection<? extends ModelElementInstance> modelElementsByType = modelInstanceImpl.getModelElementsByType(elementType);
for (ModelElementInstance element : modelElementsByType) {
resultsCollector.setCurrentElement(element);
try {
validator.validate(element, resultsCollector);
} catch (RuntimeException e) {
throw new RuntimeException("Validator " + validator + " threw an exception while validating " + element, e);
}
}
}
return resultsCollector.getResults();
}
use of org.camunda.bpm.model.xml.validation.ModelElementValidator in project camunda-bpmn-model by camunda.
the class ValidateProcessTest method validationFailsIfNoStartEventFound.
@Test
public void validationFailsIfNoStartEventFound() {
List<ModelElementValidator<?>> validators = new ArrayList<ModelElementValidator<?>>();
validators.add(new ProcessStartEventValidator());
BpmnModelInstance bpmnModelInstance = Bpmn.createProcess().done();
ValidationResults validationResults = bpmnModelInstance.validate(validators);
assertThat(validationResults.hasErrors()).isTrue();
Map<ModelElementInstance, List<ValidationResult>> results = validationResults.getResults();
assertThat(results.size()).isEqualTo(1);
Process process = bpmnModelInstance.getDefinitions().getChildElementsByType(Process.class).iterator().next();
assertThat(results.containsKey(process)).isTrue();
List<ValidationResult> resultsForProcess = results.get(process);
assertThat(resultsForProcess.size()).isEqualTo(1);
ValidationResult validationResult = resultsForProcess.get(0);
assertThat(validationResult.getElement()).isEqualTo(process);
assertThat(validationResult.getCode()).isEqualTo(10);
assertThat(validationResult.getMessage()).isEqualTo("Process does not have exactly one start event. Got 0.");
assertThat(validationResult.getType()).isEqualTo(ValidationResultType.ERROR);
}
Aggregations