@Test @SuppressWarnings("unchecked") public void testExecute() { final List lastSourceOutEdges = spy(new ArrayList()); final List sourceOutEdges = spy(new ArrayList()); final List targetInEdges = spy(new ArrayList()); 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)); }
@Override @SuppressWarnings("unchecked") public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { final CommandResult<RuleViolation> results = allow(context); if (!results.getType().equals(CommandResult.Type.ERROR)) { final Edge<? extends View, Node> edge = getEdge(context); final Node<?, Edge> sourceNode = getSourceNode(context); final Node<? extends View<?>, Edge> lastSourceNode = edge.getSourceNode(); if (null != lastSourceNode) { this.lastSourceNodeUUID = lastSourceNode.getUUID(); lastSourceNode.getOutEdges().remove(edge); } if (null != sourceNode) { sourceNode.getOutEdges().add(edge); } edge.setSourceNode(sourceNode); ViewConnector connectionContent = (ViewConnector) edge.getContent(); lastConnection = (Connection) connectionContent.getSourceConnection().orElse(null); connectionContent.setSourceConnection(connection); } return results; }
SetConnectionSourceNodeCommand extends AbstractGraphCommand { @Override @SuppressWarnings("unchecked") public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { final CommandResult<RuleViolation> results = allow(context); if (!results.getType().equals(CommandResult.Type.ERROR)) { final Edge<? extends View, Node> edge = getEdge(context); final Node<?, Edge> sourceNode = getSourceNode(context); final Node<? extends View<?>, Edge> lastSourceNode = edge.getSourceNode(); if (null != lastSourceNode) { this.lastSourceNodeUUID = lastSourceNode.getUUID(); lastSourceNode.getOutEdges().remove(edge); } if (null != sourceNode) { sourceNode.getOutEdges().add(edge); } edge.setSourceNode(sourceNode); ViewConnector connectionContent = (ViewConnector) edge.getContent(); lastConnection = (Connection) connectionContent.getSourceConnection().orElse(null); connectionContent.setSourceConnection(connection); } return results; } }
SetConnectionSourceNodeCommand extends AbstractGraphCommand { @Override @SuppressWarnings("unchecked") public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { final CommandResult<RuleViolation> results = allow(context); if (!results.getType().equals(CommandResult.Type.ERROR)) { final Edge<? extends View, Node> edge = getEdge(context); final Node<?, Edge> sourceNode = getSourceNode(context); final Node<? extends View<?>, Edge> lastSourceNode = edge.getSourceNode(); if (null != lastSourceNode) { this.lastSourceNodeUUID = lastSourceNode.getUUID(); lastSourceNode.getOutEdges().remove(edge); } if (null != sourceNode) { sourceNode.getOutEdges().add(edge); } edge.setSourceNode(sourceNode); ViewConnector connectionContent = (ViewConnector) edge.getContent(); lastConnection = (Connection) connectionContent.getSourceConnection().orElse(null); connectionContent.setSourceConnection(connection); } return results; } @SuppressWarnings("unchecked")  SetConnectionSourceNodeCommand(final @MapsTo("sourceNodeUUID") String sourceNodeUUID,
                                          final @MapsTo("edgeUUID") String edgeUUID,
                                          final @MapsTo("magnet") Connection connection); @SuppressWarnings("unchecked")  SetConnectionSourceNodeCommand(final Node<? extends View<?>, Edge> sourceNode,
                                          final Edge<? extends View, Node> edge,
                                          final Connection connection); @SuppressWarnings("unchecked")  SetConnectionSourceNodeCommand(final Node<? extends View<?>, Edge> sourceNode,
                                          final Edge<? extends View, Node> edge); }
