package org.onap.holmes.common.aai;
import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.expect;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.easymock.EasyMock;
+import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
private AaiQuery aaiQuery;
private AaiResponseUtil aaiResponseUtil;
+ @BeforeClass
+ static public void before() {
+ System.setProperty("ENABLE_ENCRYPT", "true");
+ }
+
@Test
public void testAaiQuery_getAaiVnfData_ok() throws Exception {
PowerMock.resetAll();
aaiQuery = PowerMock.createPartialMock(AaiQuery.class, "getVmResourceLinks");
aaiResponseUtil = new AaiResponseUtil();
Whitebox.setInternalState(aaiQuery, "aaiResponseUtil", aaiResponseUtil);
- PowerMockito.mockStatic(HttpsUtils.class);
+ PowerMock.mockStatic(HttpsUtils.class);
Map<String, String> 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 = "https://aai.onap/aai/v11/cloud-infrastructure";
+ String url = "https://aai.onap:8443/aai/v11/cloud-infrastructure";
HttpResponse httpResponse = PowerMock.createMock(HttpResponse.class);
CloseableHttpClient httpClient = PowerMock.createMock(CloseableHttpClient.class);
- when(HttpsUtils.getHttpClient(30000)).thenReturn(httpClient);
+ expect(HttpsUtils.getHttpsClient(30000)).andReturn(httpClient);
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("{}");
+ expect(HttpsUtils.get(anyObject(HttpGet.class), anyObject(Map.class),
+ anyObject(CloseableHttpClient.class))).andReturn(httpResponse);
+ expect(HttpsUtils.extractResponseEntity(httpResponse)).andReturn("{}");
PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2")
.andReturn("/aai/v11/cloud-infrastructure");
}
@Test
-
public void testAaiQuery_getAaiVmData_httpsutils_exception() throws Exception {
PowerMock.resetAll();
thrown.expect(CorrelationException.class);
aaiResponseUtil = new AaiResponseUtil();
Whitebox.setInternalState(aaiQuery, "aaiResponseUtil", aaiResponseUtil);
- PowerMockito.mockStatic(HttpsUtils.class);
+ PowerMock.mockStatic(HttpsUtils.class);
Map<String, String> 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 = "https://aai.onap/aai/v11/cloud-infrastructure";
+ String url = "https://aai.onap:8443/aai/v11/cloud-infrastructure";
CloseableHttpClient httpClient = PowerMock.createMock(CloseableHttpClient.class);
- when(HttpsUtils.getHttpClient(30000)).thenReturn(httpClient);
+ EasyMock.expect(HttpsUtils.getHttpsClient(30000)).andReturn(httpClient);
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);
+ EasyMock.expect(HttpsUtils.get(anyObject(HttpGet.class), anyObject(Map.class),
+ anyObject(CloseableHttpClient.class))).andThrow(new CorrelationException(""));
+ PowerMock.mockStatic(MicroServiceConfig.class);
PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2")
.andReturn("/aai/v11/cloud-infrastructure");
PowerMock.expectPrivate(httpClient,"close");
public void testAaiQuery_getResponse_ok() throws Exception {
PowerMock.resetAll();
aaiQuery = new AaiQuery();
- PowerMockito.mockStatic(HttpsUtils.class);
+ PowerMock.mockStatic(HttpsUtils.class);
Map<String, String> headers = new HashMap<>();
headers.put("X-TransactionId", AaiConfig.X_TRANSACTION_ID);
headers.put("X-FromAppId", AaiConfig.X_FROMAPP_ID);
HttpResponse httpResponse = PowerMock.createMock(HttpResponse.class);
CloseableHttpClient httpClient = PowerMock.createMock(CloseableHttpClient.class);
- when(HttpsUtils.getHttpClient(30000)).thenReturn(httpClient);
+ expect(HttpsUtils.getHttpsClient(30000)).andReturn(httpClient);
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("");
+ expect(HttpsUtils.get(anyObject(HttpGet.class), anyObject(Map.class),
+ anyObject(CloseableHttpClient.class))).andReturn(httpResponse);
+ expect(HttpsUtils.extractResponseEntity(httpResponse)).andReturn("");
PowerMock.expectPrivate(httpClient, "close");
EasyMock.expectLastCall();
thrown.expectMessage("Failed to get data from aai");
aaiQuery = new AaiQuery();
- PowerMockito.mockStatic(HttpsUtils.class);
+ PowerMock.mockStatic(HttpsUtils.class);
Map<String, String> headers = new HashMap<>();
headers.put("X-TransactionId", AaiConfig.X_TRANSACTION_ID);
headers.put("X-FromAppId", AaiConfig.X_FROMAPP_ID);
headers.put("Accept", "application/json");
String url = "host_url";
CloseableHttpClient httpClient = PowerMock.createMock(CloseableHttpClient.class);
- when(HttpsUtils.getHttpClient(30000)).thenReturn(httpClient);
+ expect(HttpsUtils.getHttpsClient(30000)).andReturn(httpClient);
HttpGet httpGet = new HttpGet(url);
PowerMock.expectNew(HttpGet.class, url).andReturn(httpGet);
- when(HttpsUtils.get(httpGet, headers, httpClient)).thenThrow(new CorrelationException(""));
+ expect(HttpsUtils.get(httpGet, headers, httpClient)).andThrow(new CorrelationException(""));
PowerMock.expectPrivate(httpClient, "close");
EasyMock.expectLastCall();
PowerMock.replayAll();
String actual = Whitebox.invokeMethod(aaiQuery,"getBaseUrl", "/url");
PowerMock.verifyAll();
- assertThat(actual, equalTo("https://aai.onap/url"));
+ assertThat(actual, equalTo("https://aai.onap:8443/url"));
}
@Test