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);
}
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);
}
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());
}
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);
}
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());
}
Aggregations