Search in sources :

Example 66 with Command

use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.

the class DMNDiagramsSessionTest method testStoreCurrentRegistryHistory.

@Test
public void testStoreCurrentRegistryHistory() {
    final Map<String, List<Command<AbstractCanvasHandler, CanvasViolation>>> storedRedoHistory = mock(Map.class);
    final Map<String, List<Command<AbstractCanvasHandler, CanvasViolation>>> storedUndoHistory = mock(Map.class);
    final String diagramId = "diagramId";
    final EditorSession editorSession = mock(EditorSession.class);
    final Optional<EditorSession> optionalEditorSession = Optional.of(editorSession);
    final List<Command<AbstractCanvasHandler, CanvasViolation>> undoHistory = mock(List.class);
    final List<Command<AbstractCanvasHandler, CanvasViolation>> redoHistory = mock(List.class);
    final Registry<Command<AbstractCanvasHandler, CanvasViolation>> undoCommandRegistry = mock(Registry.class);
    final Registry<Command<AbstractCanvasHandler, CanvasViolation>> redoCommandRegistry = mock(Registry.class);
    doReturn(storedRedoHistory).when(dmnDiagramsSession).getStoredRedoHistories();
    doReturn(storedUndoHistory).when(dmnDiagramsSession).getStoredUndoHistories();
    doReturn(diagramId).when(dmnDiagramsSession).getCurrentDiagramId();
    doReturn(optionalEditorSession).when(dmnDiagramsSession).getCurrentSession();
    when(editorSession.getCommandRegistry()).thenReturn(undoCommandRegistry);
    when(editorSession.getRedoCommandRegistry()).thenReturn(redoCommandRegistry);
    when(undoCommandRegistry.getHistory()).thenReturn(undoHistory);
    when(redoCommandRegistry.getHistory()).thenReturn(redoHistory);
    dmnDiagramsSession.storeCurrentRegistryHistory();
    verify(storedUndoHistory).put(diagramId, undoHistory);
    verify(storedRedoHistory).put(diagramId, redoHistory);
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Command(org.kie.workbench.common.stunner.core.command.Command) Arrays.asList(java.util.Arrays.asList) List(java.util.List) EditorSession(org.kie.workbench.common.stunner.core.client.session.impl.EditorSession) Test(org.junit.Test)

Example 67 with Command

use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.

the class ElementBuilderControlImplTest method getElementCommandsDocked.

@Test
public void getElementCommandsDocked() {
    ParentAssignment parentAssignment = ParentAssignment.DOCKING;
    elementBuilderControl.getElementCommands(node, parent, parentAssignment, X, Y, callback);
    verify(callback).onComplete(any(), commandsCapture.capture());
    List<Command<AbstractCanvasHandler, CanvasViolation>> commands = commandsCapture.getValue();
    assertTrue(commands.get(0) instanceof AddChildNodeCommand);
    assertTrue(commands.get(1) instanceof UpdateElementPositionCommand);
    assertTrue(commands.get(2) instanceof UpdateDockNodeCommand);
    verify(canvasCommandFactory).addChildNode(grandParent, node, SHAPE_SET_ID);
    ArgumentCaptor<Point2D> positionCaptor = ArgumentCaptor.forClass(Point2D.class);
    verify(canvasCommandFactory).updatePosition(eq(node), positionCaptor.capture());
    assertEquals(positionCaptor.getValue(), new Point2D(X, Y));
    verify(canvasCommandFactory).addChildNode(grandParent, node, SHAPE_SET_ID);
}
Also used : AddNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) UpdateDockNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateDockNodeCommand) AddChildNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddChildNodeCommand) Command(org.kie.workbench.common.stunner.core.command.Command) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) ParentAssignment(org.kie.workbench.common.stunner.core.client.canvas.controls.builder.impl.AbstractElementBuilderControl.ParentAssignment) AddChildNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddChildNodeCommand) UpdateDockNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateDockNodeCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Test(org.junit.Test)

Example 68 with Command

use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.

the class ElementProxyTest method testExecute.

@Test
@SuppressWarnings("unchecked")
public void testExecute() {
    Command c = mock(Command.class);
    tested.execute(c);
    verify(commandManager, times(1)).execute(eq(canvasHandler), eq(c));
    verify(commandManager, never()).allow(any(), any());
}
Also used : Command(org.kie.workbench.common.stunner.core.command.Command) Test(org.junit.Test)

