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;
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 {
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);
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")
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();
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();
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