Test Replace Jackson with GSON 71/31171/2
authorYiLi <li.yi101@zte.com.cn>
Sun, 11 Feb 2018 01:45:57 +0000 (09:45 +0800)
committerYiLi <li.yi101@zte.com.cn>
Sun, 11 Feb 2018 02:02:21 +0000 (10:02 +0800)
Change-Id: I2b4ada41d7a35d3427d574000bf1b3753e4d8d32
Issue-ID: HOLMES-115
Signed-off-by: YiLi <li.yi101@zte.com.cn>
holmes-actions/src/main/java/org/onap/holmes/common/config/MQConfig.java
holmes-actions/src/main/java/org/onap/holmes/common/dmaap/entity/PolicyMsg.java
holmes-actions/src/main/java/org/onap/holmes/common/utils/JacksonUtil.java [deleted file]
holmes-actions/src/test/java/org/onap/holmes/common/utils/JacksonUtilTest.java [deleted file]
holmes-actions/src/test/java/org/onap/holmes/common/utils/Md5UtilTest.java

index e1b333b..2ade152 100644 (file)
 \r
 package org.onap.holmes.common.config;\r
 \r
-import com.fasterxml.jackson.annotation.JsonProperty;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-import javax.validation.constraints.NotNull;\r
-\r
 public class MQConfig {\r
 \r
-    @JsonProperty\r
-    @NotNull\r
     public String brokerIp;\r
 \r
-    @JsonProperty\r
-    @NotNull\r
     public int brokerPort;\r
 \r
-    @JsonProperty\r
     public String brokerUsername;\r
 \r
-    @JsonProperty\r
     public String brokerPassword;\r
 }\r
index 6955d90..6c3189c 100644 (file)
@@ -16,7 +16,7 @@
 \r
 package org.onap.holmes.common.dmaap.entity;\r
 \r
-import com.fasterxml.jackson.annotation.JsonProperty;\r
+import com.google.gson.annotations.SerializedName;\r
 import java.util.HashMap;\r
 import java.util.Map;\r
 import lombok.Getter;\r
@@ -37,10 +37,10 @@ public class PolicyMsg {
     private String policyName;\r
     private String policyScope;\r
     private String from = "DCAE";\r
-    @JsonProperty(value = "target_type")\r
+    @SerializedName(value = "target_type")\r
     private String targetType = "VM";\r
     private String target;\r
-    @JsonProperty(value = "AAI")\r
+    @SerializedName(value = "AAI")\r
     private Map<String, Object> aai = new HashMap<>();\r
 \r
     public static enum EVENT_STATUS {\r
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/JacksonUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/JacksonUtil.java
deleted file mode 100644 (file)
index c5c52c2..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/**\r
- * Copyright 2017 ZTE Corporation.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.onap.holmes.common.utils;\r
-\r
-import com.fasterxml.jackson.core.JsonProcessingException;\r
-import com.fasterxml.jackson.databind.ObjectMapper;\r
-import java.io.IOException;\r
-\r
-public class JacksonUtil {\r
-\r
-    private JacksonUtil() {\r
-\r
-    }\r
-\r
-    public static String beanToJson(Object obj) throws JsonProcessingException {\r
-        ObjectMapper objectMapper = new ObjectMapper();\r
-        return objectMapper.writeValueAsString(obj);\r
-    }\r
-\r
-    public static <T> T jsonToBean(String json, Class<T> cls) throws IOException {\r
-        ObjectMapper objectMapper = new ObjectMapper();\r
-        if (json == null) {\r
-            return objectMapper.readValue("{}", cls);\r
-        }\r
-        return objectMapper.readValue(json, cls);\r
-    }\r
-}\r
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/JacksonUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/JacksonUtilTest.java
deleted file mode 100644 (file)
index 6fa9c11..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/**\r
- * Copyright 2016 ZTE Corporation.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-\r
-package org.onap.holmes.common.utils;\r
-\r
-import static org.hamcrest.core.IsEqual.equalTo;\r
-import static org.junit.Assert.assertThat;\r
-\r
-import com.google.gson.Gson;\r
-import com.google.gson.GsonBuilder;\r
-import com.google.gson.JsonDeserializationContext;\r
-import com.google.gson.JsonDeserializer;\r
-import com.google.gson.JsonElement;\r
-import com.google.gson.JsonParseException;\r
-import com.google.gson.JsonSerializationContext;\r
-import com.google.gson.JsonSerializer;\r
-import java.lang.reflect.Type;\r
-import org.junit.Test;\r
-import org.onap.holmes.common.utils.bean.TestBean;\r
-\r
-public class JacksonUtilTest {\r
-\r
-    @Test\r
-    public void testBeanToJson() throws Exception {\r
-        TestBean o = new TestBean();\r
-        o.setId("id");\r
-        String result = GsonUtil.beanToJson(o);\r
-        assertThat("{\"id\":\"id\"}", equalTo(result));\r
-    }\r
-\r
-    @Test\r
-    public void jsonToBean_json_null() throws Exception {\r
-        String jsonNull = null;\r
-        TestBean testBean = GsonUtil.jsonToBean(jsonNull, TestBean.class);\r
-        assertThat(testBean, equalTo(null));\r
-    }\r
-\r
-    @Test\r
-    public void jsonToBean_json_normal() throws Exception {\r
-        String json = "{\"id\":\"id\"}";\r
-        TestBean testBean = GsonUtil.jsonToBean(json, TestBean.class);\r
-        assertThat(testBean.getId(), equalTo("id"));\r
-    }\r
-\r
-}
\ No newline at end of file
index af81a11..f6680a3 100644 (file)
@@ -20,7 +20,6 @@ import static org.hamcrest.core.IsEqual.equalTo;
 import static org.hamcrest.core.IsNot.not;
 import static org.junit.Assert.assertThat;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
 import org.junit.Test;
 import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
 import org.onap.holmes.common.dcae.entity.SecurityInfo;