Search in sources :

Example 21 with Command

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));
}
Also used : AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) Command(org.kie.workbench.common.stunner.core.command.Command) GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) Test(org.junit.Test)

Example 22 with Command

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));
}
Also used : AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) Command(org.kie.workbench.common.stunner.core.command.Command) GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) Test(org.junit.Test)

Example 23 with Command

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));
}
Also used : Command(org.kie.workbench.common.stunner.core.command.Command) Test(org.junit.Test)

Example 24 with Command

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);
}
Also used : Command(org.kie.workbench.common.stunner.core.command.Command) Test(org.junit.Test)

Example 25 with Command

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);
}
Also used : Command(org.kie.workbench.common.stunner.core.command.Command) 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