Search in sources :

Example 11 with Point2D

use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.

the class CanvasDefinitionTooltipTest method testShow.

@Test
public void testShow() {
    final Point2D point = new Point2D(55, 6);
    tested.show(new CanvasDefinitionTooltip.DefinitionIdContent("def1"), point);
    verify(textTooltip, times(1)).show(eq("def1theTestTitle"), eq(point));
    verify(textTooltip, never()).hide();
    verify(textTooltip, never()).destroy();
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Test(org.junit.Test)

Example 12 with Point2D

use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.

the class PasteSelectionSessionCommandTest method executeWithMultiSelection.

@Test
@SuppressWarnings("unchecked")
public void executeWithMultiSelection() {
    pasteSelectionSessionCommand.bind(session);
    // Mock the callback of CloneNodeCommand
    ArgumentCaptor<Consumer> consumerNode = ArgumentCaptor.forClass(Consumer.class);
    ArgumentCaptor<Consumer> consumerNode2 = ArgumentCaptor.forClass(Consumer.class);
    when(cloneNodeCommand.getCandidate()).thenReturn(node);
    when(cloneNodeCommand2.getCandidate()).thenReturn(node2);
    when(canvasCommandFactory.cloneNode(eq(node), any(), any(), consumerNode.capture())).thenReturn(cloneNodeCommand);
    when(canvasCommandFactory.cloneNode(eq(node2), any(), any(), consumerNode2.capture())).thenReturn(cloneNodeCommand2);
    Map<Node, ArgumentCaptor<Consumer>> consumerMap = new HashMap() {

        {
            put(node, consumerNode);
            put(node2, consumerNode2);
        }
    };
    // Mock the callback of CloneConnectorCommand
    ArgumentCaptor<Consumer> consumerEdge = ArgumentCaptor.forClass(Consumer.class);
    when(canvasCommandFactory.cloneConnector(any(), anyString(), anyString(), anyString(), consumerEdge.capture())).thenReturn(cloneConnectorCommand);
    // apply callbacks mocks
    when(sessionCommandManager.execute(eq(canvasHandler), any())).thenAnswer(param -> {
        CompositeCommand argument = param.getArgumentAt(1, CompositeCommand.class);
        // callback to nodes
        argument.getCommands().stream().filter(c -> c instanceof CloneNodeCommand).forEach(c -> {
            CloneNodeCommand cloneNodeCommand = (CloneNodeCommand) c;
            Node candidate = cloneNodeCommand.getCandidate();
            consumerMap.get(candidate).getValue().accept(cloneMap.get(candidate));
        });
        // callback to connectors
        argument.getCommands().stream().filter(c -> c instanceof CloneConnectorCommand).forEach(c -> consumerEdge.getValue().accept(cloneEdge));
        return commandResult;
    });
    // Executing the command
    clipboardControl.set(graphInstance.startNode, graphInstance.edge1, graphInstance.intermNode);
    when(selectionControl.getSelectedItems()).thenReturn(Arrays.asList(graphInstance.startNode.getUUID(), graphInstance.edge1.getUUID(), graphInstance.intermNode.getUUID()));
    pasteSelectionSessionCommand.execute(callback);
    verify(canvasCommandFactory, times(1)).cloneNode(eq(graphInstance.startNode), eq(graphInstance.parentNode.getUUID()), eq(new Point2D(X, DEFAULT_PADDING + Y + NODE_SIZE)), any());
    verify(canvasCommandFactory, times(1)).cloneConnector(eq(graphInstance.edge1), anyString(), anyString(), anyString(), any());
    // check command registry update after execution to allow a single undo/redo
    verify(commandRegistry, times(2)).pop();
    ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
    verify(commandRegistry, times(1)).register(commandArgumentCaptor.capture());
    assertTrue(commandArgumentCaptor.getValue() instanceof CompositeCommand);
    assertEquals(((CompositeCommand) commandArgumentCaptor.getValue()).size(), 2);
}
Also used : Arrays(java.util.Arrays) Edge(org.kie.workbench.common.stunner.core.graph.Edge) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) UUID(org.kie.workbench.common.stunner.core.util.UUID) DEFAULT_PADDING(org.kie.workbench.common.stunner.core.client.session.command.impl.PasteSelectionSessionCommand.DEFAULT_PADDING) CloneNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.CloneNodeCommand) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) CommandRegistry(org.kie.workbench.common.stunner.core.registry.command.CommandRegistry) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) CanvasCommandFactory(org.kie.workbench.common.stunner.core.client.command.CanvasCommandFactory) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) ClientSession(org.kie.workbench.common.stunner.core.client.session.ClientSession) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Objects(java.util.Objects) Matchers.any(org.mockito.Matchers.any) Node(org.kie.workbench.common.stunner.core.graph.Node) Mockito.mock(org.mockito.Mockito.mock) LocalClipboardControl(org.kie.workbench.common.stunner.core.client.canvas.controls.clipboard.LocalClipboardControl) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Matchers.anyString(org.mockito.Matchers.anyString) ArgumentCaptor(org.mockito.ArgumentCaptor) ClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand) Element(org.kie.workbench.common.stunner.core.graph.Element) ClipboardControl(org.kie.workbench.common.stunner.core.client.canvas.controls.clipboard.ClipboardControl) KeyboardEvent(org.kie.workbench.common.stunner.core.client.event.keyboard.KeyboardEvent) Command(org.kie.workbench.common.stunner.core.command.Command) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) Before(org.junit.Before) Event(javax.enterprise.event.Event) CloneConnectorCommand(org.kie.workbench.common.stunner.core.client.canvas.command.CloneConnectorCommand) TestingGraphInstanceBuilder(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) SessionCommandManager(org.kie.workbench.common.stunner.core.client.command.SessionCommandManager) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) Collections(java.util.Collections) Mockito.reset(org.mockito.Mockito.reset) Assert.assertEquals(org.junit.Assert.assertEquals) TestingGraphMockHandler(org.kie.workbench.common.stunner.core.TestingGraphMockHandler) ArgumentCaptor(org.mockito.ArgumentCaptor) HashMap(java.util.HashMap) Node(org.kie.workbench.common.stunner.core.graph.Node) CloneNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.CloneNodeCommand) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) CloneConnectorCommand(org.kie.workbench.common.stunner.core.client.canvas.command.CloneConnectorCommand) Consumer(java.util.function.Consumer) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) CloneNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.CloneNodeCommand) ClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand) Command(org.kie.workbench.common.stunner.core.command.Command) CloneConnectorCommand(org.kie.workbench.common.stunner.core.client.canvas.command.CloneConnectorCommand) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) Test(org.junit.Test)

