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=51c3444d7f7f535b009402cd11fb06839438250b;hb=c7fd788a1cfc030e54047701b1c1f27e42a91d1c;hp=c7c32eb9a23615fd314f4eb5ce95c92f6690d5f9;hpb=c3b07b59b78275e206011bc069ffd97cc65c5ec1;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 c7c32eb..51c3444 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; @@ -119,11 +121,12 @@ public class AaiQuery4CcvpnTest { } @Test - public void test_getLogicLink_exception() { + public void test_getLogicLink_exception() throws CorrelationException { mockGetMethod(); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.NOT_FOUND).times(2); + EasyMock.expect(response.readEntity(String.class)).andReturn("Error!"); - thrown.expect(RuntimeException.class); + thrown.expect(CorrelationException.class); PowerMock.replayAll(); @@ -136,9 +139,9 @@ public class AaiQuery4CcvpnTest { } @Test - public void test_getLogicLink() { + public void test_getLogicLink() throws CorrelationException { mockGetMethod(); - EasyMock.expect(response.getEntity()).andReturn(data.getJSONObject("logic-link")); + EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("logic-link").toJSONString()); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); PowerMock.replayAll(); @@ -154,19 +157,25 @@ public class AaiQuery4CcvpnTest { @Test public void test_getServiceInstances_exception() { mockGetMethod(); - EasyMock.expect(response.getEntity()).andReturn(data.getJSONObject("vpn-binding")); + EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("vpn-binding").toJSONString()); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); mockGetMethod(); - EasyMock.expect(response.getEntity()).andReturn(data.getJSONObject("connectivity")); + EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("connectivity").toJSONString()); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); mockGetMethod(); - EasyMock.expect(response.getEntity()).andReturn(data.getJSONObject("service-instance-by-connectivity")); + EasyMock.expect(response.readEntity(String.class)) + .andReturn(data.getJSONObject("service-instance-by-connectivity").toJSONString()); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); mockGetMethod(); - EasyMock.expect(response.getEntity()).andReturn(data.getJSONObject("service-instances-by-service-type")); + EasyMock.expect(response.readEntity(String.class)) + .andReturn(data.getJSONObject("service-instances-by-service-type").toJSONString()); + 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); @@ -184,19 +193,31 @@ public class AaiQuery4CcvpnTest { @Test public void test_getServiceInstances() { mockGetMethod(); - EasyMock.expect(response.getEntity()).andReturn(data.getJSONObject("vpn-binding")); + EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("vpn-binding").toJSONString()); + EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); + + mockGetMethod(); + EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("connectivity").toJSONString()); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); mockGetMethod(); - EasyMock.expect(response.getEntity()).andReturn(data.getJSONObject("connectivity")); + EasyMock.expect(response.readEntity(String.class)) + .andReturn(data.getJSONObject("service-instance-by-connectivity").toJSONString()); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); mockGetMethod(); - EasyMock.expect(response.getEntity()).andReturn(data.getJSONObject("service-instance-by-connectivity")); + EasyMock.expect(response.readEntity(String.class)) + .andReturn(data.getJSONObject("service-instances-by-service-type").toJSONString()); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); mockGetMethod(); - EasyMock.expect(response.getEntity()).andReturn(data.getJSONObject("service-instances-by-service-type")); + 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(); @@ -208,17 +229,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 Exception { mockGetMethod(); - EasyMock.expect(response.getEntity()).andReturn(data.getJSONObject("service-instances-by-service-type")); + EasyMock.expect(response.readEntity(String.class)) + .andReturn(data.getJSONObject("service-instances-by-service-type").toJSONString()); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); PowerMock.replayAll(); - JSONArray instances = (JSONArray)Whitebox.invokeMethod(aai, "getServiceInstances", + JSONArray instances = (JSONArray) Whitebox.invokeMethod(aai, "getServiceInstances", "custom-1", "service-type-1"); PowerMock.verifyAll(); @@ -231,14 +256,14 @@ public class AaiQuery4CcvpnTest { @Test public void test_getServiceInstances_1_exception() throws Exception { mockGetMethod(); - EasyMock.expect(response.getEntity()).andReturn(data.getJSONObject("service-instances-by-service-type")); + EasyMock.expect(response.readEntity(String.class)).andReturn("Failed to get the service instance by type."); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.NOT_FOUND).times(2); thrown.expect(CorrelationException.class); PowerMock.replayAll(); - JSONArray instances = (JSONArray)Whitebox.invokeMethod(aai, "getServiceInstances", + JSONArray instances = (JSONArray) Whitebox.invokeMethod(aai, "getServiceInstances", "custom-1", "service-type-1"); PowerMock.verifyAll(); @@ -264,6 +289,7 @@ public class AaiQuery4CcvpnTest { public void test_updateTerminalPointStatus_exception() throws CorrelationException { mockPatchMethod(); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.NOT_FOUND).times(2); + EasyMock.expect(response.readEntity(String.class)).andReturn("Failed to update the TP information."); thrown.expect(CorrelationException.class); @@ -290,6 +316,7 @@ public class AaiQuery4CcvpnTest { public void test_updateLogicLinkStatus_exception() throws CorrelationException { mockPatchMethod(); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.NOT_FOUND).times(2); + EasyMock.expect(response.readEntity(String.class)).andReturn("Failed to update the logic link information."); thrown.expect(CorrelationException.class); @@ -308,7 +335,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() {