diff options
author | 2018-02-09 09:53:54 +0800 | |
---|---|---|
committer | 2018-02-09 10:37:19 +0800 | |
commit | 37630177bc70661ce86cb12e9af34e8c09893f4d (patch) | |
tree | 83ccafe8389fd8fc504c628a67b3618ac8c222bf /holmes-actions/src/test/java | |
parent | a55c700bc3aaab61731d509e4f4c85f40d6330e6 (diff) |
Test Replace Jackson with GSON
Change-Id: Id4c2ed81e7dbd5546940ff50363555336d55b75b
Issue-ID: HOLMES-115
Signed-off-by: YiLi <li.yi101@zte.com.cn>
Diffstat (limited to 'holmes-actions/src/test/java')
-rw-r--r-- | holmes-actions/src/test/java/org/onap/holmes/common/utils/JacksonUtilTest.java | 18 | ||||
-rw-r--r-- | holmes-actions/src/test/java/org/onap/holmes/common/utils/Md5UtilTest.java | 24 |
2 files changed, 23 insertions, 19 deletions
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 index 5f90c2d..6fa9c11 100644 --- 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 @@ -20,6 +20,15 @@ package org.onap.holmes.common.utils; import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+import java.lang.reflect.Type;
import org.junit.Test;
import org.onap.holmes.common.utils.bean.TestBean;
@@ -29,21 +38,22 @@ public class JacksonUtilTest { public void testBeanToJson() throws Exception {
TestBean o = new TestBean();
o.setId("id");
- String result = JacksonUtil.beanToJson(o);
+ String result = GsonUtil.beanToJson(o);
assertThat("{\"id\":\"id\"}", equalTo(result));
}
@Test
public void jsonToBean_json_null() throws Exception {
String jsonNull = null;
- TestBean testBean = JacksonUtil.jsonToBean(jsonNull, TestBean.class);
- assertThat(testBean.getId(), equalTo(null));
+ TestBean testBean = GsonUtil.jsonToBean(jsonNull, TestBean.class);
+ assertThat(testBean, equalTo(null));
}
@Test
public void jsonToBean_json_normal() throws Exception {
String json = "{\"id\":\"id\"}";
- TestBean testBean = JacksonUtil.jsonToBean(json, TestBean.class);
+ TestBean testBean = GsonUtil.jsonToBean(json, TestBean.class);
assertThat(testBean.getId(), equalTo("id"));
}
+
}
\ No newline at end of file diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/Md5UtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/Md5UtilTest.java index 041b09d..af81a11 100644 --- a/holmes-actions/src/test/java/org/onap/holmes/common/utils/Md5UtilTest.java +++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/Md5UtilTest.java @@ -26,8 +26,9 @@ import org.onap.holmes.common.dcae.entity.DcaeConfigurations; import org.onap.holmes.common.dcae.entity.SecurityInfo; public class Md5UtilTest { + @Test - public void testMd5NormalDiff(){ + public void testMd5NormalDiff() { String contents1 = "contents1"; String contents2 = "contents2"; @@ -35,7 +36,7 @@ public class Md5UtilTest { } @Test - public void testMd5NormalSame(){ + public void testMd5NormalSame() { String contents1 = "contents"; String contents2 = "contents"; @@ -43,7 +44,7 @@ public class Md5UtilTest { } @Test - public void testMd5Null(){ + public void testMd5Null() { String contents1 = null; String contents2 = null; @@ -51,32 +52,25 @@ public class Md5UtilTest { } @Test - public void testMd5ObjDiff(){ + public void testMd5ObjDiff() { DcaeConfigurations config1 = new DcaeConfigurations(); DcaeConfigurations config2 = new DcaeConfigurations(); config1.addPubSecInfo("config1", new SecurityInfo()); config2.addPubSecInfo("config2", new SecurityInfo()); + assertThat(Md5Util.md5(config1), not(equalTo(Md5Util.md5(config2)))); - try { - assertThat(Md5Util.md5(config1), not(equalTo(Md5Util.md5(config2)))); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } } @Test - public void testMd5ObjSame(){ + public void testMd5ObjSame() { DcaeConfigurations config1 = new DcaeConfigurations(); DcaeConfigurations config2 = new DcaeConfigurations(); config1.addPubSecInfo("config", new SecurityInfo()); config2.addPubSecInfo("config", new SecurityInfo()); - try { - assertThat(Md5Util.md5(config1), equalTo(Md5Util.md5(config2))); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } + assertThat(Md5Util.md5(config1), equalTo(Md5Util.md5(config2))); + } }
\ No newline at end of file |