Search in sources :

Example 6 with DomainViolation

use of org.kie.workbench.common.stunner.core.validation.DomainViolation in project kie-wb-common by kiegroup.

the class BPMNDataObjectValidator method validate.

@Override
public void validate(Diagram diagram, Consumer<Collection<DomainViolation>> resultConsumer) {
    Iterator<Element> it = diagram.getGraph().nodes().iterator();
    Map<String, String> dataObjectsMap = new HashMap<>();
    List<DomainViolation> violations = new ArrayList<>();
    while (it.hasNext()) {
        Element element = it.next();
        if (element.getContent() instanceof View && ((View) element.getContent()).getDefinition() instanceof DataObject) {
            DataObject dataObject = (DataObject) ((View) element.getContent()).getDefinition();
            String name = dataObject.getName().getValue();
            String type = dataObject.getType().getValue().getType();
            String containedType = dataObjectsMap.get(name);
            if (containedType != null && !type.equals(containedType)) {
                // If already defined with different type
                BPMNViolation bpmnViolation = new BPMNViolation(getMessageDataObjectWithTypeSameName() + " : " + name, Violation.Type.WARNING, element.getUUID());
                violations.add(bpmnViolation);
            } else {
                dataObjectsMap.put(name, type);
            }
            if (!name.matches(ALLOWED_CHARS)) {
                BPMNViolation bpmnViolation = new BPMNViolation(getMessageDataObjectIllegalName() + " : " + name, Violation.Type.WARNING, element.getUUID());
                violations.add(bpmnViolation);
            }
        }
    }
    resultConsumer.accept(violations);
}
Also used : DataObject(org.kie.workbench.common.stunner.bpmn.definition.DataObject) HashMap(java.util.HashMap) Element(org.kie.workbench.common.stunner.core.graph.Element) ArrayList(java.util.ArrayList) DomainViolation(org.kie.workbench.common.stunner.core.validation.DomainViolation) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 7 with DomainViolation

use of org.kie.workbench.common.stunner.core.validation.DomainViolation in project kie-wb-common by kiegroup.

the class NotificationsObserverTest method testNotifyValidationFailed.

@Test
@SuppressWarnings("unchecked")
public void testNotifyValidationFailed() {
    final DomainViolation domainV1 = mock(DomainViolation.class);
    when(domainV1.getMessage()).thenReturn("message");
    when(translationService.getElementName(anyString())).thenReturn(Optional.of("name"));
    when(translationService.getValue(anyString(), anyString(), anyString())).thenReturn("message");
    final DiagramElementViolation violation = mock(DiagramElementViolation.class);
    final DiagramElementViolation violation2 = mock(DiagramElementViolation.class);
    when(violation.getDomainViolations()).thenReturn(Arrays.asList(domainV1));
    when(violation2.getDomainViolations()).thenReturn(Arrays.asList(domainV1));
    final Collection<DiagramElementViolation<RuleViolation>> violations = Arrays.asList(violation, violation2);
    validationFailedNotification = new ValidationFailedNotification(violations, notificationContext, "message1", Notification.Type.ERROR);
    final CanvasValidationFailEvent validationFailEvent = new CanvasValidationFailEvent(UUID, NAME, TITLE, violations);
    tested.onCanvasValidationFailEvent(validationFailEvent);
    final InOrder inOrder = inOrder(validationExecuted, onNotification, validationFailed, commandFailed, validationSuccess, commandSuccess);
    // verify in order calls
    inOrder.verify(validationExecuted).execute(any(ValidationExecutedNotification.class));
    inOrder.verify(onNotification, times(1)).execute(any(Notification.class));
    inOrder.verify(validationFailed, times(1)).execute(eq(validationFailedNotification));
    inOrder.verify(onNotification, times(1)).execute(any(Notification.class));
    inOrder.verify(validationFailed, times(1)).execute(eq(validationFailedNotification));
    inOrder.verify(commandFailed, never()).execute(any(CommandNotification.class));
    inOrder.verify(validationSuccess, never()).execute(any(ValidationSuccessNotification.class));
    inOrder.verify(commandSuccess, never()).execute(any(CommandNotification.class));
    // verify total calls
    verify(validationFailed, times(2)).execute(eq(validationFailedNotification));
    verify(onNotification, times(2)).execute(any(Notification.class));
}
Also used : InOrder(org.mockito.InOrder) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) CanvasValidationFailEvent(org.kie.workbench.common.stunner.core.client.validation.canvas.CanvasValidationFailEvent) DomainViolation(org.kie.workbench.common.stunner.core.validation.DomainViolation) Test(org.junit.Test)

Example 8 with DomainViolation

use of org.kie.workbench.common.stunner.core.validation.DomainViolation in project kie-wb-common by kiegroup.

the class ProjectValidationServiceImplTest 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 9 with DomainViolation

use of org.kie.workbench.common.stunner.core.validation.DomainViolation in project kie-wb-common by kiegroup.

the class ProjectMessagesListenerTest method testEnable.

@Test
public void testEnable() {
    projectMessagesListener.enable();
    final ArgumentCaptor<ParameterizedCommand> callbackCaptor = ArgumentCaptor.forClass(ParameterizedCommand.class);
    // onCommandExecutionFailed
    verify(notificationsObserver).onCommandExecutionFailed(callbackCaptor.capture());
    callbackCaptor.getAllValues().get(0).execute(CommandNotification.Builder.build(buildNotificationContext(), mock(Command.class), Notification.Type.INFO, "message"));
    verify(projectMessagesListener, times(1)).fireNotification(any());
    // onValidationFailed
    verify(notificationsObserver).onValidationFailed(callbackCaptor.capture());
    final DiagramElementViolation diagramElementViolation = mock(DiagramElementViolation.class);
    final DomainViolation domainViolation = mock(DomainViolation.class);
    final ClientTranslationService translationService = mock(ClientTranslationService.class);
    when(diagramElementViolation.getViolationType()).thenReturn(Violation.Type.ERROR);
    when(diagramElementViolation.getDomainViolations()).thenReturn(Arrays.asList(domainViolation));
    when(domainViolation.getViolationType()).thenReturn(Violation.Type.ERROR);
    when(translationService.getElementName(anyString())).thenReturn(Optional.of("name"));
    when(translationService.getValue(anyString(), anyString(), anyString())).thenReturn("message");
    when(domainViolation.getMessage()).thenReturn("message");
    callbackCaptor.getAllValues().get(1).execute(ValidationFailedNotification.Builder.build(translationService, buildNotificationContext(), Arrays.asList(diagramElementViolation)).get());
    verify(projectMessagesListener, times(2)).fireNotification(any());
    // onValidationExecuted
    verify(notificationsObserver).onValidationExecuted(callbackCaptor.capture());
    callbackCaptor.getAllValues().get(2).execute(null);
    verify(projectMessagesListener, times(1)).clearMessages(any());
}
Also used : ClientTranslationService(org.kie.workbench.common.stunner.core.client.i18n.ClientTranslationService) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) DomainViolation(org.kie.workbench.common.stunner.core.validation.DomainViolation) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) 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