use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.
the class SafeDeleteNodeCommandRulesTest method testSingleNode.
@Test
@SuppressWarnings("unchecked")
public void testSingleNode() {
CommandResult<RuleViolation> result = tested.allow(graphCommandExecutionContext);
List<Command<GraphCommandExecutionContext, RuleViolation>> commands = tested.getCommands();
assertNotNull(commands);
assertTrue(1 == commands.size());
Command command1 = commands.get(0);
assertTrue(command1 instanceof DeregisterNodeCommand);
assertEquals(CommandResult.Type.INFO, result.getType());
final ArgumentCaptor<RuleEvaluationContext> contextCaptor = ArgumentCaptor.forClass(RuleEvaluationContext.class);
verify(ruleManager, times(1)).evaluate(eq(ruleSet), contextCaptor.capture());
final List<RuleEvaluationContext> contexts = contextCaptor.getAllValues();
assertEquals(1, contexts.size());
verifyCardinality((ElementCardinalityContext) contexts.get(0), graph, node, CardinalityContext.Operation.DELETE);
}
use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.
the class CompositeCommandTest method testExecute1Failed.
@Test
@SuppressWarnings("unchecked")
public void testExecute1Failed() {
Command c1 = mockSuccessCommandOperations();
when(c1.execute(eq(commandExecutionContext))).thenReturn(SOME_ERROR_VIOLATION);
Command c2 = mockSuccessCommandOperations();
Command c3 = mockSuccessCommandOperations();
CompositeCommand command = new CompositeCommand.Builder<>().addCommand(c1).addCommand(c2).addCommand(c3).build();
CommandResult result = command.execute(commandExecutionContext);
assertEquals(CommandResult.Type.ERROR, result.getType());
verify(c1, times(1)).execute(eq(commandExecutionContext));
verify(c1, never()).undo(eq(commandExecutionContext));
verify(c2, never()).execute(eq(commandExecutionContext));
verify(c2, never()).undo(eq(commandExecutionContext));
verify(c3, never()).execute(eq(commandExecutionContext));
verify(c3, never()).undo(eq(commandExecutionContext));
}
use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.
the class CompositeCommandTest method testExecute3FailedThenUndo.
@Test
@SuppressWarnings("unchecked")
public void testExecute3FailedThenUndo() {
Command c1 = mockSuccessCommandOperations();
Command c2 = mockSuccessCommandOperations();
Command c3 = mockSuccessCommandOperations();
when(c3.execute(eq(commandExecutionContext))).thenReturn(SOME_ERROR_VIOLATION);
CompositeCommand command = new CompositeCommand.Builder<>().addCommand(c1).addCommand(c2).addCommand(c3).build();
CommandResult result = command.execute(commandExecutionContext);
assertEquals(CommandResult.Type.ERROR, result.getType());
verify(c1, times(1)).execute(eq(commandExecutionContext));
verify(c1, times(1)).undo(eq(commandExecutionContext));
verify(c2, times(1)).execute(eq(commandExecutionContext));
verify(c2, times(1)).undo(eq(commandExecutionContext));
verify(c3, times(1)).execute(eq(commandExecutionContext));
verify(c3, never()).undo(eq(commandExecutionContext));
}
use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.
the class CompositeCommandTest method testUndo2FailedSoRedo.
@Test
@SuppressWarnings("unchecked")
public void testUndo2FailedSoRedo() {
Command c1 = mockSuccessCommandOperations();
Command c2 = mockSuccessCommandOperations();
when(c2.undo(eq(commandExecutionContext))).thenReturn(SOME_ERROR_VIOLATION);
Command c3 = mockSuccessCommandOperations();
CompositeCommand command = new CompositeCommand.Builder<>().addCommand(c1).addCommand(c2).addCommand(c3).build();
CommandResult result = command.undo(commandExecutionContext);
assertEquals(CommandResult.Type.ERROR, result.getType());
verify(c3, times(1)).undo(eq(commandExecutionContext));
verify(c3, times(1)).execute(eq(commandExecutionContext));
verify(c2, times(1)).undo(eq(commandExecutionContext));
verify(c2, never()).execute(eq(commandExecutionContext));
verify(c1, never()).undo(eq(commandExecutionContext));
verify(c1, never()).execute(eq(commandExecutionContext));
}
use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.
the class DMNDiagramsSessionTest method testLoadHistoryForTheCurrentDiagram_WhenThereIsNotHistoryStored.
@Test
public void testLoadHistoryForTheCurrentDiagram_WhenThereIsNotHistoryStored() {
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 Registry<Command<AbstractCanvasHandler, CanvasViolation>> undoCommandRegistry = mock(Registry.class);
final Registry<Command<AbstractCanvasHandler, CanvasViolation>> redoCommandRegistry = mock(Registry.class);
final List<Command<AbstractCanvasHandler, CanvasViolation>> redoHistory = mock(List.class);
final List<Command<AbstractCanvasHandler, CanvasViolation>> undoHistory = mock(List.class);
doReturn(storedRedoHistory).when(dmnDiagramsSession).getStoredRedoHistories();
doReturn(storedUndoHistory).when(dmnDiagramsSession).getStoredUndoHistories();
doReturn(diagramId).when(dmnDiagramsSession).getCurrentDiagramId();
doReturn(optionalEditorSession).when(dmnDiagramsSession).getCurrentSession();
when(storedRedoHistory.containsKey(diagramId)).thenReturn(false);
when(storedUndoHistory.containsKey(diagramId)).thenReturn(false);
when(editorSession.getCommandRegistry()).thenReturn(undoCommandRegistry);
when(editorSession.getRedoCommandRegistry()).thenReturn(redoCommandRegistry);
when(storedRedoHistory.get(diagramId)).thenReturn(redoHistory);
when(storedUndoHistory.get(diagramId)).thenReturn(undoHistory);
doNothing().when(dmnDiagramsSession).loadHistoryToTheRegistry(redoHistory, redoCommandRegistry);
doNothing().when(dmnDiagramsSession).loadHistoryToTheRegistry(undoHistory, undoCommandRegistry);
dmnDiagramsSession.loadHistoryForTheCurrentDiagram();
verify(dmnDiagramsSession, never()).loadHistoryToTheRegistry(redoHistory, redoCommandRegistry);
verify(dmnDiagramsSession, never()).loadHistoryToTheRegistry(undoHistory, undoCommandRegistry);
verify(dmnDiagramsSession).notifyRegistryChanged();
verify(undoCommandRegistry).clear();
verify(redoCommandRegistry).clear();
}
Aggregations