Search in sources :

Example 1 with DomainValidator

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

the class ProjectValidationServiceImplTest method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() {
    domainViolationList = Arrays.asList(domainViolation, domainViolation2, domainViolation3, domainViolation4, domainViolationNull, domainViolationNullStr);
    domainValidator = new DomainValidator() {

        @Override
        public String getDefinitionSetId() {
            return DEF_SET_ID;
        }

        @Override
        public void validate(Diagram entity, Consumer<Collection<DomainViolation>> resultConsumer) {
            resultConsumer.accept(domainViolationList);
        }
    };
    when(diagram.getMetadata()).thenReturn(metadata);
    when(metadata.getDefinitionSetId()).thenReturn(DEF_SET_ID);
    when(diagram.getGraph()).thenReturn(graph);
    when(graph.getUUID()).thenReturn(GRAPH_UUID);
    mockViolations(domainViolationList);
    validationService = new ProjectValidationServiceImpl(new MockInstanceImpl(domainValidator));
}
Also used : MockInstanceImpl(org.uberfire.mocks.MockInstanceImpl) Collection(java.util.Collection) DomainValidator(org.kie.workbench.common.stunner.core.validation.DomainValidator) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Before(org.junit.Before)

Example 2 with DomainValidator

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

the class DiagramValidatorTest method testValidateDiagram1InvalidBean.

@Test
@SuppressWarnings("unchecked")
public void testValidateDiagram1InvalidBean() {
    domainViolationList = Arrays.asList(domainViolation, domainViolation2, domainViolation3, domainViolation4, domainViolationNull, domainViolationNullStr);
    domainValidator = new DomainValidator() {

        @Override
        public String getDefinitionSetId() {
            return DEF_SET_ID;
        }

        @Override
        public void validate(Diagram entity, Consumer<Collection<DomainViolation>> resultConsumer) {
            resultConsumer.accept(domainViolationList);
        }
    };
    final TestingGraphInstanceBuilder.TestGraph1 graph1 = TestingGraphInstanceBuilder.newGraph1(graphTestHandler);
    when(diagram.getGraph()).thenReturn(graphTestHandler.graph);
    // model violation
    final ModelBeanViolation beanViolation = mock(ModelBeanViolation.class);
    when(beanViolation.getViolationType()).thenReturn(Violation.Type.ERROR);
    when(beanViolation.getMessage()).thenReturn(MODEL_VIOLATION);
    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.intermNode), any(Consumer.class));
    // graph violation
    RuleViolation ruleViolation = mock(RuleViolation.class);
    when(ruleViolation.getViolationType()).thenReturn(Violation.Type.ERROR);
    when(ruleViolation.getMessage()).thenReturn(RULE_VIOLATION);
    when(graphTestHandler.getRuleManager().evaluate(any(), any())).thenReturn(new DefaultRuleViolations().addViolation(ruleViolation));
    tested.validate(diagram, violations -> assertElementError(violations, TestingGraphInstanceBuilder.INTERM_NODE_UUID));
    verify(modelValidator, times(1)).validate(eq(graph1.startNode), any(Consumer.class));
    verify(modelValidator, times(1)).validate(eq(graph1.intermNode), any(Consumer.class));
    verify(modelValidator, times(1)).validate(eq(graph1.endNode), any(Consumer.class));
    verify(modelValidator, times(1)).validate(eq(graph1.edge1), any(Consumer.class));
    verify(modelValidator, times(1)).validate(eq(graph1.edge2), any(Consumer.class));
    verify(modelValidator, times(1)).validate(eq(graphTestHandler.graph), any(Consumer.class));
}
Also used : TestingGraphInstanceBuilder(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) ModelBeanViolation(org.kie.workbench.common.stunner.core.validation.ModelBeanViolation) Consumer(java.util.function.Consumer) Collection(java.util.Collection) DomainValidator(org.kie.workbench.common.stunner.core.validation.DomainValidator) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) Test(org.junit.Test)

Aggregations

Collection (java.util.Collection)2 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)2 DomainValidator (org.kie.workbench.common.stunner.core.validation.DomainValidator)2 Consumer (java.util.function.Consumer)1 Before (org.junit.Before)1 Test (org.junit.Test)1 TestingGraphInstanceBuilder (org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder)1 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)1 DefaultRuleViolations (org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)1 ModelBeanViolation (org.kie.workbench.common.stunner.core.validation.ModelBeanViolation)1 MockInstanceImpl (org.uberfire.mocks.MockInstanceImpl)1