Search in sources :

Example 86 with Graph

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

the class BPMNDiagramMarshallerTest method testMarshallEndMessageEvent.

@Test
public void testMarshallEndMessageEvent() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_ENDMESSAGEEVENT);
    String result = tested.marshall(diagram);
    assertDiagram(result, 1, 1, 0);
    assertTrue(result.contains("<bpmn2:endEvent id=\"_4A8A0A9E-D4A5-4B6E-94A6-20817A57B3C6\""));
    assertTrue(result.contains(" name=\"EndMessageEvent\""));
    assertTrue(result.contains("<bpmn2:message "));
    assertTrue(result.contains(" name=\"msgref\""));
    assertTrue(result.contains("<bpmn2:messageEventDefinition"));
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 87 with Graph

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

the class BPMNDirectDiagramMarshallerTest method testMarshallMagnetDockers.

@Test
public void testMarshallMagnetDockers() throws Exception {
    Diagram<Graph, Metadata> diagram1 = unmarshall(BPMN_MAGNETDOCKERS);
    String result = tested.marshall(diagram1);
    assertDiagram(result, 1, 8, 7);
    Diagram<Graph, Metadata> diagram2 = unmarshall(new ByteArrayInputStream(result.getBytes()));
    testMagnetDockers(diagram2);
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) ByteArrayInputStream(java.io.ByteArrayInputStream) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Test(org.junit.Test)

Example 88 with Graph

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

the class BPMNDirectDiagramMarshallerTest method testMarshallMagnetsInlane.

@Test
public void testMarshallMagnetsInlane() throws Exception {
    Diagram<Graph, Metadata> diagram1 = unmarshall(BPMN_MAGNETSINLANE);
    String result = tested.marshall(diagram1);
    assertDiagram(result, 1, 6, 4);
    // Check the waypoints are as in the original process
    assertTrue(result.contains("<di:waypoint xsi:type=\"dc:Point\" x=\"371.0\" y=\"86.0\"/>"));
    assertTrue(result.contains("<di:waypoint xsi:type=\"dc:Point\" x=\"406.0\" y=\"324.0\"/>"));
    assertTrue(result.contains("<di:waypoint xsi:type=\"dc:Point\" x=\"692.0\" y=\"276.0\"/>"));
    assertTrue(result.contains("<di:waypoint xsi:type=\"dc:Point\" x=\"805.0\" y=\"76.0\"/>"));
    assertTrue(result.contains("<di:waypoint xsi:type=\"dc:Point\" x=\"81.0\" y=\"86.0\"/>"));
    assertTrue(result.contains("<di:waypoint xsi:type=\"dc:Point\" x=\"235.0\" y=\"86.0\"/>"));
    assertTrue(result.contains("<di:waypoint xsi:type=\"dc:Point\" x=\"474.0\" y=\"372.0\"/>"));
    assertTrue(result.contains("<di:waypoint xsi:type=\"dc:Point\" x=\"556.0\" y=\"276.0\"/>"));
    // Test unmarshall
    Diagram<Graph, Metadata> diagram2 = unmarshall(new ByteArrayInputStream(result.getBytes()));
    testMagnetsInLane(diagram2);
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) ByteArrayInputStream(java.io.ByteArrayInputStream) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Test(org.junit.Test)

Example 89 with Graph

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

the class BPMNDirectDiagramMarshallerTest method testUnmarshallSequenceFlow.

