47a46a8cf4085f49a8cae88146523f5d4d49cdc3
[sdc/sdc-workflow-designer.git] /
1 /**
2  * Copyright (c) 2018 ZTE Corporation.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the Apache License, Version 2.0
5  * and the Eclipse Public License v1.0 which both accompany this distribution,
6  * and are available at http://www.eclipse.org/legal/epl-v10.html
7  * and http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Contributors:
10  *     ZTE - initial API and implementation and/or initial documentation
11  */
12 package org.onap.sdc.workflowdesigner.resources;
13
14 import static org.junit.Assert.assertEquals;
15
16 import java.io.IOException;
17 import java.net.URI;
18 import java.nio.file.Paths;
19 import java.util.UUID;
20
21 import org.dom4j.DocumentException;
22 import org.junit.After;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.onap.sdc.workflowdesigner.resources.entity.WorkflowInfo;
26 import org.onap.sdc.workflowdesigner.utils.FileCommonUtils;
27 import org.onap.sdc.workflowdesigner.utils.JsonUtils;
28
29 /**
30  *
31  */
32 public class WorkflowModelerResourceTest {
33   private static final String WORKFLOW_JSON_TEMP_FILE_NAME = "temp_workflow.json";
34
35   /**
36    * @throws java.lang.Exception
37    */
38   @Before
39   public void setUp() throws Exception {}
40
41   /**
42    * @throws java.lang.Exception
43    */
44   @After
45   public void tearDown() throws Exception {}
46
47   /**
48    * Test method for
49    * {@link org.onap.sdc.workflowdesigner.resources.WorkflowModelerResource#buildBPMN(java.net.URI, java.lang.String)}.
50    */
51   @Test
52   public void testBuildBPMN() {
53     String bpmn = parseBpmnfromJsonFile();
54     assertEquals(false, bpmn.isEmpty());
55   }
56
57   /**
58    * @return
59    */
60   private String parseBpmnfromJsonFile() {
61     try {
62       URI srcUri = Paths.get("src/main/assembly", WORKFLOW_JSON_TEMP_FILE_NAME).toUri();
63       WorkflowModelerResource resource = new WorkflowModelerResource();
64       String processName = "plan_" + UUID.randomUUID().toString();
65       return resource.buildBPMN(srcUri, processName);
66     } catch (IOException e) {
67     } catch (Exception e) {
68     }
69
70     return null;
71   }
72
73   /**
74    * Test method for
75    * {@link org.onap.sdc.workflowdesigner.resources.WorkflowModelerResource#insertJson2Bpmn(java.lang.String, java.lang.String)}.
76    */
77   @Test
78   public void testInsertJson2Bpmn() {
79     String bpmn = parseBpmnfromJsonFile();
80
81     try {
82       String json = FileCommonUtils.readString("src/main/assembly/" + WORKFLOW_JSON_TEMP_FILE_NAME);
83       WorkflowModelerResource resource = new WorkflowModelerResource();
84       String combineBpmn = resource.insertJson2Bpmn(json, bpmn);
85
86       String json1 = resource.readJsonfromBPMN(combineBpmn);
87
88       assertEqualsJson(json, json1);
89     } catch (IOException e) {
90     } catch (DocumentException e) {
91     }
92   }
93
94   /**
95    * @param json
96    * @param json1
97    */
98   private void assertEqualsJson(String json, String json1) {
99     WorkflowInfo wi = JsonUtils.fromJson(json, WorkflowInfo.class);
100     WorkflowInfo wi1 = JsonUtils.fromJson(json1, WorkflowInfo.class);
101
102     String newJson = JsonUtils.toJson(wi);
103     String newJson1 = JsonUtils.toJson(wi1);
104
105     assertEquals(newJson1, newJson);
106
107   }
108
109 }