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=11dba544fdc6dfb1d7f671fc67bcfaabf97f64c8;hb=c7fd788a1cfc030e54047701b1c1f27e42a91d1c;hp=f6488c235afe3ee69b55602d6fb4c38a7d2c9392;hpb=96a6ea5cab6575b7e04d6736cee6906298065a7b;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 f6488c2..11dba54 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 @@ -23,6 +23,7 @@ import static org.powermock.api.mockito.PowerMockito.when; import java.util.HashMap; import java.util.Map; import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.easymock.EasyMock; import org.junit.Rule; @@ -42,7 +43,7 @@ import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; -@PrepareForTest({AaiQuery.class, HttpsUtils.class, MicroServiceConfig.class}) +@PrepareForTest({AaiQuery.class, HttpsUtils.class, MicroServiceConfig.class, HttpGet.class}) @RunWith(PowerMockRunner.class) public class AaiQueryTest { @@ -96,11 +97,13 @@ public class AaiQueryTest { 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"; + String url = "http://10.96.33.33:80/api/aai-cloudInfrastructure/v11"; HttpResponse httpResponse = PowerMock.createMock(HttpResponse.class); CloseableHttpClient httpClient = PowerMock.createMock(CloseableHttpClient.class); when(HttpsUtils.getHttpClient(30000)).thenReturn(httpClient); - when(HttpsUtils.get(url, headers, httpClient)).thenReturn(httpResponse); + HttpGet httpGet = new HttpGet(url); + PowerMock.expectNew(HttpGet.class, url).andReturn(httpGet); + when(HttpsUtils.get(httpGet, headers, httpClient)).thenReturn(httpResponse); when(HttpsUtils.extractResponseEntity(httpResponse)).thenReturn("{}"); PowerMockito.mockStatic(MicroServiceConfig.class); @@ -133,10 +136,12 @@ public class AaiQueryTest { 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"; + String url = "http://10.96.33.33:80/api/aai-cloudInfrastructure/v11"; CloseableHttpClient httpClient = PowerMock.createMock(CloseableHttpClient.class); when(HttpsUtils.getHttpClient(30000)).thenReturn(httpClient); - when(HttpsUtils.get(url, headers, httpClient)).thenThrow(new CorrelationException("")); + HttpGet httpGet = new HttpGet(url); + PowerMock.expectNew(HttpGet.class, url).andReturn(httpGet); + when(HttpsUtils.get(httpGet, headers, httpClient)).thenThrow(new CorrelationException("")); PowerMockito.mockStatic(MicroServiceConfig.class); when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("http://10.96.33.33:80"); PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2") @@ -221,7 +226,9 @@ public class AaiQueryTest { HttpResponse httpResponse = PowerMock.createMock(HttpResponse.class); CloseableHttpClient httpClient = PowerMock.createMock(CloseableHttpClient.class); when(HttpsUtils.getHttpClient(30000)).thenReturn(httpClient); - when(HttpsUtils.get(url, headers, httpClient)).thenReturn(httpResponse); + HttpGet httpGet = new HttpGet(url); + PowerMock.expectNew(HttpGet.class, url).andReturn(httpGet); + when(HttpsUtils.get(httpGet, headers, httpClient)).thenReturn(httpResponse); when(HttpsUtils.extractResponseEntity(httpResponse)).thenReturn(""); PowerMock.expectPrivate(httpClient, "close"); EasyMock.expectLastCall(); @@ -249,7 +256,9 @@ public class AaiQueryTest { String url = "host_url"; CloseableHttpClient httpClient = PowerMock.createMock(CloseableHttpClient.class); when(HttpsUtils.getHttpClient(30000)).thenReturn(httpClient); - when(HttpsUtils.get(url, headers, httpClient)).thenThrow(new CorrelationException("")); + HttpGet httpGet = new HttpGet(url); + PowerMock.expectNew(HttpGet.class, url).andReturn(httpGet); + when(HttpsUtils.get(httpGet, headers, httpClient)).thenThrow(new CorrelationException("")); PowerMock.expectPrivate(httpClient, "close"); EasyMock.expectLastCall(); PowerMock.replayAll(); @@ -284,7 +293,7 @@ public class AaiQueryTest { PowerMock.replayAll(); String actual = Whitebox.invokeMethod(aaiQuery,"getBaseUrl", "/url"); PowerMock.verifyAll(); - assertThat(actual, equalTo("http://10.96.33.33/url")); + assertThat(actual, equalTo("http://10.96.33.33:80/url")); } @Test