aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2019-07-21 13:56:43 +0300
committerIttay Stern <ittay.stern@att.com>2019-07-21 16:46:53 +0300
commit2161e5d01e6ff0e1460d268371c97792331b0974 (patch)
tree057a0bc5b72c4d990aff5913b632e4605205920c /vid-app-common/src/test/java
parente751654a743922fc2a2d23b27553ad451dba6643 (diff)
Return a value from MsoInterface::setServiceInstanceStatus
This resolves the case where mso_activate_service_instance API is returning an empty object. Issue-ID: VID-267 Change-Id: I691c7ca037c5458ce728bed10bf959e664679b6a Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/test/java')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java39
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java37
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java9
3 files changed, 36 insertions, 49 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
index a7fa8cd13..0efdb6b69 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
@@ -92,7 +92,6 @@ import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import static org.onap.vid.controller.MsoController.CONFIGURATION_ID;
import static org.onap.vid.controller.MsoController.REQUEST_TYPE;
import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
@@ -628,26 +627,6 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
}
@Test(expectedExceptions = MsoTestException.class)
- public void shouldThrowExceptionWhenActivateServiceInstanceWithWrongParameters() {
- //given
- RequestDetails requestDetails = new RequestDetails();
- String taskId = "testTaskId";
-
- RestObject<String> restObjStr = new RestObject<>();
- restObjStr.set("");
- MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(restObjStr);
-
- doThrow(new MsoTestException("testException")).
- when(msoInterface).setServiceInstanceStatus(eq(requestDetails), any(String.class), any(String.class), any(String.class), any(RestObject.class));
-
- //when
- MsoResponseWrapper response = msoBusinessLogic.activateServiceInstance(requestDetails, taskId);
-
- //then
- assertThat(response).isEqualToComparingFieldByField(expectedResponse);
- }
-
- @Test(expectedExceptions = MsoTestException.class)
public void shouldThrowExceptionWhenManualTaskWithWrongParameters() {
//given
RequestDetails requestDetails = new RequestDetails();
@@ -1118,38 +1097,34 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
public void shouldProperlySetServiceInstanceStatusActiveWithProperParameters() {
// given
String serviceInstanceId = "testServiceId";
+ MsoResponseWrapper okResponse = createOkResponse();
org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
- RestObject<String> restObjStr = new RestObject<>();
- restObjStr.set("");
- MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(restObjStr);
+ given(msoInterface.setServiceInstanceStatus(eq(requestDetails), endsWith(serviceInstanceId + "/activate"))).willReturn(okResponse);
// when
MsoResponseWrapper response = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, true);
// then
- assertThat(response).isEqualToComparingFieldByField(expectedResponse);
-
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
}
@Test
public void shouldProperlySetServiceInstanceStatusDeactivateWithProperParameters() {
// given
String serviceInstanceId = "testServiceId";
+ MsoResponseWrapper okResponse = createOkResponse();
org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails();
- RestObject<String> restObjStr = new RestObject<>();
- restObjStr.set("");
- MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(restObjStr);
+ given(msoInterface.setServiceInstanceStatus(eq(requestDetails), endsWith(serviceInstanceId + "/deactivate"))).willReturn(okResponse);
// when
MsoResponseWrapper response = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, false);
// then
- assertThat(response).isEqualToComparingFieldByField(expectedResponse);
-
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
}
@Test(expectedExceptions = MsoTestException.class)
@@ -1158,7 +1133,7 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
String serviceInstanceId = "testServiceId";
doThrow(new MsoTestException("testException")).
- when(msoInterface).setServiceInstanceStatus(eq(null), any(String.class), any(String.class), any(String.class), any(RestObject.class));
+ when(msoInterface).setServiceInstanceStatus(eq(null), any(String.class));
// when
msoBusinessLogic.setServiceInstanceStatus(null, serviceInstanceId, true);
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java
index 832aa098a..d4abfae38 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java
@@ -20,11 +20,19 @@
*/
package org.onap.vid.mso.rest;
+import static org.apache.commons.io.IOUtils.toInputStream;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xebialabs.restito.server.StubServer;
+import io.joshworks.restclient.http.HttpResponse;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
@@ -413,20 +421,29 @@ public class MsoRestClientNewTest {
}
@Test
- public void testSetServiceInstanceStatus() throws Exception {
- MsoRestClientNew testSubject;
- RequestDetails requestDetails = null;
+ public void testSetServiceInstanceStatus_givenValidResponse_responseIsPopulatedAccordingly() {
+ RequestDetails requestDetails = new RequestDetails();
String t = "";
String sourceId = "";
String endpoint = "";
- RestObject<String> restObject = null;
+ final SyncRestClient client = mock(SyncRestClient.class);
+ MsoRestClientNew testSubject = new MsoRestClientNew(client, "", null, new SystemPropertiesWrapper());
- // default test
- try {
- testSubject = createTestSubject();
- testSubject.setServiceInstanceStatus(requestDetails, t, sourceId, endpoint, restObject);
- } catch (Exception e) {
- }
+ // setup
+ final HttpResponse<String> response = mock(HttpResponse.class);
+ final int expectedStatus = 202;
+ final String expectedResponse = "expected response";
+
+ when(client.post(eq(endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(response);
+ when(response.getStatus()).thenReturn(expectedStatus);
+ when(response.getBody()).thenReturn(expectedResponse);
+ when(response.getRawBody()).thenReturn(toInputStream(expectedResponse));
+
+ // test
+ MsoResponseWrapper responseWrapper = testSubject.setServiceInstanceStatus(requestDetails, endpoint);
+
+ assertThat(responseWrapper.getStatus(), is(expectedStatus));
+ assertThat(responseWrapper.getEntity(), is(expectedResponse));
}
@Test
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
index 050fa0dce..8ea4836a2 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
@@ -35,11 +35,9 @@ import org.apache.http.ProtocolVersion;
import org.apache.http.StatusLine;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.message.BasicStatusLine;
-import org.jetbrains.annotations.NotNull;
import org.mockito.Mock;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.changeManagement.RequestDetailsWrapper;
-import org.onap.vid.changeManagement.RequestParameters;
import org.onap.vid.changeManagement.WorkflowRequestDetail;
import org.onap.vid.client.SyncRestClient;
import org.onap.vid.controller.LocalWebConfig;
@@ -49,7 +47,6 @@ import org.onap.vid.mso.MsoResponseWrapper;
import org.onap.vid.mso.MsoResponseWrapperInterface;
import org.onap.vid.mso.MsoUtil;
import org.onap.vid.mso.RestObject;
-import org.onap.vid.mso.model.CloudConfiguration;
import org.onap.vid.mso.model.RequestReferences;
import org.onap.vid.utils.SystemPropertiesWrapper;
import org.springframework.test.context.ContextConfiguration;
@@ -57,9 +54,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -664,7 +659,7 @@ public class MsoRestClientTest {
when(client.post(eq(baseUrl + endpoint), anyMap(), eq(requestDetails), eq(String.class))).thenReturn(httpResponse);
// when
- restClient.setServiceInstanceStatus(requestDetails,"", "", endpoint, restObject);
+ restClient.setServiceInstanceStatus(requestDetails, endpoint);
}
@Test( expectedExceptions = MsoTestException.class)
@@ -675,7 +670,7 @@ public class MsoRestClientTest {
when(client.post(eq(baseUrl), anyMap(), eq(null), eq(String.class))).thenThrow(new MsoTestException("test-post-exception"));
// when
- restClient.setServiceInstanceStatus(null,"", "", endpoint, null);
+ restClient.setServiceInstanceStatus(null, endpoint);
}
@Test