Search in sources :

Example 36 with Node

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

the class CanvasLayoutUtilsTest method getNextFromRootWithParent.

@Test
@SuppressWarnings("unchecked")
public void getNextFromRootWithParent() {
    this.graphTestHandlerParent = new TestingGraphMockHandler();
    graphInstanceParent = TestingGraphInstanceBuilder.newGraph2(graphTestHandlerParent);
    Node node = mock(Node.class);
    Bounds boundsNode = new BoundsImpl(new BoundImpl(100d, 100d), new BoundImpl(300d, 200d));
    View viewNode = mock(View.class);
    when(node.getContent()).thenReturn(viewNode);
    when(viewNode.getBounds()).thenReturn(boundsNode);
    when(canvasHandler.getDiagram().getGraph()).thenReturn(graphInstanceParent.graph);
    Point2D next = canvasLayoutUtils.getNext(canvasHandler, graphInstanceParent.startNode, node);
    Node<View<?>, Edge> start = (Node<View<?>, Edge>) graphInstanceParent.startNode;
    double[] size = GraphUtils.getNodeSize(start.getContent());
    assertTrue(next.getX() == CanvasLayoutUtils.getPaddingX());
    assertTrue(next.getY() > size[1]);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) TestingGraphMockHandler(org.kie.workbench.common.stunner.core.TestingGraphMockHandler) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 37 with Node

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

the class CanvasLayoutUtilsTest method getNextNewTaskWithNonEmptyPosition.

// TODO (AlessioP & Roger):
@Test
@Ignore
@SuppressWarnings("unchecked")
public void getNextNewTaskWithNonEmptyPosition() {
    when(ruleManager.evaluate(eq(ruleSet), any(RuleEvaluationContext.class))).thenReturn(ruleViolations);
    when(ruleViolations.violations(Violation.Type.ERROR)).thenReturn(ruleViolationIterable);
    when(ruleViolations.violations(Violation.Type.ERROR).iterator()).thenReturn(ruleViolationIterator);
    when(ruleViolations.violations(Violation.Type.ERROR).iterator().hasNext()).thenReturn(true);
    this.graphTestHandler = new TestingGraphMockHandler();
    graphInstance = TestingGraphInstanceBuilder.newGraph1(graphTestHandler);
    Node newNode = mock(Node.class);
    Bounds boundsNewNode = new BoundsImpl(new BoundImpl(200d, 300d), new BoundImpl(300d, 400d));
    View viewNewNode = mock(View.class);
    when(newNode.getContent()).thenReturn(viewNewNode);
    when(viewNewNode.getBounds()).thenReturn(boundsNewNode);
    when(canvasHandler.getDiagram().getGraph()).thenReturn(graphInstance.graph);
    when(graphBoundsIndexer.getAt(140.0, 0.0, 100.0, 100.0, null)).thenReturn(graphInstance.intermNode);
    graphInstance.startNode.getOutEdges().clear();
    Point2D next = canvasLayoutUtils.getNext(canvasHandler, graphInstance.startNode, newNode);
    Node<View<?>, Edge> startNode = (Node<View<?>, Edge>) graphInstance.startNode;
    double[] sizeStartNode = GraphUtils.getNodeSize(startNode.getContent());
    Node<View<?>, Edge> intermNode = (Node<View<?>, Edge>) graphInstance.intermNode;
    double[] sizeIntermNode = GraphUtils.getNodeSize(intermNode.getContent());
    assertTrue(next.getX() == sizeStartNode[0] + CanvasLayoutUtils.getPaddingX());
    assertTrue(next.getY() > sizeIntermNode[1]);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) TestingGraphMockHandler(org.kie.workbench.common.stunner.core.TestingGraphMockHandler) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 38 with Node

use of org.kie.workbench.common.stunner.core.graph.Node 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 39 with Node

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

the class AbstractCloneCommandTest method setUp.

