use of org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext 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.RuleEvaluationContext in project kie-wb-common by kiegroup.
the class RuleExtensionMultiHandler method evaluate.
@Override
@SuppressWarnings("unchecked")
public RuleViolations evaluate(final RuleExtension rule, final RuleEvaluationContext context) {
final List<RuleExtensionHandler> candidates = handlers.stream().filter(h -> isHandlerAccepted(h, rule, context)).collect(Collectors.toList());
final DefaultRuleViolations result = new DefaultRuleViolations();
candidates.forEach(candidate -> result.addViolations(candidate.evaluate(rule, context)));
return result;
}
use of org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext in project kie-wb-common by kiegroup.
the class SetConnectionTargetNodeCommandTest method testExecute.
@Test
@SuppressWarnings("unchecked")
public void testExecute() {
final List lastTargetInEdges = mock(List.class);
final List sourceOutEdges = mock(List.class);
final List targetInEdges = mock(List.class);
when(source.getOutEdges()).thenReturn(sourceOutEdges);
when(lastTargetNode.getInEdges()).thenReturn(lastTargetInEdges);
when(node.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, source, node);
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(1), graph, lastTargetNode, edge, EdgeCardinalityContext.Direction.INCOMING, Optional.of(CardinalityContext.Operation.DELETE));
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(2), graph, node, edge, EdgeCardinalityContext.Direction.INCOMING, Optional.of(CardinalityContext.Operation.ADD));
assertEquals(CommandResult.Type.INFO, result.getType());
verify(lastTargetInEdges, times(1)).remove(eq(edge));
verify(targetInEdges, times(1)).add(eq(edge));
verify(edgeContent, times(1)).setTargetConnection(any(Connection.class));
verify(edge, times(1)).setTargetNode(eq(node));
verify(targetInEdges, times(0)).remove(any(Edge.class));
verify(sourceOutEdges, 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));
}
use of org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext in project kie-wb-common by kiegroup.
the class ConnectorParentsMatchHandlerTest method testAccept.
@Test(expected = IllegalArgumentException.class)
public void testAccept() {
final RuleExtension ruleExtension = mock(RuleExtension.class);
when(ruleExtension.getArguments()).thenReturn(new String[] { "parentType" });
final RuleEvaluationContext context = mock(RuleEvaluationContext.class);
assertTrue(tested.accepts(ruleExtension, context));
verify(multiHandler, times(1)).accepts(eq(ruleExtension), eq(context));
}
use of org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext in project kie-wb-common by kiegroup.
the class ConnectorParentsMatchHandlerTest method testEvaluateNoParentType.
@Test(expected = IllegalArgumentException.class)
public void testEvaluateNoParentType() {
final RuleExtension ruleExtension = mock(RuleExtension.class);
when(ruleExtension.getArguments()).thenReturn(new String[] {});
final RuleEvaluationContext context = mock(RuleEvaluationContext.class);
tested.evaluate(ruleExtension, context);
}
Aggregations