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