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