aboutsummaryrefslogtreecommitdiffstats
path: root/sdc-workflow-designer-server/src/test/java/org/onap
diff options
context:
space:
mode:
authorYuanHu <yuan.hu1@zte.com.cn>2018-03-21 14:41:40 +0800
committerYuanHu <yuan.hu1@zte.com.cn>2018-03-21 15:10:14 +0800
commitcf0f4ccdb2b7152cf5251038fc6fa94ad0d637ae (patch)
tree907c3f1cc18e444cdcddc1039eb02d32d1ada182 /sdc-workflow-designer-server/src/test/java/org/onap
parentde5748dc931aea9ee258ad0704731723a17e1421 (diff)
Add Unit test.
Add Unit test for WorkflowModelerResource. Issue-ID: SDC-1078 Change-Id: I5701f268a1bb187e765822dd8483c3766602becd Signed-off-by: YuanHu <yuan.hu1@zte.com.cn>
Diffstat (limited to 'sdc-workflow-designer-server/src/test/java/org/onap')
-rw-r--r--sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResourceTest.java2
-rw-r--r--sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/resources/WorkflowModelerResourceTest.java110
-rw-r--r--sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtilsTest.java2
3 files changed, 112 insertions, 2 deletions
diff --git a/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResourceTest.java b/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResourceTest.java
index 060008b3..899e2ee9 100644
--- a/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResourceTest.java
+++ b/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResourceTest.java
@@ -24,7 +24,7 @@ import org.onap.sdc.workflowdesigner.utils.JsonUtils;
*
*/
public class ExtendActivityResourceTest {
- private static final String EXT_ACTIVITIES_FILE_NAME = "..\\distribution\\src\\main\\assembly\\ext-activities.json";
+ private static final String EXT_ACTIVITIES_FILE_NAME = "src/main/assembly/ext-activities.json";
/**
* @throws java.lang.Exception
diff --git a/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/resources/WorkflowModelerResourceTest.java b/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/resources/WorkflowModelerResourceTest.java
new file mode 100644
index 00000000..f91a42bb
--- /dev/null
+++ b/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/resources/WorkflowModelerResourceTest.java
@@ -0,0 +1,110 @@
+/**
+ * Copyright (c) 2018 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.resources;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.Paths;
+import java.util.UUID;
+
+import org.dom4j.DocumentException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.sdc.workflowdesigner.resources.entity.WorkflowInfo;
+import org.onap.sdc.workflowdesigner.utils.FileCommonUtils;
+import org.onap.sdc.workflowdesigner.utils.JsonUtils;
+
+/**
+ *
+ */
+public class WorkflowModelerResourceTest {
+ private static final String WORKFLOW_JSON_TEMP_FILE_NAME = "temp_workflow.json";
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {}
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {}
+
+ /**
+ * Test method for {@link org.onap.sdc.workflowdesigner.resources.WorkflowModelerResource#buildBPMN(java.net.URI, java.lang.String)}.
+ */
+ @Test
+ public void testBuildBPMN() {
+ String bpmn = parseBpmnfromJsonFile();
+ assertEquals(false, bpmn.isEmpty());
+ }
+
+ /**
+ * @return
+ */
+ private String parseBpmnfromJsonFile() {
+ try {
+ URI srcUri = Paths.get("src/main/assembly", WORKFLOW_JSON_TEMP_FILE_NAME).toUri();
+ WorkflowModelerResource resource = new WorkflowModelerResource();
+ String processName = "plan_" + UUID.randomUUID().toString();
+ return resource.buildBPMN(srcUri, processName);
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * Test method for {@link org.onap.sdc.workflowdesigner.resources.WorkflowModelerResource#insertJson2Bpmn(java.lang.String, java.lang.String)}.
+ */
+ @Test
+ public void testInsertJson2Bpmn() {
+ String bpmn = parseBpmnfromJsonFile();
+
+ try {
+ String json = FileCommonUtils.readString("src/main/assembly/" + WORKFLOW_JSON_TEMP_FILE_NAME);
+ WorkflowModelerResource resource = new WorkflowModelerResource();
+ String combineBpmn = resource.insertJson2Bpmn(json, bpmn);
+
+ String json1 = resource.readJsonfromBPMNFile(combineBpmn);
+
+ assertEqualsJson(json, json1);
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (DocumentException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * @param json
+ * @param json1
+ */
+ private void assertEqualsJson(String json, String json1) {
+ WorkflowInfo wi = JsonUtils.fromJson(json, WorkflowInfo.class);
+ WorkflowInfo wi1 = JsonUtils.fromJson(json1, WorkflowInfo.class);
+
+ String newJson = JsonUtils.toJson(wi);
+ String newJson1 = JsonUtils.toJson(wi1);
+
+ assertEquals(newJson1, newJson);
+
+ }
+
+}
diff --git a/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtilsTest.java b/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtilsTest.java
index a9770de0..39065056 100644
--- a/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtilsTest.java
+++ b/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtilsTest.java
@@ -56,7 +56,7 @@ public class FileCommonUtilsTest {
*/
@Test
public void testReadStringString() {
- String fileName = "src\\test\\resources\\workflow\\template-test.bpmn20.xml";
+ String fileName = "src/test/resources/workflow/template-test.bpmn20.xml";
File file = new File(fileName);
if (file.exists()) {
try {