SetConnectionSourceNodeCommand extends AbstractGraphCommand { @Override @SuppressWarnings("unchecked") public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { final CommandResult<RuleViolation> results = allow(context); if (!results.getType().equals(CommandResult.Type.ERROR)) { final Edge<? extends View, Node> edge = getEdge(context); final Node<?, Edge> sourceNode = getSourceNode(context); final Node<? extends View<?>, Edge> lastSourceNode = edge.getSourceNode(); if (null != lastSourceNode) { this.lastSourceNodeUUID = lastSourceNode.getUUID(); lastSourceNode.getOutEdges().remove(edge); } if (null != sourceNode) { sourceNode.getOutEdges().add(edge); } edge.setSourceNode(sourceNode); ViewConnector connectionContent = (ViewConnector) edge.getContent(); lastConnection = (Connection) connectionContent.getSourceConnection().orElse(null); connectionContent.setSourceConnection(connection); } return results; } @SuppressWarnings("unchecked")  SetConnectionSourceNodeCommand(final @MapsTo("sourceNodeUUID") String sourceNodeUUID,
                                          final @MapsTo("edgeUUID") String edgeUUID,
                                          final @MapsTo("magnet") Connection connection); @SuppressWarnings("unchecked")  SetConnectionSourceNodeCommand(final Node<? extends View<?>, Edge> sourceNode,
                                          final Edge<? extends View, Node> edge,
                                          final Connection connection); @SuppressWarnings("unchecked")  SetConnectionSourceNodeCommand(final Node<? extends View<?>, Edge> sourceNode,
                                          final Edge<? extends View, Node> edge); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context); @SuppressWarnings("unchecked") Node<? extends View<?>, Edge> getTargetNode(final GraphCommandExecutionContext context); @SuppressWarnings("unchecked") Node<? extends View<?>, Edge> getSourceNode(final GraphCommandExecutionContext context); Edge<? extends View, Node> getEdge(final GraphCommandExecutionContext context); Node<? extends View<?>, Edge> getSourceNode(); Edge<? extends View, Node> getEdge(); Node<? extends View<?>, Edge> getTargetNode(); Connection getConnection(); @Override String toString(); }
SetConnectionSourceNodeCommand extends AbstractGraphCommand { @Override @SuppressWarnings("unchecked") public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { final CommandResult<RuleViolation> results = allow(context); if (!results.getType().equals(CommandResult.Type.ERROR)) { final Edge<? extends View, Node> edge = getEdge(context); final Node<?, Edge> sourceNode = getSourceNode(context); final Node<? extends View<?>, Edge> lastSourceNode = edge.getSourceNode(); if (null != lastSourceNode) { this.lastSourceNodeUUID = lastSourceNode.getUUID(); lastSourceNode.getOutEdges().remove(edge); } if (null != sourceNode) { sourceNode.getOutEdges().add(edge); } edge.setSourceNode(sourceNode); ViewConnector connectionContent = (ViewConnector) edge.getContent(); lastConnection = (Connection) connectionContent.getSourceConnection().orElse(null); connectionContent.setSourceConnection(connection); } return results; } @SuppressWarnings("unchecked")  SetConnectionSourceNodeCommand(final @MapsTo("sourceNodeUUID") String sourceNodeUUID,
                                          final @MapsTo("edgeUUID") String edgeUUID,
                                          final @MapsTo("magnet") Connection connection); @SuppressWarnings("unchecked")  SetConnectionSourceNodeCommand(final Node<? extends View<?>, Edge> sourceNode,
                                          final Edge<? extends View, Node> edge,
                                          final Connection connection); @SuppressWarnings("unchecked")  SetConnectionSourceNodeCommand(final Node<? extends View<?>, Edge> sourceNode,
                                          final Edge<? extends View, Node> edge); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context); @SuppressWarnings("unchecked") Node<? extends View<?>, Edge> getTargetNode(final GraphCommandExecutionContext context); @SuppressWarnings("unchecked") Node<? extends View<?>, Edge> getSourceNode(final GraphCommandExecutionContext context); Edge<? extends View, Node> getEdge(final GraphCommandExecutionContext context); Node<? extends View<?>, Edge> getSourceNode(); Edge<? extends View, Node> getEdge(); Node<? extends View<?>, Edge> getTargetNode(); Connection getConnection(); @Override String toString();  }