Search in sources :

Example 71 with Node

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

the class BPMNDirectDiagramMarshallerTest method testMagnetsInLane.

private void testMagnetsInLane(Diagram<Graph, Metadata> diagram) throws Exception {
    Node userTaskNode = (Node) findElementByContentType(diagram, UserTask.class);
    Node scriptTaskNode = (Node) findElementByContentType(diagram, ScriptTask.class);
    assertNotNull(userTaskNode);
    assertNotNull(scriptTaskNode);
    ViewConnector userTaskInEdgeConnector = getInEdgeViewConnector(userTaskNode);
    ViewConnector scriptTaskInEdgeConnector = getInEdgeViewConnector(scriptTaskNode);
    assertNotNull(userTaskInEdgeConnector);
    assertNotNull(scriptTaskInEdgeConnector);
    ViewConnector userTaskOutEdgeConnector = getOutEdgeViewConnector(userTaskNode);
    ViewConnector scriptTaskOutEdgeConnector = getOutEdgeViewConnector(scriptTaskNode);
    assertNotNull(userTaskOutEdgeConnector);
    assertNotNull(scriptTaskOutEdgeConnector);
    // userTaskInEdgeConnector is from magnet right-middle to middle-top
    assertTrue(userTaskInEdgeConnector.getSourceConnection().isPresent());
    assertTrue(userTaskInEdgeConnector.getTargetConnection().isPresent());
    Connection sourceConnection = (Connection) userTaskInEdgeConnector.getSourceConnection().get();
    Connection targetConnection = (Connection) userTaskInEdgeConnector.getTargetConnection().get();
    assertEquals(136d, sourceConnection.getLocation().getX(), 0.1d);
    assertEquals(24d, sourceConnection.getLocation().getY(), 0.1d);
    assertEquals(68d, targetConnection.getLocation().getX(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getY(), 0.1d);
    // scriptTaskInEdgeConnector is from magnet right-bottom to left-top
    assertTrue(scriptTaskInEdgeConnector.getSourceConnection().isPresent());
    assertTrue(scriptTaskInEdgeConnector.getTargetConnection().isPresent());
    sourceConnection = (Connection) scriptTaskInEdgeConnector.getSourceConnection().get();
    targetConnection = (Connection) scriptTaskInEdgeConnector.getTargetConnection().get();
    assertEquals(136d, sourceConnection.getLocation().getX(), 0.1d);
    assertEquals(48d, sourceConnection.getLocation().getY(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getY(), 0.1d);
    // userTaskOutEdgeConnector is from magnet right-bottom to left-top
    assertTrue(userTaskOutEdgeConnector.getSourceConnection().isPresent());
    assertTrue(userTaskOutEdgeConnector.getTargetConnection().isPresent());
    sourceConnection = (Connection) userTaskOutEdgeConnector.getSourceConnection().get();
    targetConnection = (Connection) userTaskOutEdgeConnector.getTargetConnection().get();
    assertEquals(136d, sourceConnection.getLocation().getX(), 0.1d);
    assertEquals(48d, sourceConnection.getLocation().getY(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getY(), 0.1d);
    // scriptTaskOutEdgeConnector is from magnet right-top to left-middle
    assertTrue(scriptTaskOutEdgeConnector.getSourceConnection().isPresent());
    assertTrue(scriptTaskOutEdgeConnector.getTargetConnection().isPresent());
    sourceConnection = (Connection) scriptTaskOutEdgeConnector.getSourceConnection().get();
    targetConnection = (Connection) scriptTaskOutEdgeConnector.getTargetConnection().get();
    assertEquals(136d, sourceConnection.getLocation().getX(), 0.1d);
    assertEquals(0d, sourceConnection.getLocation().getY(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
    assertEquals(14d, targetConnection.getLocation().getY(), 0.1d);
}
Also used : ScriptTask(org.kie.workbench.common.stunner.bpmn.definition.ScriptTask) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node) UserTask(org.kie.workbench.common.stunner.bpmn.definition.UserTask) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) DiscreteConnection(org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection)

Example 72 with Node

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

the class MigrationDiagramMarshallerTest method assertNodeEquals.

private void assertNodeEquals(Diagram<Graph, Metadata> oldDiagram, Diagram<Graph, Metadata> newDiagram, String fileName) {
    Map<String, Node<View, ?>> oldNodes = asNodeMap(oldDiagram.getGraph().nodes());
    Map<String, Node<View, ?>> newNodes = asNodeMap(newDiagram.getGraph().nodes());
    assertEquals(fileName + ": Number of nodes should match", oldNodes.size(), newNodes.size());
    for (Node<View, ?> o : oldNodes.values()) {
        Node<View, ?> n = newNodes.get(o.getUUID());
        View oldContent = o.getContent();
        View newContent = n.getContent();
        Bounds oldBounds = oldContent.getBounds();
        Bounds newBounds = newContent.getBounds();
        assertEquals(fileName + ": Bounds should match for " + o.getUUID(), oldBounds, newBounds);
        Object oldDefinition = oldContent.getDefinition();
        Object newDefinition = newContent.getDefinition();
        assertEquals(fileName + ": Definitions should match for " + o.getUUID(), oldDefinition, newDefinition);
    }
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Matchers.anyString(org.mockito.Matchers.anyString) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 73 with Node

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

the class MigrationDiagramMarshallerTest method asNodeMap.

private Map<String, Node<View, ?>> asNodeMap(Iterable nodes) {
    Map<String, Node<View, ?>> oldNodes = new HashMap<>();
    nodes.forEach(n -> {
        Node n1 = (Node) n;
        oldNodes.put(n1.getUUID(), n1);
    });
    return oldNodes;
}
Also used : HashMap(java.util.HashMap) Node(org.kie.workbench.common.stunner.core.graph.Node) Matchers.anyString(org.mockito.Matchers.anyString)

Example 74 with Node

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

the class Unmarshalling method unmarshall.

public static Diagram<Graph, Metadata> unmarshall(DiagramMarshaller tested, InputStream is) throws Exception {
    Metadata metadata = new MetadataImpl.MetadataImplBuilder(BindableAdapterUtils.getDefinitionSetId(BPMNDefinitionSet.class)).build();
    DiagramImpl diagram = new DiagramImpl(UUID.uuid(), metadata);
    Graph<DefinitionSet, Node> graph = tested.unmarshall(metadata, is);
    diagram.setGraph(graph);
    return diagram;
}
Also used : MetadataImpl(org.kie.workbench.common.stunner.core.diagram.MetadataImpl) DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) BPMNDefinitionSet(org.kie.workbench.common.stunner.bpmn.BPMNDefinitionSet) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)

Example 75 with Node

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

the class BPMNDiagramMarshallerBase method assertNodeEquals.

private void assertNodeEquals(Diagram<Graph, Metadata> oldDiagram, Diagram<Graph, Metadata> newDiagram, String fileName) {
    Map<String, Node<View, ?>> oldNodes = asNodeMap(oldDiagram.getGraph().nodes());
    Map<String, Node<View, ?>> newNodes = asNodeMap(newDiagram.getGraph().nodes());
    assertEquals(fileName + ": Number of nodes should match", oldNodes.size(), newNodes.size());
    for (Node<View, ?> o : oldNodes.values()) {
        Node<View, ?> n = newNodes.get(o.getUUID());
        View oldContent = o.getContent();
        View newContent = n.getContent();
        Bounds oldBounds = oldContent.getBounds();
        Bounds newBounds = newContent.getBounds();
        assertEquals(fileName + ": Bounds should match for " + o.getUUID(), oldBounds, newBounds);
        Object oldDefinition = oldContent.getDefinition();
        Object newDefinition = newContent.getDefinition();
        assertEquals(fileName + ": Definitions should match for " + o.getUUID(), oldDefinition, newDefinition);
    }
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Matchers.anyString(org.mockito.Matchers.anyString) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

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