Example 13 with Point2D

use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.

the class AbstractControlPointCommandTest method setUp.

public void setUp() {
    super.init(0, 0);
    newLocation = new Point2D(0, 0);
    controlPoint1 = new ControlPointImpl(new Point2D(1, 1), 1);
    controlPoint2 = new ControlPointImpl(new Point2D(2, 2), 2);
    controlPoint3 = new ControlPointImpl(new Point2D(3, 3), 3);
    controlPointList = new ArrayList<ControlPoint>() {

        {
            add(controlPoint1);
            add(controlPoint2);
            add(controlPoint3);
        }
    };
    when(edge.getContent()).thenReturn(viewConnector);
    when(viewConnector.getControlPoints()).thenReturn(controlPointList);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) ControlPointImpl(org.kie.workbench.common.stunner.core.graph.content.view.ControlPointImpl) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)

Example 14 with Point2D

use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.

the class CloneNodeCommandTest method setUp.

@Before
public void setUp() {
    super.setUp();
    candidate = graphInstance.containerNode;
    parent = graphInstance.parentNode;
    candidate.setContent(candidateContent);
    this.position = new Point2D(1, 1);
    this.cloneNodeCommand = new CloneNodeCommand(candidate, parent.getUUID(), position, null, childrenTraverseProcessorManagedInstance);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Before(org.junit.Before)

Example 15 with Point2D

use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.

the class GraphBoundsIndexerImplTest method testGetTrimmedBounds.

@Test
public void testGetTrimmedBounds() {
    Point2D position = GraphUtils.getPosition((View) graphInstanceParent.startNode.getContent());
    double[] size = GraphUtils.getNodeSize((View) graphInstanceParent.startNode.getContent());
    double[] trimmedBounds = graphBoundsIndexerImpl.getTrimmedBounds();
    assertEquals(trimmedBounds[0], position.getX(), 0.001);
    assertEquals(trimmedBounds[1], position.getY(), 0.001);
    assertEquals(trimmedBounds[2], size[0], 0.001);
    assertEquals(trimmedBounds[3], size[1], 0.001);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Test(org.junit.Test)

Aggregations

Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)55 Test (org.junit.Test)25 Edge (org.kie.workbench.common.stunner.core.graph.Edge)18 View (org.kie.workbench.common.stunner.core.graph.content.view.View)17 Node (org.kie.workbench.common.stunner.core.graph.Node)15 Command (org.kie.workbench.common.stunner.core.command.Command)10 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)10 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)10 Before (org.junit.Before)9 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)7 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)6 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)6 TestingGraphMockHandler (org.kie.workbench.common.stunner.core.TestingGraphMockHandler)5 UpdateElementPositionCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand)5 Ignore (org.junit.Ignore)4 Element (org.kie.workbench.common.stunner.core.graph.Element)4 AbstractCanvas (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas)3 CanvasCommand (org.kie.workbench.common.stunner.core.client.command.CanvasCommand)3 ShapeView (org.kie.workbench.common.stunner.core.client.shape.view.ShapeView)3 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)3