use of org.kie.workbench.common.stunner.core.command.CommandResult in project kie-wb-common by kiegroup.
the class CommandRegistryListenerTest method testUndoFailed.
@Test
@SuppressWarnings("unchecked")
public void testUndoFailed() {
Object context = mock(Object.class);
Command command = mock(Command.class);
CommandResult result = mock(CommandResult.class);
when(result.getType()).thenReturn(CommandResult.Type.ERROR);
tested.onUndo(context, command, result);
verify(commandRegistry, times(0)).pop();
verify(commandRegistry, times(0)).peek();
verify(commandRegistry, times(0)).register(any(Command.class));
}
use of org.kie.workbench.common.stunner.core.command.CommandResult in project kie-wb-common by kiegroup.
the class CommandRegistryListenerTest method testExecuteSuccess.
@Test
@SuppressWarnings("unchecked")
public void testExecuteSuccess() {
Object context = mock(Object.class);
Command command = mock(Command.class);
CommandResult result = mock(CommandResult.class);
when(result.getType()).thenReturn(CommandResult.Type.INFO);
tested.onExecute(context, command, result);
verify(commandRegistry, times(1)).register(eq(command));
verify(commandRegistry, times(0)).pop();
verify(commandRegistry, times(0)).peek();
}
use of org.kie.workbench.common.stunner.core.command.CommandResult in project kie-wb-common by kiegroup.
the class CommandRegistryListenerTest method testUndoSuccess.
@Test
@SuppressWarnings("unchecked")
public void testUndoSuccess() {
Object context = mock(Object.class);
Command command = mock(Command.class);
CommandResult result = mock(CommandResult.class);
when(result.getType()).thenReturn(CommandResult.Type.INFO);
tested.onUndo(context, command, result);
verify(commandRegistry, times(1)).pop();
verify(commandRegistry, times(0)).peek();
verify(commandRegistry, times(0)).register(any(Command.class));
}
use of org.kie.workbench.common.stunner.core.command.CommandResult in project kie-wb-common by kiegroup.
the class CompositeCommandTest method testExecuteFailedThenUndo.
@Test
@SuppressWarnings("unchecked")
public void testExecuteFailedThenUndo() {
Command c1 = mock(Command.class);
when(c1.allow(eq(commandExecutionContext))).thenReturn(GraphCommandResultBuilder.SUCCESS);
when(c1.execute(eq(commandExecutionContext))).thenReturn(GraphCommandResultBuilder.SUCCESS);
Command c2 = mock(Command.class);
when(c2.allow(eq(commandExecutionContext))).thenReturn(GraphCommandResultBuilder.SUCCESS);
when(c2.execute(eq(commandExecutionContext))).thenReturn(GraphCommandResultBuilder.SUCCESS);
CommandResult<RuleViolation> failed = new CommandResultImpl<>(CommandResult.Type.ERROR, Collections.singletonList(new RuleViolationImpl("failed")));
Command c3 = mock(Command.class);
when(c3.allow(eq(commandExecutionContext))).thenReturn(GraphCommandResultBuilder.SUCCESS);
when(c3.execute(eq(commandExecutionContext))).thenReturn(failed);
CompositeCommand composite = new CompositeCommand.Builder<>().addCommand(c1).addCommand(c2).addCommand(c3).build();
CommandResult result = composite.execute(commandExecutionContext);
assertEquals(CommandResult.Type.ERROR, result.getType());
verify(c1, times(1)).undo(eq(commandExecutionContext));
verify(c2, times(1)).undo(eq(commandExecutionContext));
verify(c3, times(1)).undo(eq(commandExecutionContext));
}
use of org.kie.workbench.common.stunner.core.command.CommandResult in project kie-wb-common by kiegroup.
the class PasteSelectionSessionCommandTest method executeWithMultiSelection.
@Test
@SuppressWarnings("unchecked")
public void executeWithMultiSelection() {
pasteSelectionSessionCommand.bind(session);
// Mock the callback of CloneNodeCommand
ArgumentCaptor<Consumer> consumerNode = ArgumentCaptor.forClass(Consumer.class);
ArgumentCaptor<Consumer> consumerNode2 = ArgumentCaptor.forClass(Consumer.class);
when(cloneNodeCommand.getCandidate()).thenReturn(node);
when(cloneNodeCommand2.getCandidate()).thenReturn(node2);
when(canvasCommandFactory.cloneNode(eq(node), any(), any(), consumerNode.capture())).thenReturn(cloneNodeCommand);
when(canvasCommandFactory.cloneNode(eq(node2), any(), any(), consumerNode2.capture())).thenReturn(cloneNodeCommand2);
Map<Node, ArgumentCaptor<Consumer>> consumerMap = new HashMap() {
{
put(node, consumerNode);
put(node2, consumerNode2);
}
};
// Mock the callback of CloneConnectorCommand
ArgumentCaptor<Consumer> consumerEdge = ArgumentCaptor.forClass(Consumer.class);
when(canvasCommandFactory.cloneConnector(any(), anyString(), anyString(), anyString(), consumerEdge.capture())).thenReturn(cloneConnectorCommand);
// apply callbacks mocks
when(sessionCommandManager.execute(eq(canvasHandler), any())).thenAnswer(param -> {
CompositeCommand argument = param.getArgumentAt(1, CompositeCommand.class);
// callback to nodes
argument.getCommands().stream().filter(c -> c instanceof CloneNodeCommand).forEach(c -> {
CloneNodeCommand cloneNodeCommand = (CloneNodeCommand) c;
Node candidate = cloneNodeCommand.getCandidate();
consumerMap.get(candidate).getValue().accept(cloneMap.get(candidate));
});
// callback to connectors
argument.getCommands().stream().filter(c -> c instanceof CloneConnectorCommand).forEach(c -> consumerEdge.getValue().accept(cloneEdge));
return commandResult;
});
// Executing the command
clipboardControl.set(graphInstance.startNode, graphInstance.edge1, graphInstance.intermNode);
when(selectionControl.getSelectedItems()).thenReturn(Arrays.asList(graphInstance.startNode.getUUID(), graphInstance.edge1.getUUID(), graphInstance.intermNode.getUUID()));
pasteSelectionSessionCommand.execute(callback);
verify(canvasCommandFactory, times(1)).cloneNode(eq(graphInstance.startNode), eq(graphInstance.parentNode.getUUID()), eq(new Point2D(X, DEFAULT_PADDING + Y + NODE_SIZE)), any());
verify(canvasCommandFactory, times(1)).cloneConnector(eq(graphInstance.edge1), anyString(), anyString(), anyString(), any());
// check command registry update after execution to allow a single undo/redo
verify(commandRegistry, times(2)).pop();
ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
verify(commandRegistry, times(1)).register(commandArgumentCaptor.capture());
assertTrue(commandArgumentCaptor.getValue() instanceof CompositeCommand);
assertEquals(((CompositeCommand) commandArgumentCaptor.getValue()).size(), 2);
}
Aggregations