use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.
the class SetChildNodeCommandTest 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 Child);
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.graph.Edge 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.graph.Edge 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.graph.Edge in project kie-wb-common by kiegroup.
the class GraphBoundsIndexerImplTest method testGetAreaAt.
@Test
public void testGetAreaAt() {
Point2D position = GraphUtils.getPosition((View) graphInstanceParent.startNode.getContent());
double[] size = GraphUtils.getNodeSize((View) graphInstanceParent.startNode.getContent());
double getAtX = position.getX() + (size[0] / 2);
double getAtY = position.getY() + (size[1] / 2);
Node<View<?>, Edge> node = graphBoundsIndexerImpl.getAt(getAtX, getAtY, size[0], size[1], graphInstanceParent.parentNode);
assertNotNull(node);
Node<View<?>, Edge> nodeFreePosition = graphBoundsIndexerImpl.getAt(getAtX, getAtY + 400, size[0], size[1], graphInstanceParent.parentNode);
assertNull(nodeFreePosition);
}
use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.
the class GraphBoundsIndexerImplTest method testGetAreaAtWithParent.
@Test
public void testGetAreaAtWithParent() {
Point2D position = GraphUtils.getPosition((View) graphInstanceParent.startNode.getContent());
double[] size = GraphUtils.getNodeSize((View) graphInstanceParent.startNode.getContent());
double getAtX = position.getX() + (size[0] / 2);
double getAtY = position.getY() + (size[1] / 2);
Node<View<?>, Edge> node = graphBoundsIndexerImpl.getAt(getAtX, getAtY, size[0], size[1], graphInstanceParent.parentNode);
assertNotNull(node);
Node<View<?>, Edge> nodeAtFreePosition = graphBoundsIndexerImpl.getAt(getAtX, getAtY + 200, size[0], size[1], graphInstanceParent.parentNode);
assertNull(nodeAtFreePosition);
}
Aggregations