summaryrefslogtreecommitdiffstats
path: root/holmes-actions/src/test/java/org
diff options
context:
space:
mode:
authorYiLi <li.yi101@zte.com.cn>2018-02-11 17:39:05 +0800
committerYiLi <li.yi101@zte.com.cn>2018-02-12 11:56:57 +0800
commit83307e37a264972f4f9c60a114f40a375e32634b (patch)
treeed6639132fb0a97d8853ded37e9faa9f6eab4e24 /holmes-actions/src/test/java/org
parentd4a991ad631f16831d380eef8e7405d9c2ea85c5 (diff)
Test Replace Jackson with GSON
Change-Id: I7ac92dd83a4bf7dcfb70199f1d0f61e600db8904 Issue-ID: HOLMES-115 Signed-off-by: YiLi <li.yi101@zte.com.cn>
Diffstat (limited to 'holmes-actions/src/test/java/org')
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java49
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiResponseUtilTest.java24
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java18
3 files changed, 23 insertions, 68 deletions
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java
index b3f1eb6..e0d5bf7 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java
@@ -16,8 +16,8 @@
package org.onap.holmes.common.aai;
import static org.easymock.EasyMock.anyObject;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
import java.util.HashMap;
@@ -110,36 +110,7 @@ public class AaiQueryTest {
- @Test
- public void testAaiQuery_getAaiVmData_exception() throws Exception {
- PowerMock.resetAll();
- thrown.expect(CorrelationException.class);
- thrown.expectMessage("Failed to convert aai vm response data to vm entity");
- aaiQuery = PowerMock.createPartialMock(AaiQuery.class, "getVmResourceLinks");
-
- aaiResponseUtil = new AaiResponseUtil();
- Whitebox.setInternalState(aaiQuery, "aaiResponseUtil", aaiResponseUtil);
-
- PowerMockito.mockStatic(HttpsUtils.class);
- Map<String, String> headers = new HashMap<>();
- headers.put("X-TransactionId", AaiConfig.X_TRANSACTION_ID);
- headers.put("X-FromAppId", AaiConfig.X_FROMAPP_ID);
- headers.put("Authorization", AaiConfig.getAuthenticationCredentials());
- headers.put("Accept", "application/json");
- String url = "http://10.96.33.33/api/aai-cloudInfrastructure/v11";
-
- when(HttpsUtils.get(url, headers)).thenReturn("");
-
- PowerMockito.mockStatic(MicroServiceConfig.class);
- when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("http://10.96.33.33:80");
- PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2")
- .andReturn("/aai/v11/cloud-infrastructure");
-
- PowerMock.replayAll();
- Whitebox.invokeMethod(aaiQuery, "getAaiVmData", "test1", "test2");
- PowerMock.verifyAll();
- }
@Test
public void testAaiQuery_getAaiVmData_httpsutils_exception() throws Exception {
@@ -189,23 +160,7 @@ public class AaiQueryTest {
assertThat(resource, equalTo("le-vserver-id-val-51834"));
}
- @Test
- public void testAaiQuery_getVmResourceLinks_exception() throws Exception {
- PowerMock.resetAll();
- thrown.expect(CorrelationException.class);
- thrown.expectMessage("Failed to get aai resource link");
- aaiQuery = PowerMock.createPartialMock(AaiQuery.class, "getResourceLinksResponse");
-
- aaiResponseUtil = new AaiResponseUtil();
- Whitebox.setInternalState(aaiQuery, "aaiResponseUtil", aaiResponseUtil);
-
- PowerMock.expectPrivate(aaiQuery, "getResourceLinksResponse", "test1", "test2").andReturn("");
- PowerMock.replayAll();
- String resource = Whitebox.invokeMethod(aaiQuery, "getVmResourceLinks", "test1", "test2");
- PowerMock.verifyAll();
- assertThat(resource, equalTo("le-vserver-id-val-51834"));
- }
@Test
public void testAaiQuery_getResourceLinksResponse() throws Exception {
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiResponseUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiResponseUtilTest.java
index fee98b9..3d20af9 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiResponseUtilTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiResponseUtilTest.java
@@ -16,8 +16,9 @@
package org.onap.holmes.common.aai;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
import java.io.IOException;
import java.util.List;
@@ -112,12 +113,6 @@ public class AaiResponseUtilTest {
assertThat(actual.isEmpty(), equalTo(true));
}
- @Test
- public void testAaiResponseUtil_convert_resource_link_throw_IOException() throws IOException {
- thrown.expect(IOException.class);
- String json = "{**}";
- aaiResponseUtil.convertJsonToVmResourceLink(json);
- }
@Test
public void testAaiResponseUtil_convert_VmEntity_success() throws IOException {
@@ -142,12 +137,6 @@ public class AaiResponseUtilTest {
assertThat(actual.getVserverSelflink(), equalTo("example-vserver-selflink-val-2"));
}
- @Test
- public void testAaiResponseUtil_convert_VmEntity_throw_IOException() throws IOException {
- thrown.expect(IOException.class);
- String json = "{**}";
- aaiResponseUtil.convertJsonToVmEntity(json);
- }
@Test
public void testAaiResponseUtil_convert_VmEntity_input_empty() throws IOException {
@@ -222,13 +211,6 @@ public class AaiResponseUtilTest {
}
@Test
- public void testAaiResponseUtil_throw_IOException() throws IOException {
- thrown.expect(IOException.class);
- String json = "{**}";
- aaiResponseUtil.convertJsonToVnfEntity(json);
- }
-
- @Test
public void testAaiResponseUtil_convert_VnfEntity_input_empty() throws IOException {
String json = "{}";
VnfEntity actual = aaiResponseUtil.convertJsonToVnfEntity(json);
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java
index 92658d6..d701f3d 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java
@@ -16,6 +16,11 @@
package org.onap.holmes.common.api.stat;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
import java.util.Date;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertFalse;
@@ -29,6 +34,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.onap.holmes.common.api.entity.ServiceNode;
public class AlarmTest {
@@ -190,4 +196,16 @@ public class AlarmTest {
alarm.setCenterType(centerType);
assertThat(centerType, equalTo(alarm.getCenterType()));
}
+ @Test
+ public void TestJson(){
+ ServiceNode serviceNode = new ServiceNode();
+ serviceNode.setIp("111");
+ String jsonString = "{\"uid\":\"189024\", \"region\":\"SouthChina\", \"order\":123}";
+ String COMPLEX_JSON_STR = "{\"teacherName\":\"crystall\",\"teacherAge\":27,\"course\":{\"courseName\":\"english\",\"code\":1270},\"students\":[{\"studentName\":\"lily\",\"studentAge\":12},{\"studentName\":\"lucy\",\"studentAge\":15}]}";
+
+ JSONObject jsonObject = JSON.parseObject(COMPLEX_JSON_STR);
+ JSONArray jsonArray = jsonObject.getJSONArray("students");
+ System.out.printf("jsonObject:"+jsonArray);
+// System.out.println("uid:" + retMap.get("uid") + ", " + "region:" + retMap.get("region") + ", " + "order:" + retMap.get("order"));
+ }
}