aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/parser/Bpmn4ToscaJsonParserTest.java137
-rw-r--r--sdc-workflow-designer-server/src/test/resources/workflow/workflow.json5
2 files changed, 139 insertions, 3 deletions
diff --git a/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/parser/Bpmn4ToscaJsonParserTest.java b/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/parser/Bpmn4ToscaJsonParserTest.java
new file mode 100644
index 00000000..1f56efbf
--- /dev/null
+++ b/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/parser/Bpmn4ToscaJsonParserTest.java
@@ -0,0 +1,137 @@
+/**
+ * Copyright (c) 2017 ZTE Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the Apache License, Version 2.0
+ * and the Eclipse Public License v1.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * ZTE - initial API and implementation and/or initial documentation
+ */
+package org.onap.sdc.workflowdesigner.parser;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Test;
+import org.onap.sdc.workflowdesigner.model.Element;
+import org.onap.sdc.workflowdesigner.model.EndEvent;
+import org.onap.sdc.workflowdesigner.model.Process;
+import org.onap.sdc.workflowdesigner.model.SequenceFlow;
+import org.onap.sdc.workflowdesigner.model.StartEvent;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+
+public class Bpmn4ToscaJsonParserTest {
+
+ private static String RESOURCES_DIR = "src/test/resources/workflow";
+ protected static String PROCESS_NAME = "test1";
+
+ @Test
+ public void parseTest() throws JsonParseException, JsonMappingException, MalformedURLException, IOException {
+ Bpmn4ToscaJsonParser parser = new Bpmn4ToscaJsonParser();
+ URI srcUri = Paths.get(RESOURCES_DIR, "workflow.json").toUri();
+ Process actualProcess = parser.parse(PROCESS_NAME, srcUri);
+ Process expectedProcess = createReferenceProcess();
+
+ assertElements(expectedProcess.getElementList(), actualProcess.getElementList());
+ assertSequenceFlows(expectedProcess.getSequenceFlowList(), actualProcess.getSequenceFlowList());
+ }
+
+ private static void assertElements(List<Element> expectedElementList, List<Element> actualElementList) {
+ assertEquals(expectedElementList.size(), actualElementList.size());
+
+ for (Iterator<Element> iterator = expectedElementList.iterator(); iterator.hasNext();) {
+ Element expectedElement = (Element) iterator.next();
+ Element actualElement = getElementById(expectedElement.getId(), actualElementList);
+ if (actualElement != null) {
+ assertElement(expectedElement, actualElement);
+ } else {
+ fail("Element with id " + expectedElement.getId() + " could not be found");
+ }
+ }
+ }
+
+ private static Element getElementById(String id, List<Element> actualElementList) {
+ Iterator<Element> iter = actualElementList.iterator();
+ while (iter.hasNext()) {
+ Element element = (Element) iter.next();
+ if (element.getId().equals(id)) {
+ return element;
+ }
+ }
+ return null;
+ }
+
+ public static void assertElement(Element expected, Element actual) {
+ assertEquals("element: id ", expected.getId(), actual.getId());
+ assertEquals("element: name ", expected.getName(), actual.getName());
+ }
+
+ public static void assertSequenceFlows(List<SequenceFlow> expectedSequenceList,
+ List<SequenceFlow> actualSequenceFlowList) {
+ assertEquals(expectedSequenceList.size(), actualSequenceFlowList.size());
+
+ for (Iterator<SequenceFlow> iterator = expectedSequenceList.iterator(); iterator.hasNext();) {
+ SequenceFlow expectedElement = (SequenceFlow) iterator.next();
+ SequenceFlow actualElement = getSequenceById(expectedElement.getSourceRef(), expectedElement.getTargetRef(),
+ actualSequenceFlowList);
+ if (actualElement != null) {
+ assertLink(expectedElement, actualElement);
+ } else {
+ fail("Element with id " + expectedElement.getId() + " could not be found");
+ }
+ }
+ }
+
+ private static SequenceFlow getSequenceById(String sourceRef, String targetRef,
+ List<SequenceFlow> actualSequenceFlowList) {
+ Iterator<SequenceFlow> iter = actualSequenceFlowList.iterator();
+ while (iter.hasNext()) {
+ SequenceFlow element = (SequenceFlow) iter.next();
+ if (element.getSourceRef().equals(sourceRef) && element.getTargetRef().equals(targetRef)) {
+ return element;
+ }
+ }
+ return null;
+ }
+
+ public static void assertLink(SequenceFlow expectedLink, SequenceFlow actualLink) {
+ assertEquals("Link source: id", expectedLink.getSourceRef(), actualLink.getSourceRef());
+ assertEquals("Link target :id", expectedLink.getTargetRef(), actualLink.getTargetRef());
+ }
+
+ private static Process createReferenceProcess() {
+ Process process = new Process(PROCESS_NAME);
+
+ StartEvent startEvent = new StartEvent();
+ startEvent.setDocumentation("");
+ startEvent.setId("node0");
+ startEvent.setName("startEvent");
+ process.getElementList().add(startEvent);
+
+ EndEvent endEvent = new EndEvent();
+ endEvent.setDocumentation("");
+ endEvent.setId("node1");
+ endEvent.setName("endEvent");
+ process.getElementList().add(endEvent);
+
+ SequenceFlow flow2 = new SequenceFlow();
+ flow2.setId("node0node1");
+ flow2.setSourceRef("node0");
+ flow2.setTargetRef("node1");
+ process.getSequenceFlowList().add(flow2);
+
+ return process;
+ }
+
+}
diff --git a/sdc-workflow-designer-server/src/test/resources/workflow/workflow.json b/sdc-workflow-designer-server/src/test/resources/workflow/workflow.json
index 4799fc99..2042810f 100644
--- a/sdc-workflow-designer-server/src/test/resources/workflow/workflow.json
+++ b/sdc-workflow-designer-server/src/test/resources/workflow/workflow.json
@@ -1,14 +1,13 @@
{"nodes":[
{
"sequenceFlows":[
- {"condition":"","sourceRef":"node0","targetRef":"node1"},
- {"condition":"","sourceRef":"node0","targetRef":"node3"}
+ {"condition":"","sourceRef":"node0","targetRef":"node1"}
],
"parameters":[],"id":"node0","name":"startEvent","type":"startEvent","parentId":"root",
"position":{"width":30,"height":30,"left":468,"top":55}
},
{
- "sequenceFlows":[{"condition":"","sourceRef":"node1","targetRef":"node2"}],
+ "sequenceFlows":[],
"input":[],"output":[],"template":{},"id":"node1","name":"endEvent",
"type":"endEvent","parentId":"root",
"position":{"width":252.08334350585938,"height":46.66666793823242,"left":432,"top":167}