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
10 * ZTE - initial API and implementation and/or initial documentation
12 package org.onap.sdc.workflowdesigner.resources;
14 import static org.junit.Assert.assertEquals;
16 import java.io.IOException;
18 import java.nio.file.Paths;
19 import java.util.UUID;
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;
32 public class WorkflowModelerResourceTest {
33 private static final String WORKFLOW_JSON_TEMP_FILE_NAME = "temp_workflow.json";
36 * @throws java.lang.Exception
39 public void setUp() throws Exception {}
42 * @throws java.lang.Exception
45 public void tearDown() throws Exception {}
49 * {@link org.onap.sdc.workflowdesigner.resources.WorkflowModelerResource#buildBPMN(java.net.URI, java.lang.String)}.
52 public void testBuildBPMN() {
53 String bpmn = parseBpmnfromJsonFile();
54 assertEquals(false, bpmn.isEmpty());
60 private String parseBpmnfromJsonFile() {
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) {
75 * {@link org.onap.sdc.workflowdesigner.resources.WorkflowModelerResource#insertJson2Bpmn(java.lang.String, java.lang.String)}.
78 public void testInsertJson2Bpmn() {
79 String bpmn = parseBpmnfromJsonFile();
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);
86 String json1 = resource.readJsonfromBPMN(combineBpmn);
88 assertEqualsJson(json, json1);
89 } catch (IOException e) {
90 } catch (DocumentException e) {
98 private void assertEqualsJson(String json, String json1) {
99 WorkflowInfo wi = JsonUtils.fromJson(json, WorkflowInfo.class);
100 WorkflowInfo wi1 = JsonUtils.fromJson(json1, WorkflowInfo.class);
102 String newJson = JsonUtils.toJson(wi);
103 String newJson1 = JsonUtils.toJson(wi1);
105 assertEquals(newJson1, newJson);