use of org.kie.workbench.common.stunner.core.rule.RuleViolation 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.RuleViolation in project kie-wb-common by kiegroup.
the class SetParentNodeCommandTest method testNotAllowed.
@Test
@SuppressWarnings("unchecked")
public void testNotAllowed() {
final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations().addViolation(new ContainmentRuleViolation(graph.getUUID(), PARENT_UUID));
when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS);
CommandResult<RuleViolation> result = tested.allow(graphCommandExecutionContext);
assertEquals(CommandResult.Type.ERROR, result.getType());
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class SetParentNodeCommandTest method testExecute.
@Test
@SuppressWarnings("unchecked")
public void testExecute() {
CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
assertEquals(CommandResult.Type.INFO, result.getType());
assertFalse(parent.getOutEdges().isEmpty());
assertFalse(candidate.getInEdges().isEmpty());
Edge edge = (Edge) parent.getOutEdges().get(0);
assertTrue(edge.getContent() instanceof Parent);
assertEquals(parent, edge.getSourceNode());
assertEquals(candidate, edge.getTargetNode());
verify(graphIndex, times(1)).addEdge(eq(edge));
verify(graphIndex, times(0)).addNode(any(Node.class));
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class UpdateElementPositionCommandTest method testExecute.
@Test
public void testExecute() {
CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
ArgumentCaptor<Bounds> bounds = ArgumentCaptor.forClass(Bounds.class);
verify(content, times(1)).setBounds(bounds.capture());
assertEquals(CommandResult.Type.INFO, result.getType());
Bounds b = bounds.getValue();
assertEquals(UUID, tested.getUuid());
assertEquals(LOCATION, tested.getLocation());
assertEquals(PREVIOUS_LOCATION, tested.getPreviousLocation());
assertEquals(PREVIOUS_LOCATION.getY(), tested.getPreviousLocation().getY(), 0d);
assertEquals(Double.valueOf(LOCATION.getX() + W), b.getLowerRight().getX());
assertEquals(Double.valueOf(LOCATION.getY() + H), b.getLowerRight().getY());
}
use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.
the class RuleExtensionMultiHandlerTest method testEvaluateAll.
@Test
@SuppressWarnings("unchecked")
public void testEvaluateAll() {
when(handler1.accepts(eq(rule1), eq(context))).thenReturn(true);
when(handler2.accepts(eq(rule1), eq(context))).thenReturn(true);
when(handler1.evaluate(eq(rule1), eq(context))).thenReturn(violations1);
when(handler2.evaluate(eq(rule1), eq(context))).thenReturn(violations1);
final RuleViolations result = tested.evaluate(rule1, context);
assertNotNull(result);
final Collection<RuleViolation> violations = (Collection<RuleViolation>) result.violations();
assertTrue(violations.size() == 2);
assertTrue(violations.contains(violation1));
assertTrue(violations.contains(violation1));
}
Aggregations