X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=holmes-actions%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fholmes%2Fcommon%2Faai%2FAaiQuery4CcvpnTest.java;h=43cb5173a4fab05c72994b0d8ceaf76f193934f7;hb=67ef2af341cbe8530437f67bbffdc7721f4e5587;hp=51cba1c7cf0f85c1b156fd6f1d7a7a1eb217612c;hpb=b6f78979786fdc4eb1e67d40cdd0d246c3db44d3;p=holmes%2Fcommon.git diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4CcvpnTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4CcvpnTest.java index 51cba1c..43cb517 100644 --- a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4CcvpnTest.java +++ b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4CcvpnTest.java @@ -17,6 +17,7 @@ package org.onap.holmes.common.aai; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import org.easymock.EasyMock; +import org.glassfish.jersey.client.HttpUrlConnectorProvider; import org.junit.*; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; @@ -36,6 +37,7 @@ import java.io.*; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; +import java.util.Map; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; @@ -51,7 +53,7 @@ public class AaiQuery4CcvpnTest { private static JSONObject data; - private static AaiQuery4Ccvpn aai = new AaiQuery4Ccvpn(); + private static AaiQuery4Ccvpn aai = AaiQuery4Ccvpn.newInstance(); private static MultivaluedMap headers = new MultivaluedHashMap<>(); private static Client client; @@ -169,6 +171,10 @@ public class AaiQuery4CcvpnTest { EasyMock.expect(response.getEntity()).andReturn(data.getJSONObject("service-instances-by-service-type")); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.NOT_FOUND).times(2); + mockGetMethod(); + EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("service-instance").toString()); + EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.NOT_FOUND).times(2); + thrown.expect(RuntimeException.class); PowerMock.replayAll(); @@ -199,6 +205,16 @@ public class AaiQuery4CcvpnTest { EasyMock.expect(response.getEntity()).andReturn(data.getJSONObject("service-instances-by-service-type")); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); + mockGetMethod(); + EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("service-instance").toString()); + EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); + mockGetMethod(); + EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("service-instance").toString()); + EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); + mockGetMethod(); + EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("service-instance").toString()); + EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); + PowerMock.replayAll(); JSONArray instances = aai.getServiceInstances("network-1", "pnf-1", "interface-1", "DOWN"); @@ -208,17 +224,21 @@ public class AaiQuery4CcvpnTest { assertThat(instances.getJSONObject(0).getString("service-instance-id"), equalTo("some id 1")); assertThat(instances.getJSONObject(1).getString("service-instance-id"), equalTo("some id 2")); assertThat(instances.getJSONObject(2).getString("service-instance-id"), equalTo("some id 3")); + assertThat(instances.getJSONObject(0).getString("input-parameters"), equalTo("This is the service instance recreation input looked up by CL.")); + assertThat(instances.getJSONObject(0).getString("globalSubscriberId"), equalTo("e151059a-d924-4629-845f-264db19e50b4")); + assertThat(instances.getJSONObject(0).getString("serviceType"), equalTo("volte")); } @Test - public void test_getServiceInstances_1() throws CorrelationException { + public void test_getServiceInstances_1() throws Exception { mockGetMethod(); EasyMock.expect(response.getEntity()).andReturn(data.getJSONObject("service-instances-by-service-type")); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); PowerMock.replayAll(); - JSONArray instances = aai.getServiceInstances("custom-1", "service-type-1"); + JSONArray instances = (JSONArray) Whitebox.invokeMethod(aai, "getServiceInstances", + "custom-1", "service-type-1"); PowerMock.verifyAll(); @@ -228,7 +248,7 @@ public class AaiQuery4CcvpnTest { } @Test - public void test_getServiceInstances_1_exception() throws CorrelationException { + public void test_getServiceInstances_1_exception() throws Exception { mockGetMethod(); EasyMock.expect(response.getEntity()).andReturn(data.getJSONObject("service-instances-by-service-type")); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.NOT_FOUND).times(2); @@ -237,7 +257,8 @@ public class AaiQuery4CcvpnTest { PowerMock.replayAll(); - JSONArray instances = aai.getServiceInstances("custom-1", "service-type-1"); + JSONArray instances = (JSONArray) Whitebox.invokeMethod(aai, "getServiceInstances", + "custom-1", "service-type-1"); PowerMock.verifyAll(); @@ -306,7 +327,10 @@ public class AaiQuery4CcvpnTest { private void mockPatchMethod() { initCommonMock(); - EasyMock.expect(builder.method(EasyMock.anyObject(String.class), EasyMock.anyObject(Entity.class))).andReturn(response); + Invocation invocation = PowerMock.createMock(Invocation.class); + EasyMock.expect(builder.build(EasyMock.anyObject(String.class), EasyMock.anyObject(Entity.class))).andReturn(invocation); + EasyMock.expect(invocation.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true)).andReturn(invocation); + EasyMock.expect(invocation.invoke()).andReturn(response); } private void initCommonMock() {