use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.
the class CompositeCommandTest method testUndo1FailedSoRedo.
@Test
@SuppressWarnings("unchecked")
public void testUndo1FailedSoRedo() {
Command c1 = mockSuccessCommandOperations();
when(c1.undo(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.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, times(1)).execute(eq(commandExecutionContext));
verify(c1, times(1)).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 CompositeCommandTest method testUndo3Failed.
@Test
@SuppressWarnings("unchecked")
public void testUndo3Failed() {
Command c1 = mockSuccessCommandOperations();
Command c2 = mockSuccessCommandOperations();
Command c3 = mockSuccessCommandOperations();
when(c3.undo(eq(commandExecutionContext))).thenReturn(SOME_ERROR_VIOLATION);
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, never()).execute(eq(commandExecutionContext));
verify(c2, never()).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 CompositeCommandBuilderTest method testAddFirstCommand.
@Test
public void testAddFirstCommand() throws Exception {
Command c1 = mock(Command.class);
Command c2 = mock(Command.class);
Command c3 = mock(Command.class);
builder.addFirstCommand(c1);
builder.addFirstCommand(c2);
builder.addFirstCommand(c3);
assertEquals(c3, builder.get(0));
assertEquals(c2, builder.get(1));
assertEquals(c1, builder.get(2));
}
use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.
the class DeferredCompositeCommandTest method testExecuteSuccessful.
@Test
@SuppressWarnings("unchecked")
public void testExecuteSuccessful() {
// c1 command succeeded
Command c1 = mockCommand(SUCCESS, SUCCESS);
// c2 command succeeded
Command c2 = mockCommand(SUCCESS, SUCCESS);
// c3 command succeed
Command c3 = mockCommand(SUCCESS, SUCCESS);
// c4 command succeeded
Command c4 = mockCommand(SUCCESS, SUCCESS);
compositeCommand = buildCompositeCommand(c1, c2, c3, c4);
compositeCommand.execute(commandExecutionContext);
// c1, c2, c3, c4, must have been allowed and executed
verifyAllowedAndExecuted(c1);
verifyAllowedAndExecuted(c2);
verifyAllowedAndExecuted(c3);
verifyAllowedAndExecuted(c4);
}
use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.
the class DeferredCompositeCommandTest method testExecuteWithExecutionFailure.
@Test
@SuppressWarnings("unchecked")
public void testExecuteWithExecutionFailure() {
// c1 command succeeded
Command c1 = mockCommand(SUCCESS, SUCCESS);
// c2 command allowance succeeded but execution failed
Command c2 = mockCommand(SUCCESS, failed());
// no matter
Command c3 = mockCommand(SUCCESS, SUCCESS);
// no matter
Command c4 = mockCommand(SUCCESS, SUCCESS);
compositeCommand = buildCompositeCommand(c1, c2, c3, c4);
compositeCommand.execute(commandExecutionContext);
// c1 must have been allowed, executed and undone
verifyAllowedExecutedAndUnDone(c1);
// c2 must have been allowed, executed and undone
verifyAllowedAndExecuted(c2);
verifyNeverUsed(c3);
verifyNeverUsed(c4);
}
Aggregations