Search in sources :

Example 1 with RuleManager

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);
}
Also used : RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) TestingGraphInstanceBuilder(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder) Node(org.kie.workbench.common.stunner.core.graph.Node) RuleManager(org.kie.workbench.common.stunner.core.rule.RuleManager) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Test(org.junit.Test)

Example 2 with RuleManager

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);
}
Also used : RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) TestingGraphInstanceBuilder(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder) Node(org.kie.workbench.common.stunner.core.graph.Node) RuleManager(org.kie.workbench.common.stunner.core.rule.RuleManager) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 TestingGraphInstanceBuilder (org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder)2 Node (org.kie.workbench.common.stunner.core.graph.Node)2 DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)2 RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)2 RuleManager (org.kie.workbench.common.stunner.core.rule.RuleManager)2 RuleSet (org.kie.workbench.common.stunner.core.rule.RuleSet)2