Search in sources :

Example 1 with DomainViolation

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);
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) ArrayList(java.util.ArrayList) DomainViolation(org.kie.workbench.common.stunner.core.validation.DomainViolation)

Example 2 with DomainViolation

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);
}
Also used : MarshallingMessage(org.kie.workbench.common.stunner.core.marshaller.MarshallingMessage) GwtMockitoTestRunner(com.google.gwtmockito.GwtMockitoTestRunner) MarshallingMessage(org.kie.workbench.common.stunner.core.marshaller.MarshallingMessage) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DMNDomainValidator(org.kie.workbench.common.dmn.api.validation.DMNDomainValidator) CallerMock(org.uberfire.mocks.CallerMock) ErrorCallback(org.jboss.errai.common.client.api.ErrorCallback) Mock(org.mockito.Mock) ManagedInstance(org.jboss.errai.ioc.client.api.ManagedInstance) RunWith(org.junit.runner.RunWith) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) Mockito.spy(org.mockito.Mockito.spy) Collections.singletonList(java.util.Collections.singletonList) TreeWalkTraverseProcessor(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessor) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) DomainViolation(org.kie.workbench.common.stunner.core.validation.DomainViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) Mockito.doReturn(org.mockito.Mockito.doReturn) ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Before(org.junit.Before) DomainValidator(org.kie.workbench.common.stunner.core.validation.DomainValidator) ElementViolationImpl(org.kie.workbench.common.stunner.core.validation.impl.ElementViolationImpl) Collection(java.util.Collection) ModelValidator(org.kie.workbench.common.stunner.core.validation.ModelValidator) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback) Test(org.junit.Test) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) DMNMarshallerService(org.kie.workbench.common.dmn.client.marshaller.DMNMarshallerService) RuleManager(org.kie.workbench.common.stunner.core.rule.RuleManager) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) ElementViolationImpl(org.kie.workbench.common.stunner.core.validation.impl.ElementViolationImpl) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) Collection(java.util.Collection) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) DomainViolation(org.kie.workbench.common.stunner.core.validation.DomainViolation) Test(org.junit.Test)

Example 3 with DomainViolation

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);
}
Also used : Path(javax.validation.Path) ModelBeanViolation(org.kie.workbench.common.stunner.core.validation.ModelBeanViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DomainViolation(org.kie.workbench.common.stunner.core.validation.DomainViolation) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Test(org.junit.Test)

Example 4 with DomainViolation

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");
}
Also used : DomainViolation(org.kie.workbench.common.stunner.core.validation.DomainViolation)

Example 5 with DomainViolation

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);
}
Also used : DMNElement(org.kie.dmn.model.api.DMNElement) DomainViolation(org.kie.workbench.common.stunner.core.validation.DomainViolation) Test(org.junit.Test)

Aggregations

DomainViolation (org.kie.workbench.common.stunner.core.validation.DomainViolation)9 Test (org.junit.Test)5 DiagramElementViolation (org.kie.workbench.common.stunner.core.validation.DiagramElementViolation)3 ArrayList (java.util.ArrayList)2 Element (org.kie.workbench.common.stunner.core.graph.Element)2 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)2 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 GwtMockitoTestRunner (com.google.gwtmockito.GwtMockitoTestRunner)1 Collection (java.util.Collection)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 Consumer (java.util.function.Consumer)1 Path (javax.validation.Path)1 ErrorCallback (org.jboss.errai.common.client.api.ErrorCallback)1 RemoteCallback (org.jboss.errai.common.client.api.RemoteCallback)1 ManagedInstance (org.jboss.errai.ioc.client.api.ManagedInstance)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Before (org.junit.Before)1 RunWith (org.junit.runner.RunWith)1 DMNElement (org.kie.dmn.model.api.DMNElement)1