@Test
public void testUnmarshallSequenceFlow() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_SEQUENCEFLOW);
    SequenceFlow sequenceFlow1 = null;
    SequenceFlow sequenceFlow2 = null;
    Iterator<Element> it = nodesIterator(diagram);
    while (it.hasNext()) {
        Element element = it.next();
        if (element.getContent() instanceof View) {
            Object oDefinition = ((View) element.getContent()).getDefinition();
            if (oDefinition instanceof ExclusiveGateway) {
                List<Edge> outEdges = ((NodeImpl) element).getOutEdges();
                for (Edge edge : outEdges) {
                    SequenceFlow flow = (SequenceFlow) ((ViewConnectorImpl) edge.getContent()).getDefinition();
                    if ("route1".equals(flow.getGeneral().getName().getValue())) {
                        sequenceFlow1 = flow;
                    }
                    if ("route2".equals(flow.getGeneral().getName().getValue())) {
                        sequenceFlow2 = flow;
                    }
                }
            }
        }
    }
    assertNotNull(sequenceFlow1);
    assertNotNull(sequenceFlow1.getExecutionSet());
    assertNotNull(sequenceFlow1.getExecutionSet().getConditionExpression());
    assertNotNull(sequenceFlow1.getExecutionSet().getPriority());
    assertNotNull(sequenceFlow1.getGeneral());
    assertNotNull(sequenceFlow1.getGeneral().getName());
    assertEquals("route1", sequenceFlow1.getGeneral().getName().getValue());
    assertEquals("age >= 10;", sequenceFlow1.getExecutionSet().getConditionExpression().getValue().getScript());
    assertEquals("javascript", sequenceFlow1.getExecutionSet().getConditionExpression().getValue().getLanguage());
    assertEquals("2", sequenceFlow1.getExecutionSet().getPriority().getValue());
    assertNotNull(sequenceFlow2);
    assertNotNull(sequenceFlow2.getExecutionSet());
    assertNotNull(sequenceFlow2.getExecutionSet().getConditionExpression());
    assertNotNull(sequenceFlow2.getExecutionSet().getPriority());
    assertNotNull(sequenceFlow2.getGeneral());
    assertNotNull(sequenceFlow2.getGeneral().getName());
    assertEquals("route2", sequenceFlow2.getGeneral().getName().getValue());
    assertEquals("age\n" + "<\n" + "10;", sequenceFlow2.getExecutionSet().getConditionExpression().getValue().getScript());
    assertEquals("java", sequenceFlow2.getExecutionSet().getConditionExpression().getValue().getLanguage());
    assertEquals("1", sequenceFlow2.getExecutionSet().getPriority().getValue());
}
Also used : ExclusiveGateway(org.kie.workbench.common.stunner.bpmn.definition.ExclusiveGateway) Graph(org.kie.workbench.common.stunner.core.graph.Graph) NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) SequenceFlow(org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) FlowElement(org.eclipse.bpmn2.FlowElement) RootElement(org.eclipse.bpmn2.RootElement) Element(org.kie.workbench.common.stunner.core.graph.Element) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) 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 90 with Graph

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

the class BPMNDirectDiagramMarshallerTest method getNodes.

private List<Node> getNodes(Diagram<Graph, Metadata> diagram) {
    Graph graph = diagram.getGraph();
    assertNotNull(graph);
    Iterator<Node> nodesIterable = graph.nodes().iterator();
    List<Node> nodes = new ArrayList<>();
    nodesIterable.forEachRemaining(nodes::add);
    return nodes;
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList)

Aggregations

Graph (org.kie.workbench.common.stunner.core.graph.Graph)190 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)162 Test (org.junit.Test)152 Matchers.anyString (org.mockito.Matchers.anyString)54 View (org.kie.workbench.common.stunner.core.graph.content.view.View)45 Element (org.kie.workbench.common.stunner.core.graph.Element)31 AssignmentsInfo (org.kie.workbench.common.stunner.bpmn.definition.property.dataio.AssignmentsInfo)30 Node (org.kie.workbench.common.stunner.core.graph.Node)30 Edge (org.kie.workbench.common.stunner.core.graph.Edge)29 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)28 RootElement (org.eclipse.bpmn2.RootElement)28 DataIOSet (org.kie.workbench.common.stunner.bpmn.definition.property.dataio.DataIOSet)28 FlowElement (org.eclipse.bpmn2.FlowElement)26 UserTask (org.kie.workbench.common.stunner.bpmn.definition.UserTask)17 ArrayList (java.util.ArrayList)14 List (java.util.List)13 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)13 MessageRef (org.kie.workbench.common.stunner.bpmn.definition.property.event.message.MessageRef)10 Optional (java.util.Optional)9 Definitions (org.eclipse.bpmn2.Definitions)9