public void setUp() {
    super.init(0, 0);
    // creating the mock graph for test
    TestingGraphMockHandler handler = new TestingGraphMockHandler();
    graphInstance = TestingGraphInstanceBuilder.newGraph3(handler);
    graph = graphInstance.graph;
    graphIndex = handler.graphIndex;
    // mocking the clone nodes on the graphIndex
    ArgumentCaptor<Node> nodeArgumentCaptor = ArgumentCaptor.forClass(Node.class);
    when(handler.graphIndex.addNode(nodeArgumentCaptor.capture())).thenAnswer(t -> {
        // Node node = (Node)t.getArguments()[0];
        when(graphIndex.getNode(eq(nodeArgumentCaptor.getValue().getUUID()))).thenReturn(nodeArgumentCaptor.getValue());
        return graphIndex;
    });
    // edge mock
    connectorContent = new ViewConnectorImpl(connectorDefinition, new BoundsImpl(new BoundImpl(1d, 1d), new BoundImpl(1d, 1d)));
    sourceConnection = MagnetConnection.Builder.forElement(graphInstance.startNode);
    connectorContent.setSourceConnection(sourceConnection);
    targetConnection = MagnetConnection.Builder.forElement(graphInstance.intermNode);
    connectorContent.setTargetConnection(targetConnection);
    graphInstance.edge1.setContent(connectorContent);
    graphInstance.edge2.setContent(connectorContent);
    when(definitionManager.cloneManager()).thenReturn(cloneManager);
    when(cloneManager.clone(definition, ClonePolicy.ALL)).thenReturn(definition);
    when(cloneManager.clone(connectorDefinition, ClonePolicy.ALL)).thenReturn(connectorDefinition);
    when(graphCommandExecutionContext.getGraphIndex()).thenReturn(graphIndex);
    when(candidateContent.getDefinition()).thenReturn(definition);
    when(factoryManager.newElement(anyString(), any(Class.class))).thenReturn(cloneElement);
    when(cloneElement.asNode()).thenReturn(clone);
    when(cloneElement.asEdge()).thenReturn(cloneEdge);
    when(cloneEdge.getContent()).thenReturn(connectorContent);
    when(cloneEdge.getUUID()).thenReturn(CLONE_EDGE_UUID);
    when(clone.getContent()).thenReturn(cloneContent);
    when(clone.getUUID()).thenReturn(CLONE_UUID);
    when(cloneElement.getUUID()).thenReturn(CLONE_UUID);
    when(cloneContent.getBounds()).thenReturn(bounds);
    when(bounds.getUpperLeft()).thenReturn(bound);
    when(bounds.getLowerRight()).thenReturn(bound);
    when(childrenTraverseProcessorManagedInstance.get()).thenReturn(new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()));
}
Also used : ViewConnectorImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnectorImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) ChildrenTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl) TestingGraphMockHandler(org.kie.workbench.common.stunner.core.TestingGraphMockHandler) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl)

Example 40 with Node

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

the class AbstractGraphCommandTest method mockNode.

public static Node mockNode(String uuid) {
    Node node = mock(Node.class);
    when(node.getUUID()).thenReturn(uuid);
    when(node.asNode()).thenReturn(node);
    when(node.getInEdges()).thenReturn(new LinkedList());
    when(node.getOutEdges()).thenReturn(new LinkedList());
    return node;
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) LinkedList(java.util.LinkedList)

Aggregations

Node (org.kie.workbench.common.stunner.core.graph.Node)153 Edge (org.kie.workbench.common.stunner.core.graph.Edge)85 View (org.kie.workbench.common.stunner.core.graph.content.view.View)59 Test (org.junit.Test)38 Graph (org.kie.workbench.common.stunner.core.graph.Graph)32 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)24 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)21 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)17 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)15 Element (org.kie.workbench.common.stunner.core.graph.Element)14 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)13 DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)13 EdgeImpl (org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl)13 Matchers.anyString (org.mockito.Matchers.anyString)13 List (java.util.List)12 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)12 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)12 Before (org.junit.Before)11 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)11 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)11