Search in sources :

Example 6 with RuleEvaluationContext

use of org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext 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)

Example 7 with RuleEvaluationContext

use of org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext in project kie-wb-common by kiegroup.

the class SafeDeleteNodeCommandRulesTest method testSingleNode.

@Test
@SuppressWarnings("unchecked")
public void testSingleNode() {
    CommandResult<RuleViolation> result = tested.allow(graphCommandExecutionContext);
    List<Command<GraphCommandExecutionContext, RuleViolation>> commands = tested.getCommands();
    assertNotNull(commands);
    assertTrue(1 == commands.size());
    Command command1 = commands.get(0);
    assertTrue(command1 instanceof DeregisterNodeCommand);
    assertEquals(CommandResult.Type.INFO, result.getType());
    final ArgumentCaptor<RuleEvaluationContext> contextCaptor = ArgumentCaptor.forClass(RuleEvaluationContext.class);
    verify(ruleManager, times(2)).evaluate(eq(ruleSet), contextCaptor.capture());
    final List<RuleEvaluationContext> contexts = contextCaptor.getAllValues();
    assertEquals(2, contexts.size());
    verifyCardinality((ElementCardinalityContext) contexts.get(0), graph, node, CardinalityContext.Operation.DELETE);
}
Also used : Command(org.kie.workbench.common.stunner.core.command.Command) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 8 with RuleEvaluationContext

use of org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext in project kie-wb-common by kiegroup.

the class SetConnectionSourceNodeCommandTest method testExecute.

@Test
@SuppressWarnings("unchecked")
public void testExecute() {
    final List lastSourceOutEdges = mock(List.class);
    final List sourceOutEdges = mock(List.class);
    final List targetInEdges = mock(List.class);
    when(node.getOutEdges()).thenReturn(sourceOutEdges);
    when(lastSourceNode.getOutEdges()).thenReturn(lastSourceOutEdges);
    when(target.getInEdges()).thenReturn(targetInEdges);
    CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
    final ArgumentCaptor<RuleEvaluationContext> contextCaptor = ArgumentCaptor.forClass(RuleEvaluationContext.class);
    verify(ruleManager, times(3)).evaluate(eq(ruleSet), contextCaptor.capture());
    final List<RuleEvaluationContext> contexts = contextCaptor.getAllValues();
    assertEquals(3, contexts.size());
    verifyConnection((GraphConnectionContext) contexts.get(0), edge, node, target);
    verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(1), graph, lastSourceNode, edge, EdgeCardinalityContext.Direction.OUTGOING, Optional.of(CardinalityContext.Operation.DELETE));
    verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(2), graph, node, edge, EdgeCardinalityContext.Direction.OUTGOING, Optional.of(CardinalityContext.Operation.ADD));
    assertEquals(CommandResult.Type.INFO, result.getType());
    verify(lastSourceOutEdges, times(1)).remove(eq(edge));
    verify(sourceOutEdges, times(1)).add(eq(edge));
    verify(edgeContent, times(1)).setSourceConnection(any(Connection.class));
    verify(edge, times(1)).setSourceNode(eq(node));
    verify(targetInEdges, times(0)).remove(any(Edge.class));
    verify(targetInEdges, times(0)).add(any(Edge.class));
    verify(graphIndex, times(0)).removeEdge(any(Edge.class));
    verify(graphIndex, times(0)).addEdge(any(Edge.class));
    verify(graphIndex, times(0)).addNode(any(Node.class));
    verify(graphIndex, times(0)).removeNode(any(Node.class));
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) TestingGraphUtils.verifyConnection(org.kie.workbench.common.stunner.core.TestingGraphUtils.verifyConnection) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) List(java.util.List) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 9 with RuleEvaluationContext

use of org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext in project kie-wb-common by kiegroup.

the class ConnectorParentsMatchHandlerTest method testAcceptNoParentType.

@Test(expected = IllegalArgumentException.class)
public void testAcceptNoParentType() {
    final RuleExtension ruleExtension = mock(RuleExtension.class);
    when(ruleExtension.getArguments()).thenReturn(new String[] {});
    final RuleEvaluationContext context = mock(RuleEvaluationContext.class);
    tested.accepts(ruleExtension, context);
}
Also used : RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) RuleExtension(org.kie.workbench.common.stunner.core.rule.ext.RuleExtension) Test(org.junit.Test)

Example 10 with RuleEvaluationContext

use of org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext in project kie-wb-common by kiegroup.

the class ConnectorParentsMatchHandlerTest method testEvaluate.

@Test(expected = IllegalArgumentException.class)
public void testEvaluate() {
    final RuleExtension ruleExtension = mock(RuleExtension.class);
    when(ruleExtension.getArguments()).thenReturn(new String[] { "parentType" });
    final RuleEvaluationContext context = mock(RuleEvaluationContext.class);
    assertEquals(ruleViolations, tested.evaluate(ruleExtension, context));
    verify(multiHandler, times(1)).evaluate(eq(ruleExtension), eq(context));
}
Also used : RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) RuleExtension(org.kie.workbench.common.stunner.core.rule.ext.RuleExtension) Test(org.junit.Test)

Aggregations

RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)10 Test (org.junit.Test)9 Node (org.kie.workbench.common.stunner.core.graph.Node)4 RuleExtension (org.kie.workbench.common.stunner.core.rule.ext.RuleExtension)4 List (java.util.List)3 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)3 TestingGraphInstanceBuilder (org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder)2 TestingGraphUtils.verifyConnection (org.kie.workbench.common.stunner.core.TestingGraphUtils.verifyConnection)2 Edge (org.kie.workbench.common.stunner.core.graph.Edge)2 DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)2 Connection (org.kie.workbench.common.stunner.core.graph.content.view.Connection)2 MagnetConnection (org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection)2 RuleManager (org.kie.workbench.common.stunner.core.rule.RuleManager)2 RuleSet (org.kie.workbench.common.stunner.core.rule.RuleSet)2 LinkedList (java.util.LinkedList)1 Collectors (java.util.stream.Collectors)1 Dependent (javax.enterprise.context.Dependent)1 Command (org.kie.workbench.common.stunner.core.command.Command)1 RuleViolations (org.kie.workbench.common.stunner.core.rule.RuleViolations)1 DefaultRuleViolations (org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)1