use of org.kie.workbench.common.stunner.core.client.canvas.command.AddConnectorCommand in project kie-wb-common by kiegroup.
the class GeneralCreateNodeActionTest method testExecuteAction.
@Test
public void testExecuteAction() {
final AbstractCanvasHandler canvasHandler = mock(AbstractCanvasHandler.class);
final String sourceNodeId = "src-id";
final String targetNodeId = "dest-id";
final String connectorId = "edge-id";
final AbstractCanvas canvas = mock(AbstractCanvas.class);
doReturn(canvas).when(canvasHandler).getCanvas();
doReturn(canvas).when(canvasHandler).getAbstractCanvas();
final Diagram diagram = mock(Diagram.class);
doReturn(diagram).when(canvasHandler).getDiagram();
final Metadata metadata = mock(Metadata.class);
doReturn(metadata).when(diagram).getMetadata();
final String shapeSetId = "shape-set-id";
doReturn(shapeSetId).when(metadata).getShapeSetId();
final Index graphIndex = mock(Index.class);
doReturn(graphIndex).when(canvasHandler).getGraphIndex();
final Element sourceElement = mock(Element.class);
doReturn(sourceElement).when(graphIndex).get(sourceNodeId);
final Node sourceNode = mock(Node.class);
final View sourceElementContent = mock(View.class);
doReturn(sourceElementContent).when(sourceNode).getContent();
doReturn(Bounds.create(10d, 0d, 200d, 100d)).when(sourceElementContent).getBounds();
doReturn(sourceNode).when(sourceElement).asNode();
doReturn(Collections.emptyList()).when(sourceNode).getInEdges();
final Element targetNodeElement = mock(Element.class);
doReturn(targetNodeElement).when(clientFactoryManager).newElement(anyString(), eq(targetNodeId));
final Node targetNode = mock(Node.class);
final View targetElementContent = mock(View.class);
doReturn(targetElementContent).when(targetNode).getContent();
doReturn(Bounds.create(-100d, 0d, 0d, 100d)).when(targetElementContent).getBounds();
doReturn(targetNode).when(targetNodeElement).asNode();
final String targetNodeUuid = "target-uuid";
doReturn(targetNodeUuid).when(targetNode).getUUID();
final Element connectorElement = mock(Element.class);
doReturn(connectorElement).when(clientFactoryManager).newElement(anyString(), eq(connectorId));
final Edge connectorEdge = mock(Edge.class);
doReturn(connectorEdge).when(connectorElement).asEdge();
when(canvasLayoutUtils.getNext(eq(canvasHandler), eq(sourceNode), eq(targetNode))).thenReturn(new Point2D(100d, 500d));
createNodeAction.executeAction(canvasHandler, sourceNodeId, targetNodeId, connectorId);
final ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
verify(sessionCommandManager).execute(eq(canvasHandler), commandArgumentCaptor.capture());
final DeferredCompositeCommand command = (DeferredCompositeCommand) commandArgumentCaptor.getValue();
final DeferredCommand c0 = (DeferredCommand) command.getCommands().get(0);
final DeferredCommand c1 = (DeferredCommand) command.getCommands().get(1);
final DeferredCommand c2 = (DeferredCommand) command.getCommands().get(2);
final DeferredCommand c3 = (DeferredCommand) command.getCommands().get(3);
final AddNodeCommand addNodeCommand = (AddNodeCommand) c0.getCommand();
final UpdateElementPositionCommand updateElementPositionCommand = (UpdateElementPositionCommand) c1.getCommand();
final AddConnectorCommand addConnectorCommand = (AddConnectorCommand) c2.getCommand();
final SetConnectionTargetNodeCommand setTargetNodeCommand = (SetConnectionTargetNodeCommand) c3.getCommand();
Assertions.assertThat(targetNode).isEqualTo(addNodeCommand.getCandidate());
Assertions.assertThat(shapeSetId).isEqualTo(addNodeCommand.getShapeSetId());
Assertions.assertThat(connectorEdge).isEqualTo(addConnectorCommand.getCandidate());
Assertions.assertThat(sourceNode).isEqualTo(addConnectorCommand.getSource());
Assertions.assertThat(shapeSetId).isEqualTo(addConnectorCommand.getShapeSetId());
Assertions.assertThat(connectorEdge).isEqualTo(setTargetNodeCommand.getEdge());
Assertions.assertThat(targetNode).isEqualTo(setTargetNodeCommand.getNode());
Assertions.assertThat(targetNode).isEqualTo(updateElementPositionCommand.getElement());
Assertions.assertThat(new Point2D(100d, 500d)).isEqualTo(updateElementPositionCommand.getLocation());
final ArgumentCaptor<CanvasSelectionEvent> eventArgumentCaptor = ArgumentCaptor.forClass(CanvasSelectionEvent.class);
verify(selectionEvent).fire(eventArgumentCaptor.capture());
final CanvasSelectionEvent eCaptured = eventArgumentCaptor.getValue();
Assertions.assertThat(targetNodeUuid).isEqualTo(eCaptured.getIdentifiers().iterator().next());
Assertions.assertThat(addConnectorCommand.getConnection()).isInstanceOf(MagnetConnection.class);
Assertions.assertThat(((MagnetConnection) addConnectorCommand.getConnection()).getMagnetIndex().getAsInt()).isEqualTo(MagnetConnection.MAGNET_LEFT);
Assertions.assertThat(setTargetNodeCommand.getConnection()).isInstanceOf(MagnetConnection.class);
Assertions.assertThat(((MagnetConnection) setTargetNodeCommand.getConnection()).getMagnetIndex().getAsInt()).isEqualTo(MagnetConnection.MAGNET_RIGHT);
}
use of org.kie.workbench.common.stunner.core.client.canvas.command.AddConnectorCommand in project kie-wb-common by kiegroup.
the class CreateNodeActionTest method testAction.
@Test
@SuppressWarnings("unchecked")
public void testAction() {
when(canvasLayoutUtils.getNext(eq(canvasHandler), eq(element), eq(targetNode))).thenReturn(new Point2D(100d, 500d));
final MouseClickEvent event = mock(MouseClickEvent.class);
when(event.getX()).thenReturn(100d);
when(event.getY()).thenReturn(500d);
ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, NODE_UUID, event);
assertEquals(tested, cascade);
ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
verify(sessionCommandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
DeferredCompositeCommand command = (DeferredCompositeCommand) commandArgumentCaptor.getValue();
DeferredCommand c0 = (DeferredCommand) command.getCommands().get(0);
DeferredCommand c1 = (DeferredCommand) command.getCommands().get(1);
DeferredCommand c2 = (DeferredCommand) command.getCommands().get(2);
DeferredCommand c3 = (DeferredCommand) command.getCommands().get(3);
AddNodeCommand addNodeCommand = (AddNodeCommand) c0.getCommand();
UpdateElementPositionCommand updateElementPositionCommand = (UpdateElementPositionCommand) c1.getCommand();
AddConnectorCommand addConnectorCommand = (AddConnectorCommand) c2.getCommand();
SetConnectionTargetNodeCommand setTargetNodeCommand = (SetConnectionTargetNodeCommand) c3.getCommand();
assertEquals(targetNode, addNodeCommand.getCandidate());
assertEquals("ss1", addNodeCommand.getShapeSetId());
assertEquals(edge, addConnectorCommand.getCandidate());
assertEquals(element, addConnectorCommand.getSource());
assertEquals("ss1", addConnectorCommand.getShapeSetId());
assertEquals(edge, setTargetNodeCommand.getEdge());
assertEquals(targetNode, setTargetNodeCommand.getNode());
assertEquals(targetNode, updateElementPositionCommand.getElement());
assertEquals(new Point2D(100d, 500d), updateElementPositionCommand.getLocation());
final ArgumentCaptor<CanvasSelectionEvent> eventArgumentCaptor = ArgumentCaptor.forClass(CanvasSelectionEvent.class);
verify(canvasElementSelectedEvent, times(1)).fire(eventArgumentCaptor.capture());
final CanvasSelectionEvent eCaptured = eventArgumentCaptor.getValue();
assertEquals(TARGET_NODE_UUID, eCaptured.getIdentifiers().iterator().next());
}
Aggregations