Search in sources :

Example 1 with ModelBeanViolation

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

the class ModelBeanValidatorTest method assertViolation.

private void assertViolation(final Collection<ModelBeanViolation> violations, final ConstraintViolation violation) {
    assertNotNull(violations);
    assertFalse(violations.isEmpty());
    final ModelBeanViolation modelBeanViolation = violations.iterator().next();
    assertEquals(Violation.Type.WARNING, modelBeanViolation.getViolationType());
    assertEquals(violation.getMessage(), modelBeanViolation.getMessage());
    assertEquals(violation.getPropertyPath().toString(), modelBeanViolation.getPropertyPath());
}
Also used : ModelBeanViolation(org.kie.workbench.common.stunner.core.validation.ModelBeanViolation)

Example 2 with ModelBeanViolation

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

the class DiagramValidatorlTest method testValidateDiagram1InvalidBean.

@Test
@SuppressWarnings("unchecked")
public void testValidateDiagram1InvalidBean() {
    final TestingGraphInstanceBuilder.TestGraph1 graph1 = TestingGraphInstanceBuilder.newGraph1(graphTestHandler);
    when(diagram.getGraph()).thenReturn(graphTestHandler.graph);
    final ModelBeanViolation beanViolation = mock(ModelBeanViolation.class);
    when(beanViolation.getViolationType()).thenReturn(Violation.Type.ERROR);
    doAnswer(invocationOnMock -> {
        final Consumer<Collection<ModelBeanViolation>> validationsConsumer = (Consumer<Collection<ModelBeanViolation>>) invocationOnMock.getArguments()[1];
        validationsConsumer.accept(Collections.singleton(beanViolation));
        return null;
    }).when(modelValidator).validate(eq(graph1.intermNodeBean), any(Consumer.class));
    tested.validate(diagram, violations -> assertElementError(violations, TestingGraphInstanceBuilder.INTERM_NODE_UUID));
    verify(modelValidator, times(1)).validate(eq(graph1.startNodeBean), any(Consumer.class));
    verify(modelValidator, times(1)).validate(eq(graph1.intermNodeBean), any(Consumer.class));
    verify(modelValidator, times(1)).validate(eq(graph1.endNodeBean), any(Consumer.class));
    verify(modelValidator, times(1)).validate(eq(graph1.edge1Bean), any(Consumer.class));
    verify(modelValidator, times(1)).validate(eq(graph1.edge2Bean), any(Consumer.class));
    verify(modelValidator, never()).validate(eq(graphTestHandler.graph), any(Consumer.class));
}
Also used : ModelBeanViolation(org.kie.workbench.common.stunner.core.validation.ModelBeanViolation) TestingGraphInstanceBuilder(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder) Consumer(java.util.function.Consumer) Collection(java.util.Collection) Test(org.junit.Test)

Example 3 with ModelBeanViolation

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

the class NotificationMessageUtilsTest 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);
    final RuleViolation ruleViolation = mock(RuleViolation.class);
    final DiagramElementViolation<RuleViolation> diagramViolation = mock(DiagramElementViolation.class);
    when(diagramViolation.getUUID()).thenReturn("uuid1");
    when(diagramViolation.getModelViolations()).thenReturn(Collections.singletonList(beanViolation));
    when(diagramViolation.getGraphViolations()).thenReturn(Collections.singletonList(ruleViolation));
    when(ruleViolation.getViolationType()).thenReturn(Violation.Type.WARNING);
    when(translationService.getViolationMessage(eq(ruleViolation))).thenReturn("rv1");
    when(translationService.getValue(eq("aKey"))).thenReturn("aValue");
    String message = NotificationMessageUtils.getDiagramValidationsErrorMessage(translationService, "aKey", Collections.singleton(diagramViolation));
    message = new SafeHtmlBuilder().appendEscapedLines(message).toSafeHtml().asString();
    assertEquals("aValue." + HTML_NEW_LINE + "R" + COLON + HTML_NEW_LINE + OPEN_BRA + "E" + COLON + "uuid1" + CLOSE_BRA + HTML_NEW_LINE + "(WARNING) " + HTML_OPEN_COMMENT + "path1" + HTML_CLOSE_COMMENT + "message1" + HTML_NEW_LINE + "(WARNING) rv1" + HTML_NEW_LINE, 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) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Test(org.junit.Test)

Example 4 with ModelBeanViolation

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

the class NotificationMessageUtilsTest method testBeanValidationMessage.

@Test
public void testBeanValidationMessage() {
    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 violation = ModelBeanViolationImpl.Builder.build(rootViolation);
    final String message = NotificationMessageUtils.getBeanValidationMessage(translationService, violation);
    assertEquals("(WARNING) " + OPEN_COMMENT + "path1" + CLOSE_COMMENT + "message1", message);
}
Also used : Path(javax.validation.Path) ModelBeanViolation(org.kie.workbench.common.stunner.core.validation.ModelBeanViolation) Test(org.junit.Test)

Aggregations

ModelBeanViolation (org.kie.workbench.common.stunner.core.validation.ModelBeanViolation)4 Test (org.junit.Test)3 Path (javax.validation.Path)2 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 Collection (java.util.Collection)1 Consumer (java.util.function.Consumer)1 TestingGraphInstanceBuilder (org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder)1 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)1