Add Unit Test & Remove redundant code 33/39333/1
authorYuanHu <yuan.hu1@zte.com.cn>
Wed, 28 Mar 2018 01:02:58 +0000 (09:02 +0800)
committerYuanHu <yuan.hu1@zte.com.cn>
Wed, 28 Mar 2018 01:02:58 +0000 (09:02 +0800)
Add Unit Test & Remove redundant code

Issue-ID: SDC-1078

Change-Id: I83ee83f3265386373749463c43dced047d4aa407
Signed-off-by: YuanHu <yuan.hu1@zte.com.cn>
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/converter/Bpmn4Tosca2Bpmn.java [deleted file]
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/WorkflowModelerResource.java
sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/SDCServiceProxyInfoTest.java [new file with mode: 0644]
sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/WorkflowDesignerConfigurationTest.java [new file with mode: 0644]
sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/convert/BPMN4Tosca2BpmnTest.java [deleted file]

diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/converter/Bpmn4Tosca2Bpmn.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/converter/Bpmn4Tosca2Bpmn.java
deleted file mode 100644 (file)
index 0b4f2ed..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/**\r
- * Copyright (c) 2017 ZTE Corporation.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the Apache License, Version 2.0\r
- * and the Eclipse Public License v1.0 which both accompany this distribution,\r
- * and are available at http://www.eclipse.org/legal/epl-v10.html\r
- * and http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Contributors:\r
- *     ZTE - initial API and implementation and/or initial documentation\r
- */\r
-package org.onap.sdc.workflowdesigner.converter;\r
-\r
-import java.net.URI;\r
-import java.nio.file.Files;\r
-import java.nio.file.Path;\r
-import java.nio.file.Paths;\r
-import java.nio.file.StandardOpenOption;\r
-\r
-import org.onap.sdc.workflowdesigner.model.Process;\r
-import org.onap.sdc.workflowdesigner.parser.Bpmn4ToscaJsonParser;\r
-import org.onap.sdc.workflowdesigner.writer.BpmnPlanArtefactWriter;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-public class Bpmn4Tosca2Bpmn {\r
-\r
-    private static Logger log = LoggerFactory.getLogger(Bpmn4Tosca2Bpmn.class);\r
-\r
-    /**\r
-     * Transforms the given BPMN4Tosca Json management into a bpmn plan that can\r
-     * be excuted by activiti.\r
-     * <p>\r
-     *\r
-     * @param srcBpmn4ToscaJsonFile\r
-     * @param targetBpmnArchive\r
-     * @throws Exception \r
-     */\r
-    public void transform(String processId, URI srcBpmn4ToscaJsonFile, URI targetBpmnArchive) throws Exception {\r
-        log.info("transform start");\r
-\r
-        // parse json object\r
-        Bpmn4ToscaJsonParser parser = new Bpmn4ToscaJsonParser();\r
-        Process process = parser.parse(processId, srcBpmn4ToscaJsonFile);\r
-\r
-        // transform bpmn template\r
-        BpmnPlanArtefactWriter writer = new BpmnPlanArtefactWriter(process);\r
-        String workflowString = writer.completePlanTemplate();\r
-\r
-        // write bpmn to file\r
-        Path targetPath = Paths.get(targetBpmnArchive);\r
-        Files.write(targetPath, workflowString.getBytes(), StandardOpenOption.CREATE);\r
-        log.info("transform end");\r
-    }\r
-\r
-}\r
index fe73689..0f0e2dd 100644 (file)
@@ -14,9 +14,9 @@ package org.onap.sdc.workflowdesigner.resources;
 
 import java.io.IOException;
 import java.net.URI;
-import java.nio.file.Paths;
+//import java.nio.file.Paths;
 import java.util.List;
-import java.util.UUID;
+//import java.util.UUID;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
@@ -32,14 +32,14 @@ import org.dom4j.Document;
 import org.dom4j.DocumentException;
 import org.dom4j.DocumentHelper;
 import org.eclipse.jetty.http.HttpStatus;
-import org.onap.sdc.workflowdesigner.common.WorkflowDesignerException;
-import org.onap.sdc.workflowdesigner.externalservice.sdc.SDCServiceProxy;
-import org.onap.sdc.workflowdesigner.externalservice.sdc.entity.WorkflowArtifactInfo;
+//import org.onap.sdc.workflowdesigner.common.WorkflowDesignerException;
+//import org.onap.sdc.workflowdesigner.externalservice.sdc.SDCServiceProxy;
+//import org.onap.sdc.workflowdesigner.externalservice.sdc.entity.WorkflowArtifactInfo;
 import org.onap.sdc.workflowdesigner.model.Process;
 import org.onap.sdc.workflowdesigner.parser.Bpmn4ToscaJsonParser;
