use of org.kie.workbench.common.stunner.core.validation.DomainViolation in project kie-wb-common by kiegroup.
the class BPMNReusableSubProcessValidator method validate.
@Override
public void validate(Diagram diagram, Consumer<Collection<DomainViolation>> resultConsumer) {
Iterator<Element> it = diagram.getGraph().nodes().iterator();
List<DomainViolation> violations = new ArrayList<>();
while (it.hasNext()) {
Element element = it.next();
checkElementForViolations(violations, element);
}
resultConsumer.accept(violations);
}
use of org.kie.workbench.common.stunner.core.validation.DomainViolation in project kie-wb-common by kiegroup.
the class DMNClientDiagramValidatorTest method testOnValidatorSuccess.
@Test
public void testOnValidatorSuccess() {
final ElementViolationImpl elementViolation = new ElementViolationImpl.Builder().build();
final MarshallingMessage marshallingMessage = MarshallingMessage.builder().build();
final Collection<DiagramElementViolation<RuleViolation>> diagramElementViolations = singletonList(elementViolation);
final Collection<DomainViolation> response = singletonList(marshallingMessage);
final Consumer<Collection<DiagramElementViolation<RuleViolation>>> resultConsumer = (collection) -> {
assertEquals(1, collection.size());
};
validator.onValidatorSuccess(diagramElementViolations, resultConsumer).callback(response);
}
use of org.kie.workbench.common.stunner.core.validation.DomainViolation in project kie-wb-common by kiegroup.
the class CoreTranslationMessagesTest method testDiagramValidationMessage.
@Test
@SuppressWarnings("unchecked")
public void testDiagramValidationMessage() {
final ConstraintViolation<?> rootViolation = mock(ConstraintViolation.class);
final Path propertyPath = mock(Path.class);
when(propertyPath.toString()).thenReturn("path1");
when(rootViolation.getPropertyPath()).thenReturn(propertyPath);
when(rootViolation.getMessage()).thenReturn("message1");
final ModelBeanViolation beanViolation = ModelBeanViolationImpl.Builder.build(rootViolation, "uuid");
final RuleViolation ruleViolation = mock(RuleViolation.class);
final DiagramElementViolation<RuleViolation> diagramViolation = mock(DiagramElementViolation.class);
final DomainViolation domainViolation = mock(DomainViolation.class);
when(diagramViolation.getUUID()).thenReturn("uuid1");
when(diagramViolation.getModelViolations()).thenReturn(Collections.singletonList(beanViolation));
when(diagramViolation.getGraphViolations()).thenReturn(Collections.singletonList(ruleViolation));
when(diagramViolation.getDomainViolations()).thenReturn(Collections.singletonList(domainViolation));
when(ruleViolation.getViolationType()).thenReturn(Violation.Type.WARNING);
when(translationService.getViolationMessage(eq(ruleViolation))).thenReturn("rv1");
when(translationService.getValue(eq("aKey"))).thenReturn("aValue");
when(translationService.getElementName("uuid1")).thenReturn(Optional.of("name"));
String message = CoreTranslationMessages.getDiagramValidationsErrorMessage(translationService, Collections.singleton(diagramViolation)).get();
message = new SafeHtmlBuilder().appendEscapedLines(message).toSafeHtml().asString();
assertEquals(VALIDATION_ELEMENT_MESSAGE, message);
}
use of org.kie.workbench.common.stunner.core.validation.DomainViolation in project kie-wb-common by kiegroup.
the class DiagramValidatorTest method mockViolations.
private void mockViolations(List<DomainViolation> violations) {
violations.stream().forEach(v -> {
when(v.getViolationType()).thenReturn(Violation.Type.ERROR);
when(v.getUUID()).thenReturn(UUID_1);
});
DomainViolation first = violations.get(0);
when(first.getUUID()).thenReturn(UUID_0);
DomainViolation last1 = violations.get(violations.size() - 2);
when(last1.getUUID()).thenReturn(null);
DomainViolation last = violations.get(violations.size() - 1);
when(last.getUUID()).thenReturn("null");
}
use of org.kie.workbench.common.stunner.core.validation.DomainViolation in project kie-wb-common by kiegroup.
the class DMNDomainValidatorImplTest method testValidationMessageConversion.
@Test
public void testValidationMessageConversion() {
final String dmnElementUUID = "element-uuid";
final DMNElement dmnElement1 = mock(DMNElement.class);
final DMNElement dmnElement2 = mock(DMNElement.class);
doReturn(resolver).when(domainValidator).getValidatorImportReaderResolver(metadata);
// Default UUID
validationMessages.add(makeDMNMessage(DMNMessage.Severity.ERROR, "error", null));
// Explicit UUID
when(dmnElement1.getId()).thenReturn(dmnElementUUID);
validationMessages.add(makeDMNMessage(DMNMessage.Severity.WARN, "warn", dmnElement1));
// Parent UUID
when(dmnElement2.getParent()).thenReturn(dmnElement1);
validationMessages.add(makeDMNMessage(DMNMessage.Severity.INFO, "info", dmnElement2));
domainValidator.validate(diagram, resultConsumer);
verify(resultConsumer).accept(domainViolationsArgumentCaptor.capture());
final Collection<DomainViolation> domainViolations = domainViolationsArgumentCaptor.getValue();
assertThat(domainViolations).hasSize(3);
final Iterator<DomainViolation> domainViolationIterator = domainViolations.iterator();
final DomainViolation domainViolation0 = domainViolationIterator.next();
assertThat(domainViolation0.getViolationType()).isEqualTo(Violation.Type.ERROR);
assertThat(domainViolation0.getMessage()).contains("error");
assertThat(domainViolation0.getUUID()).isEqualTo(DMNDomainValidatorImpl.DEFAULT_UUID);
final DomainViolation domainViolation1 = domainViolationIterator.next();
assertThat(domainViolation1.getViolationType()).isEqualTo(Violation.Type.WARNING);
assertThat(domainViolation1.getMessage()).contains("warn");
assertThat(domainViolation1.getUUID()).isEqualTo(dmnElementUUID);
final DomainViolation domainViolation2 = domainViolationIterator.next();
assertThat(domainViolation2.getViolationType()).isEqualTo(Violation.Type.INFO);
assertThat(domainViolation2.getMessage()).contains("info");
assertThat(domainViolation2.getUUID()).isEqualTo(dmnElementUUID);
}
Aggregations