Search in sources :

Example 71 with Command

use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.

the class DeleteNodeCommandTest method startNodeTestCanvasCommands.

@Test
public void startNodeTestCanvasCommands() {
    this.tested = new DeleteNodeCommand(graphHolder.startNode);
    final CommandResult<CanvasViolation> result = tested.allow(canvasHandler);
    final AbstractCompositeCommand<AbstractCanvasHandler, CanvasViolation> compositeCommand = tested.getCommand();
    assertNotNull(compositeCommand);
    assertTrue(3 == compositeCommand.size());
    final List<Command<AbstractCanvasHandler, CanvasViolation>> commands = compositeCommand.getCommands();
    assertNotNull(commands);
    final DeleteCanvasConnectorCommand delete1 = (DeleteCanvasConnectorCommand) commands.get(0);
    assertNotNull(delete1);
    assertEquals(graphHolder.edge1, delete1.getCandidate());
    final RemoveCanvasChildrenCommand c2 = (RemoveCanvasChildrenCommand) commands.get(1);
    assertNotNull(c2);
    assertEquals(graphHolder.parentNode, c2.getParent());
    assertEquals(graphHolder.startNode, c2.getChildren().iterator().next());
    final DeleteCanvasNodeCommand c3 = (DeleteCanvasNodeCommand) commands.get(2);
    assertNotNull(c3);
    assertEquals(graphHolder.startNode, c3.getCandidate());
    assertEquals(CommandResult.Type.INFO, result.getType());
}
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) AbstractCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.AbstractCompositeCommand) SafeDeleteNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.SafeDeleteNodeCommand) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) SafeDeleteNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.SafeDeleteNodeCommand) Test(org.junit.Test)

Example 72 with Command

use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.

the class CloneConnectorCommandTest method newCanvasCommand.

@Test
@SuppressWarnings("unchecked")
public void newCanvasCommand() {
    Command<AbstractCanvasHandler, CanvasViolation> command = cloneConnectorCommand.newCanvasCommand(context);
    assertTrue(command instanceof CompositeCommand);
    Consumer<Edge> cloneCallback = cloneConnectorCommand.getCloneCallback();
    cloneCallback.accept(clone);
    CompositeCommand compositeCommand = (CompositeCommand) command;
    assertTrue(compositeCommand.getCommands().stream().anyMatch(c -> c instanceof AddCanvasConnectorCommand));
    assertEquals(((AddCanvasConnectorCommand) compositeCommand.getCommands().stream().filter(c -> c instanceof AddCanvasConnectorCommand).findFirst().get()).getCandidate(), clone);
    assertTrue(compositeCommand.getCommands().stream().anyMatch(c -> c instanceof SetCanvasConnectionCommand));
    assertEquals(((SetCanvasConnectionCommand) compositeCommand.getCommands().stream().filter(c -> c instanceof SetCanvasConnectionCommand).findFirst().get()).getEdge(), clone);
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) Mock(org.mockito.Mock) Edge(org.kie.workbench.common.stunner.core.graph.Edge) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) UUID(org.kie.workbench.common.stunner.core.util.UUID) Consumer(java.util.function.Consumer) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Command(org.kie.workbench.common.stunner.core.command.Command) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Edge(org.kie.workbench.common.stunner.core.graph.Edge) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) Test(org.junit.Test)

Example 73 with Command

use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.

the class BPMNGraphFactoryImplTest method testBuild.

@Test
@SuppressWarnings("unchecked")
public void testBuild() {
    final Node diagramNode = mock(Node.class);
    final Node startEventNode = mock(Node.class);
    when(factoryManager.newElement(anyString(), eq(getDefinitionId(BPMNDiagramImpl.class)))).thenReturn(diagramNode);
    final Graph<DefinitionSet, Node> graph = tested.build("uuid1", "defSetId");
    assertNotNull(graph);
    assertEquals("uuid1", graph.getUUID());
    assertEquals(1, graph.getLabels().size());
    assertTrue(graph.getLabels().contains("defSetId"));
    final ArgumentCaptor<Command> commandCaptor = ArgumentCaptor.forClass(Command.class);
    verify(graphCommandFactory, times(1)).addNode(eq(diagramNode));
    verify(graphCommandManager, times(1)).execute(any(GraphCommandExecutionContext.class), commandCaptor.capture());
    final Command command = commandCaptor.getValue();
    assertTrue(command instanceof CompositeCommand);
    final CompositeCommand compositeCommand = (CompositeCommand) command;
    assertEquals(1, compositeCommand.size());
}
Also used : Command(org.kie.workbench.common.stunner.core.command.Command) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) Node(org.kie.workbench.common.stunner.core.graph.Node) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) Test(org.junit.Test)

Example 74 with Command

use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.

the class CaseGraphFactoryImplTest method buildInitialisationCommands.

@Test
@SuppressWarnings("all")
public void buildInitialisationCommands() {
    final List<Command> commands = tested.buildInitialisationCommands();
    assertEquals(1, commands.size());
    final AddNodeCommand addNodeCommand = (AddNodeCommand) commands.get(0);
    assertEquals(addNodeCommand.getCandidate(), diagramNode);
}
Also used : AddNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand) Command(org.kie.workbench.common.stunner.core.command.Command) AddNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand) 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