use of org.kie.workbench.common.stunner.core.rule.RuleManager in project kie-wb-common by kiegroup.
the class GraphValidatorImplTest method testValidateGraph2.
@Test
@SuppressWarnings("unchecked")
public void testValidateGraph2() {
final RuleManager ruleManager = graphTestHandler.ruleManager;
final RuleSet ruleSet = graphTestHandler.ruleSet;
final Graph<DefinitionSet, Node> graph = graphTestHandler.graph;
final TestingGraphInstanceBuilder.TestGraph2 testGraph2 = TestingGraphInstanceBuilder.newGraph2(graphTestHandler);
tested.validate(getGraph(), graphTestHandler.ruleSet, this::assertNoError);
final int evalCount = testGraph2.evaluationsCount + 11;
final ArgumentCaptor<RuleEvaluationContext> contextCaptor = ArgumentCaptor.forClass(RuleEvaluationContext.class);
verify(ruleManager, times(evalCount)).evaluate(eq(ruleSet), contextCaptor.capture());
final List<RuleEvaluationContext> contexts = contextCaptor.getAllValues();
assertEquals(evalCount, contexts.size());
int cindex = testGraph2.evaluationsCount;
verifyCardinality((ElementCardinalityContext) contexts.get(cindex++), graph);
verifyContainment((NodeContainmentContext) contexts.get(cindex++), graph, testGraph2.parentNode);
verifyContainment((NodeContainmentContext) contexts.get(cindex++), testGraph2.parentNode, testGraph2.startNode);
verifyConnection((GraphConnectionContext) contexts.get(cindex++), testGraph2.edge1, testGraph2.startNode, testGraph2.intermNode);
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph2.intermNode, testGraph2.edge1, EdgeCardinalityContext.Direction.INCOMING, Optional.empty());
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph2.startNode, testGraph2.edge1, EdgeCardinalityContext.Direction.OUTGOING, Optional.empty());
verifyContainment((NodeContainmentContext) contexts.get(cindex++), testGraph2.parentNode, testGraph2.intermNode);
verifyConnection((GraphConnectionContext) contexts.get(cindex++), testGraph2.edge2, testGraph2.intermNode, testGraph2.endNode);
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph2.endNode, testGraph2.edge2, EdgeCardinalityContext.Direction.INCOMING, Optional.empty());
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph2.intermNode, testGraph2.edge2, EdgeCardinalityContext.Direction.OUTGOING, Optional.empty());
verifyContainment((NodeContainmentContext) contexts.get(cindex++), testGraph2.parentNode, testGraph2.endNode);
}
use of org.kie.workbench.common.stunner.core.rule.RuleManager in project kie-wb-common by kiegroup.
the class GraphValidatorImplTest method testValidateGraph1.
@Test
@SuppressWarnings("unchecked")
public void testValidateGraph1() {
final RuleManager ruleManager = graphTestHandler.ruleManager;
final RuleSet ruleSet = graphTestHandler.ruleSet;
final Graph<DefinitionSet, Node> graph = graphTestHandler.graph;
final TestingGraphInstanceBuilder.TestGraph1 testGraph1 = TestingGraphInstanceBuilder.newGraph1(graphTestHandler);
tested.validate(graph, ruleSet, this::assertNoError);
final int evalCount = testGraph1.evaluationsCount + 10;
final ArgumentCaptor<RuleEvaluationContext> contextCaptor = ArgumentCaptor.forClass(RuleEvaluationContext.class);
verify(ruleManager, times(evalCount)).evaluate(eq(ruleSet), contextCaptor.capture());
final List<RuleEvaluationContext> contexts = contextCaptor.getAllValues();
assertEquals(evalCount, contexts.size());
int cindex = testGraph1.evaluationsCount;
verifyCardinality((ElementCardinalityContext) contexts.get(cindex++), graph);
verifyContainment((NodeContainmentContext) contexts.get(cindex++), graph, testGraph1.startNode);
verifyConnection((GraphConnectionContext) contexts.get(cindex++), testGraph1.edge1, testGraph1.startNode, testGraph1.intermNode);
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph1.intermNode, testGraph1.edge1, EdgeCardinalityContext.Direction.INCOMING, Optional.empty());
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph1.startNode, testGraph1.edge1, EdgeCardinalityContext.Direction.OUTGOING, Optional.empty());
verifyContainment((NodeContainmentContext) contexts.get(cindex++), graph, testGraph1.intermNode);
verifyConnection((GraphConnectionContext) contexts.get(cindex++), testGraph1.edge2, testGraph1.intermNode, testGraph1.endNode);
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph1.endNode, testGraph1.edge2, EdgeCardinalityContext.Direction.INCOMING, Optional.empty());
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph1.intermNode, testGraph1.edge2, EdgeCardinalityContext.Direction.OUTGOING, Optional.empty());
verifyContainment((NodeContainmentContext) contexts.get(cindex++), graph, testGraph1.endNode);
}
Aggregations