X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=holmes-actions%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fholmes%2Fcommon%2Faai%2FAaiQueryTest.java;h=44e39b1f04c3847f44642c69df30cb7f25e06ac6;hb=bf20ddf00200c5468da7a0090caf28beebb93e9c;hp=b3f1eb6c45c9cbede96c262cdf96ce4aceccbe9e;hpb=1be6bdd6b55219294a9ce6f708433fef3737cc13;p=holmes%2Fcommon.git 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..44e39b1 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,12 +16,13 @@ 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; import java.util.Map; +import org.apache.http.HttpResponse; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -94,7 +95,9 @@ public class AaiQueryTest { 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("{}"); + HttpResponse httpResponse = PowerMock.createMock(HttpResponse.class); + when(HttpsUtils.get(url, headers)).thenReturn(httpResponse); + when(HttpsUtils.extractResponseEntity(httpResponse)).thenReturn("{}"); PowerMockito.mockStatic(MicroServiceConfig.class); when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("http://10.96.33.33:80"); @@ -108,39 +111,6 @@ public class AaiQueryTest { assertThat(vmEntity == null, equalTo(true)); } - - - @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 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 { PowerMock.resetAll(); @@ -189,23 +159,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 { @@ -257,7 +211,9 @@ public class AaiQueryTest { headers.put("Accept", "application/json"); String url = "host_url"; - when(HttpsUtils.get(url, headers)).thenReturn(""); + HttpResponse httpResponse = PowerMock.createMock(HttpResponse.class); + when(HttpsUtils.get(url, headers)).thenReturn(httpResponse); + when(HttpsUtils.extractResponseEntity(httpResponse)).thenReturn(""); PowerMock.replayAll(); String resource = Whitebox.invokeMethod(aaiQuery, "getResponse", "host_url");