summaryrefslogtreecommitdiffstats
path: root/sdc-workflow-designer-server
diff options
context:
space:
mode:
Diffstat (limited to 'sdc-workflow-designer-server')
-rw-r--r--sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResource.java8
-rw-r--r--sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/entity/I18nString.java17
-rw-r--r--sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/JsonUtils.java41
-rw-r--r--sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResourceTest.java6
-rw-r--r--sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/utils/JsonUtilsTest.java59
5 files changed, 122 insertions, 9 deletions
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResource.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResource.java
index 10269a37..600ec8ca 100644
--- a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResource.java
+++ b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResource.java
@@ -26,12 +26,12 @@ import org.eclipse.jetty.http.HttpStatus;
import org.onap.sdc.workflowdesigner.resources.entity.ExtActivityDisplayInfo;
import org.onap.sdc.workflowdesigner.resources.entity.ExtendActivity;
import org.onap.sdc.workflowdesigner.utils.FileCommonUtils;
+import org.onap.sdc.workflowdesigner.utils.JsonUtils;
import org.onap.sdc.workflowdesigner.utils.RestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.codahale.metrics.annotation.Timed;
-import com.google.gson.Gson;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -90,8 +90,7 @@ public class ExtendActivityResource {
*/
private ExtendActivity[] retriveExtActivites(String sence) throws IOException {
String json = FileCommonUtils.readString(EXT_ACTIVITIES_FILE_NAME);
- Gson gson = new Gson();
- return gson.fromJson(json, ExtendActivity[].class);
+ return JsonUtils.fromJson(json, ExtendActivity[].class);
}
@@ -125,8 +124,7 @@ public class ExtendActivityResource {
*/
private ExtActivityDisplayInfo retriveDisplayInfo(String sence) throws IOException {
String json = FileCommonUtils.readString(EXT_ACTIVITIES_DISPLAY_INFO_FILE_NAME);
- Gson gson = new Gson();
- return gson.fromJson(json, ExtActivityDisplayInfo.class);
+ return JsonUtils.fromJson(json, ExtActivityDisplayInfo.class);
}
}
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/entity/I18nString.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/entity/I18nString.java
index 1dc880d8..1ed14f6f 100644
--- a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/entity/I18nString.java
+++ b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/entity/I18nString.java
@@ -20,6 +20,23 @@ public class I18nString {
private String zh_CN;
/**
+ *
+ */
+ public I18nString() {
+ super();
+ }
+
+ /**
+ * @param en_US
+ * @param zh_CN
+ */
+ public I18nString(String en_US, String zh_CN) {
+ super();
+ this.en_US = en_US;
+ this.zh_CN = zh_CN;
+ }
+
+ /**
* @return the en_US
*/
public String getEn_US() {
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/JsonUtils.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/JsonUtils.java
new file mode 100644
index 00000000..09588ef3
--- /dev/null
+++ b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/JsonUtils.java
@@ -0,0 +1,41 @@
+/**
+ * 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.utils;
+
+import com.google.gson.Gson;
+
+/**
+ *
+ */
+public class JsonUtils {
+ /**
+ *
+ * @param json
+ * @param clazz
+ * @return
+ */
+ public static <T> T fromJson(String json, Class<T> clazz) {
+ Gson gson = new Gson();
+ return gson.fromJson(json, clazz);
+ }
+
+ /**
+ *
+ * @param t
+ * @return
+ */
+ public static <T> String toJson(T t) {
+ Gson gson = new Gson();
+ return gson.toJson(t);
+ }
+
+}
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 8d3fd5d3..18a8597a 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
@@ -20,8 +20,7 @@ import org.junit.Before;
import org.junit.Test;
import org.onap.sdc.workflowdesigner.resources.entity.ExtendActivity;
import org.onap.sdc.workflowdesigner.utils.FileCommonUtils;
-
-import com.google.gson.Gson;
+import org.onap.sdc.workflowdesigner.utils.JsonUtils;
/**
*
@@ -49,8 +48,7 @@ public class ExtendActivityResourceTest {
try {
Response response = resource.getExtActivities("test");
ExtendActivity[] extActivities = (ExtendActivity[]) response.getEntity();
- Gson gson = new Gson();
- FileCommonUtils.write("test.json", gson.toJson(extActivities));
+ FileCommonUtils.write("test.json", JsonUtils.toJson(extActivities));
assertEquals(extActivities.length == 0, false);
} catch (Exception e) {
e.printStackTrace();
diff --git a/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/utils/JsonUtilsTest.java b/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/utils/JsonUtilsTest.java
new file mode 100644
index 00000000..2672f6bd
--- /dev/null
+++ b/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/utils/JsonUtilsTest.java
@@ -0,0 +1,59 @@
+/**
+ * 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.utils;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.sdc.workflowdesigner.resources.entity.I18nString;
+
+/**
+ *
+ */
+public class JsonUtilsTest {
+
+ /**
+ * @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.utils.JsonUtils#fromJson(java.lang.String, java.lang.Class)}.
+ */
+ @Test
+ public void testFromJson() {
+ String i18n = "{\"en_US\":\"Service Task\",\"zh_CN\":\"Service Task\"}";
+ I18nString i18nString = JsonUtils.fromJson(i18n, I18nString.class);
+ assertNotNull(i18nString);
+ }
+
+ /**
+ * Test method for {@link org.onap.sdc.workflowdesigner.utils.JsonUtils#toJson(java.lang.Object)}.
+ */
+ @Test
+ public void testToJson() {
+ I18nString i18nString = new I18nString("Service Task", "Service Task");
+ String i18n = JsonUtils.toJson(i18nString);
+ String expect = "{\"en_US\":\"Service Task\",\"zh_CN\":\"Service Task\"}";
+ assertEquals(expect, i18n);
+ }
+
+}