Example 69 with Command

use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.

the class ControlPointControlImplTest method testAddControlPoint.

@Test
@SuppressWarnings("unchecked")
public void testAddControlPoint() {
    final int index = 1;
    final ControlPoint controlPoint = ControlPoint.build(2, 2);
    CanvasCommand<AbstractCanvasHandler> addControlPointCommand = mock(CanvasCommand.class);
    doReturn(addControlPointCommand).when(canvasCommandFactory).addControlPoint(eq(edge), eq(controlPoint), eq(index));
    tested.init(canvasHandler);
    tested.addControlPoint(edge, controlPoint, index);
    ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
    verify(commandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
    Command<AbstractCanvasHandler, CanvasViolation> command = commandArgumentCaptor.getValue();
    assertEquals(addControlPointCommand, command);
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) Command(org.kie.workbench.common.stunner.core.command.Command) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) Test(org.junit.Test)

Example 70 with Command

use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.

the class DeleteNodeCommandTest method intermediateNodeTestCanvasCommands.

@Test
public void intermediateNodeTestCanvasCommands() {
    this.tested = new DeleteNodeCommand(graphHolder.intermNode);
    final CommandResult<CanvasViolation> result = tested.allow(canvasHandler);
    assertEquals(CommandResult.Type.INFO, result.getType());
    final AbstractCompositeCommand<AbstractCanvasHandler, CanvasViolation> compositeCommand = tested.getCommand();
    assertNotNull(compositeCommand);
    assertEquals(7, compositeCommand.size());
    final List<Command<AbstractCanvasHandler, CanvasViolation>> commands = compositeCommand.getCommands();
    assertNotNull(commands);
    final CanvasUndockNodeCommand c1 = (CanvasUndockNodeCommand) commands.get(0);
    final RemoveCanvasChildrenCommand c2 = (RemoveCanvasChildrenCommand) commands.get(1);
    final DeleteCanvasNodeCommand c3 = (DeleteCanvasNodeCommand) commands.get(2);
    final DeleteCanvasConnectorCommand c5 = (DeleteCanvasConnectorCommand) commands.get(3);
    final SetCanvasConnectionCommand c6 = (SetCanvasConnectionCommand) commands.get(4);
    final RemoveCanvasChildrenCommand c4 = (RemoveCanvasChildrenCommand) commands.get(5);
    final DeleteCanvasNodeCommand c7 = (DeleteCanvasNodeCommand) commands.get(6);
    assertEquals(graphHolder.intermNode, c1.getParent());
    assertEquals(graphHolder.dockedNode, c1.getChild());
    assertEquals(graphHolder.dockedNode, c2.getChildren().iterator().next());
    assertEquals(graphHolder.parentNode, c2.getParent());
    assertEquals(graphHolder.dockedNode, c3.getCandidate());
    assertEquals(graphHolder.parentNode, c4.getParent());
    assertEquals(graphHolder.intermNode, c4.getChildren().iterator().next());
    assertEquals(graphHolder.edge2, c5.getCandidate());
    assertEquals(graphHolder.edge1, c6.getEdge());
    assertEquals(graphHolder.intermNode, c7.getCandidate());
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Command(org.kie.workbench.common.stunner.core.command.Command) AbstractCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.AbstractCompositeCommand) SafeDeleteNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.SafeDeleteNodeCommand) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) SafeDeleteNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.SafeDeleteNodeCommand) Test(org.junit.Test)

Aggregations

Command (org.kie.workbench.common.stunner.core.command.Command)74 Test (org.junit.Test)53 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)23 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)22 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)19 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)16 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)14 Edge (org.kie.workbench.common.stunner.core.graph.Edge)12 Node (org.kie.workbench.common.stunner.core.graph.Node)12 List (java.util.List)10 GraphCommandResultBuilder (org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder)10 AbstractGraphCommand (org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand)10 View (org.kie.workbench.common.stunner.core.graph.content.view.View)9 SetCellValueCommand (org.kie.workbench.common.dmn.client.commands.general.SetCellValueCommand)7 Consumer (java.util.function.Consumer)6 UpdateElementPositionCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand)6 ArrayList (java.util.ArrayList)5 AddNodeCommand (org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand)5 Element (org.kie.workbench.common.stunner.core.graph.Element)5 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)5