-import org.onap.sdc.workflowdesigner.resources.entity.WorkflowInfo;
+//import org.onap.sdc.workflowdesigner.resources.entity.WorkflowInfo;
 import org.onap.sdc.workflowdesigner.utils.FileCommonUtils;
-import org.onap.sdc.workflowdesigner.utils.JsonUtils;
+//import org.onap.sdc.workflowdesigner.utils.JsonUtils;
 import org.onap.sdc.workflowdesigner.utils.RestUtils;
 import org.onap.sdc.workflowdesigner.writer.BpmnPlanArtefactWriter;
 import org.slf4j.Logger;
@@ -63,7 +63,7 @@ public class WorkflowModelerResource {
   private static final Logger logger = LoggerFactory.getLogger(WorkflowModelerResource.class);
 
   private static final String WORKFLOW_JSON_TEMP_FILE_NAME = "temp_workflow.json";
-  private static final String WORKFLOW_XML_TEMP_FILE_NAME = "temp_workflow.xml";
+//  private static final String WORKFLOW_XML_TEMP_FILE_NAME = "temp_workflow.xml";
 
 
   /**
@@ -112,10 +112,10 @@ public class WorkflowModelerResource {
       @ApiParam(value = "Model Content", required = true) String json) {
     try {
       FileCommonUtils.write(WORKFLOW_JSON_TEMP_FILE_NAME, json);
-
-      URI srcUri = Paths.get(".", WORKFLOW_JSON_TEMP_FILE_NAME).toUri();
-      String processName = "plan_" + UUID.randomUUID().toString();
-   // TODO for Nexus-IQ
+      
+      // TODO for Nexus-IQ
+//      URI srcUri = Paths.get(".", WORKFLOW_JSON_TEMP_FILE_NAME).toUri();
+//      String processName = "plan_" + UUID.randomUUID().toString();
 //      String bpmn = buildBPMN(srcUri, processName);
 //      String jsonBpmn = insertJson2Bpmn(json, bpmn);
 
@@ -163,20 +163,20 @@ public class WorkflowModelerResource {
   }
 
 
-  /**
-   * @param json
-   * @param bpmn
-   * @throws WorkflowDesignerException
-   */
-  private void save2SDC(String json, String bpmn) throws WorkflowDesignerException {
-    WorkflowInfo workflowInfo = JsonUtils.fromJson(json, WorkflowInfo.class);
-    WorkflowArtifactInfo workflowArtifactInfo =
-        new WorkflowArtifactInfo(workflowInfo.getName(), workflowInfo.getDescription(), bpmn);
-
-    SDCServiceProxy sdcProxy = new SDCServiceProxy();
-    sdcProxy.saveWorkflowArtifact(workflowInfo.getUuid(), workflowInfo.getOperationId(),
-        workflowInfo.getId(), workflowArtifactInfo);
-  }
+//  /**
+//   * @param json
+//   * @param bpmn
+//   * @throws WorkflowDesignerException
+//   */
+//  private void save2SDC(String json, String bpmn) throws WorkflowDesignerException {
+//    WorkflowInfo workflowInfo = JsonUtils.fromJson(json, WorkflowInfo.class);
+//    WorkflowArtifactInfo workflowArtifactInfo =
+//        new WorkflowArtifactInfo(workflowInfo.getName(), workflowInfo.getDescription(), bpmn);
+//
+//    SDCServiceProxy sdcProxy = new SDCServiceProxy();
+//    sdcProxy.saveWorkflowArtifact(workflowInfo.getUuid(), workflowInfo.getOperationId(),
+//        workflowInfo.getId(), workflowArtifactInfo);
+//  }
 
   /**
    * 
diff --git a/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/SDCServiceProxyInfoTest.java b/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/SDCServiceProxyInfoTest.java
new file mode 100644 (file)
index 0000000..6ae8ffa
--- /dev/null
@@ -0,0 +1,54 @@
+/**\r
+ * Copyright (c) 2018 ZTE Corporation.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the Apache License, Version 2.0\r
+ * and the Eclipse Public License v1.0 which both accompany this distribution,\r
+ * and are available at http://www.eclipse.org/legal/epl-v10.html\r
+ * and http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Contributors:\r
+ *     ZTE - initial API and implementation and/or initial documentation\r
+ */\r
+package org.onap.sdc.workflowdesigner;\r
+\r
+import static org.junit.Assert.*;\r
+\r
+import org.hibernate.validator.constraints.NotEmpty;\r
+import org.junit.After;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+/**\r
+ *\r
+ */\r
+public class SDCServiceProxyInfoTest {\r
+\r
+  /**\r
+   * @throws java.lang.Exception\r
+   */\r
+  @Before\r
+  public void setUp() throws Exception {}\r
+\r
+  /**\r
+   * @throws java.lang.Exception\r
+   */\r
+  @After\r
+  public void tearDown() throws Exception {}\r
+\r
+  @Test\r
+  public void test() {\r
+    String serviceAddr = "serviceAddr";\r
+    String xEcompInstanceId = "xEcompInstanceId";\r
+    String authorization = "authorization";\r
+    \r
+    SDCServiceProxyInfo spi = new SDCServiceProxyInfo();\r
+    spi.setAuthorization(authorization);\r
+    spi.setServiceAddr(serviceAddr);\r
+    spi.setxEcompInstanceId(xEcompInstanceId);\r
+    \r
+    assertEquals(authorization, spi.getAuthorization());\r
+    assertEquals(serviceAddr, spi.getServiceAddr());\r
+    assertEquals(xEcompInstanceId, spi.getxEcompInstanceId());\r
+  }\r
+\r
+}\r
diff --git a/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/WorkflowDesignerConfigurationTest.java b/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/WorkflowDesignerConfigurationTest.java
new file mode 100644 (file)
index 0000000..12e1853
--- /dev/null
@@ -0,0 +1,57 @@
+/**\r
+ * Copyright (c) 2018 ZTE Corporation.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the Apache License, Version 2.0\r
+ * and the Eclipse Public License v1.0 which both accompany this distribution,\r
+ * and are available at http://www.eclipse.org/legal/epl-v10.html\r
+ * and http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Contributors:\r
+ *     ZTE - initial API and implementation and/or initial documentation\r
+ */\r
+package org.onap.sdc.workflowdesigner;\r
+\r
+import static org.junit.Assert.*;\r
+\r
+import javax.validation.constraints.NotNull;\r
+\r
+import org.hibernate.validator.constraints.NotEmpty;\r
+import org.junit.After;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+/**\r
+ *\r
+ */\r
+public class WorkflowDesignerConfigurationTest {\r
+\r
+  /**\r
+   * @throws java.lang.Exception\r
+   */\r
+  @Before\r
+  public void setUp() throws Exception {}\r
+\r
+  /**\r
+   * @throws java.lang.Exception\r
+   */\r
+  @After\r
+  public void tearDown() throws Exception {}\r
+\r
+  @Test\r
+  public void test() {\r
+    String template = "template";\r
+    String defaultName = "Workflow Designer";\r
+    SDCServiceProxyInfo sdcServiceProxy = new SDCServiceProxyInfo();\r
+    \r
+    \r
+    WorkflowDesignerConfiguration wdc = new WorkflowDesignerConfiguration();\r
+    wdc.setDefaultName(defaultName);\r
+    wdc.setSdcServiceProxy(sdcServiceProxy);\r
+    wdc.setTemplate(template);\r
+    \r
+    assertEquals(defaultName, wdc.getDefaultName());\r
+    assertEquals(sdcServiceProxy, wdc.getSdcServiceProxy());\r
+    assertEquals(template, wdc.getTemplate());\r
+  }\r
+\r
+}\r
diff --git a/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/convert/BPMN4Tosca2BpmnTest.java b/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/convert/BPMN4Tosca2BpmnTest.java
deleted file mode 100644 (file)
index 83b52df..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/**\r
- * Copyright (c) 2017-2018 ZTE Corporation.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the Apache License, Version 2.0\r
- * and the Eclipse Public License v1.0 which both accompany this distribution,\r
- * and are available at http://www.eclipse.org/legal/epl-v10.html\r
- * and http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Contributors:\r
- *     ZTE - initial API and implementation and/or initial documentation\r
- */\r
-package org.onap.sdc.workflowdesigner.convert;\r
-\r
-import static org.junit.Assert.assertTrue;\r
-\r
-import java.io.File;\r
-import java.net.URI;\r
-import java.nio.file.Paths;\r
-\r
-import org.apache.velocity.exception.ParseErrorException;\r
-import org.apache.velocity.exception.ResourceNotFoundException;\r
-import org.junit.Test;\r
-import org.onap.sdc.workflowdesigner.converter.Bpmn4Tosca2Bpmn;\r
-\r
-public class BPMN4Tosca2BpmnTest {\r
-    private static String RESOURCES_DIR = "src/test/resources/workflow";\r
-\r
-    @Test\r
-    public void testTransform() throws ResourceNotFoundException, ParseErrorException, Exception {\r
-\r
-        URI srcUri = Paths.get(RESOURCES_DIR, "workflow.json").toUri();\r
-        URI targetUri = Paths.get(RESOURCES_DIR, "bpmnworkflow.bpmn20.xml").toUri();\r
-        BPMN4Tosca2BpmnTest.class.getResource(".");\r
-        Bpmn4Tosca2Bpmn transformer = new Bpmn4Tosca2Bpmn();\r
-//        transformer.transform("transformTest", srcUri, targetUri);\r
-//        assertTrue(new File(targetUri.getPath()).exists());\r
-        // TODO for Nexus-IQ\r
-    }\r
-\r
-}\r