Search in sources :

Example 61 with Command

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

Example 62 with Command

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));
}
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 63 with Command

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));
}
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 64 with Command

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));
}
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 65 with Command

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();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Command(org.kie.workbench.common.stunner.core.command.Command) Arrays.asList(java.util.Arrays.asList) List(java.util.List) EditorSession(org.kie.workbench.common.stunner.core.client.session.impl.EditorSession) 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