aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/test
diff options
context:
space:
mode:
authorChan, Mercy <merce.chan@att.com>2019-06-18 17:44:22 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-06-18 17:44:28 -0400
commit0c1dd50e1fe778e6d2463dc490259cae9c48a0e7 (patch)
treebda752966e387ccb5e4a5b1ae811edbf7ee1dbc3 /mso-api-handlers/mso-api-handler-infra/src/test
parent7c69f07593a8c7474bd7a69a65979dc0635f1526 (diff)
update apih to accept new uri parameter
added extSystemErrorSource queryparam flag to getOrchestrationRequest endpoint. added junit tests for the protected method that maps external system error source to request object being returned. added junit tests to test mapExtSystemErrorSourceToRequest method with extSystemErrorSource flag Change-Id: If5c9a41938d4cc922c26f7d64e3a839b6547556f Issue-ID: SO-2035 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/test')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java115
1 files changed, 112 insertions, 3 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java
index 19b9d7ea1e..a400caeae2 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java
@@ -21,21 +21,51 @@
package org.onap.so.apihandlerinfra;
import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import javax.ws.rs.core.Response;
+import org.apache.http.HttpStatus;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.apihandler.common.ResponseBuilder;
import org.onap.so.apihandlerinfra.exceptions.ApiException;
import org.onap.so.db.request.beans.InfraActiveRequests;
+import org.onap.so.db.request.client.RequestsDbClient;
import org.onap.so.serviceinstancebeans.InstanceReferences;
import org.onap.so.serviceinstancebeans.Request;
import org.onap.so.serviceinstancebeans.RequestStatus;
@RunWith(MockitoJUnitRunner.class)
public class OrchestrationRequestsUnitTest {
-
+ @Mock
+ private RequestsDbClient requestDbClient;
+ @Mock
+ private MsoRequest msoRequest;
+ @Mock
+ private ResponseBuilder builder;
+ @Mock
+ private Response response;
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+ @InjectMocks
@Spy
private OrchestrationRequests orchestrationRequests;
@@ -43,8 +73,21 @@ public class OrchestrationRequestsUnitTest {
private static final String SERVICE_INSTANCE_ID = "7cb9aa56-dd31-41e5-828e-d93027d4ebbb";
private static final String ORIGINAL_REQUEST_ID = "8f2d38a6-7c20-465a-bd7e-075645f1394b";
private static final String SERVICE = "service";
+ private static final String EXT_SYSTEM_ERROR_SOURCE = "external system error source";
private InfraActiveRequests iar;
boolean includeCloudRequest = false;
+ boolean extSystemErrorSource = false;
+ private static final String SERVICE_INSTANCE_NAME = "serviceInstanceName";
+ private static final String VNF_ID = "00032ab7-na18-42e5-965d-8ea592502017";
+ private static final String VFMODULE_ID = "00032ab7-na18-42e5-965d-8ea592502016";
+ private static final String NETWORK_ID = "00032ab7-na18-42e5-965d-8ea592502015";
+ private static final String VOLUME_GROUP_ID = "00032ab7-na18-42e5-965d-8ea592502014";
+ private static final String VNF_NAME = "vnfName";
+ private static final String VFMODULE_NAME = "vfModuleName";
+ private static final String NETWORK_NAME = "networkName";
+ private static final String VOLUME_GROUP_NAME = "volumeGroupName";
+ private static final String VERSION = "v7";
+ List<org.onap.so.db.request.beans.RequestProcessingData> requestProcessingData = new ArrayList<>();
@Before
public void setup() {
@@ -52,6 +95,12 @@ public class OrchestrationRequestsUnitTest {
iar.setRequestScope(SERVICE);
iar.setRequestId(REQUEST_ID);
iar.setServiceInstanceId(SERVICE_INSTANCE_ID);
+ when(requestDbClient.getInfraActiveRequestbyRequestId(Mockito.eq(REQUEST_ID))).thenReturn(iar);
+ when(requestDbClient.getRequestProcessingDataBySoRequestId(Mockito.eq(REQUEST_ID)))
+ .thenReturn(requestProcessingData);
+
+ when(builder.buildResponse(Mockito.eq(HttpStatus.SC_OK), Mockito.eq(REQUEST_ID), any(Object.class),
+ any(String.class))).thenReturn(response);
}
@Test
@@ -68,7 +117,8 @@ public class OrchestrationRequestsUnitTest {
iar.setOriginalRequestId(ORIGINAL_REQUEST_ID);
- Request result = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest);
+ Request result =
+ orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, extSystemErrorSource);
assertThat(result, sameBeanAs(expected));
}
@@ -83,8 +133,67 @@ public class OrchestrationRequestsUnitTest {
expected.setRequestStatus(requestStatus);
expected.setRequestScope(SERVICE);
- Request result = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest);
+ Request result =
+ orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, extSystemErrorSource);
assertThat(result, sameBeanAs(expected));
}
+ @Test
+ public void mapExtSystemErrorSourceToRequestFalseTest() throws ApiException {
+ InstanceReferences instanceReferences = new InstanceReferences();
+ instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID);
+ RequestStatus requestStatus = new RequestStatus();
+
+ Request expected = new Request();
+ expected.setRequestId(REQUEST_ID);
+ expected.setInstanceReferences(instanceReferences);
+ expected.setRequestStatus(requestStatus);
+ expected.setRequestScope(SERVICE);
+
+ extSystemErrorSource = false;
+ includeCloudRequest = false;
+
+ Request actual =
+ orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, extSystemErrorSource);
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+ @Test
+ public void mapExtSystemErrorSourceToRequestTrueTest() throws ApiException {
+ InstanceReferences instanceReferences = new InstanceReferences();
+ instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID);
+ RequestStatus requestStatus = new RequestStatus();
+ requestStatus.setExtSystemErrorSource(EXT_SYSTEM_ERROR_SOURCE);
+
+ Request expected = new Request();
+ expected.setRequestId(REQUEST_ID);
+ expected.setInstanceReferences(instanceReferences);
+ expected.setRequestStatus(requestStatus);
+ expected.setRequestScope(SERVICE);
+
+ extSystemErrorSource = true;
+ includeCloudRequest = false;
+ iar.setExtSystemErrorSource(EXT_SYSTEM_ERROR_SOURCE);
+
+ Request actual =
+ orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, extSystemErrorSource);
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+ @Test
+ public void mapExtSystemErrorSourceToRequestMethodInvokedTest() throws ApiException, IOException {
+ extSystemErrorSource = true;
+ includeCloudRequest = false;
+ orchestrationRequests.getOrchestrationRequest(REQUEST_ID, VERSION, includeCloudRequest, extSystemErrorSource);
+
+ verify(orchestrationRequests, times(1)).mapExtSystemErrorSourceToRequest(Mockito.eq(iar), Mockito.any(),
+ Mockito.eq(extSystemErrorSource));
+ }
+
+ @Test
+ public void requestStatusExtSystemErrorSourceTest() {
+ RequestStatus requestStatus = new RequestStatus();
+ requestStatus.setExtSystemErrorSource(EXT_SYSTEM_ERROR_SOURCE);
+ assertThat(requestStatus.getExtSystemErrorSource(), is(equalTo(EXT_SYSTEM_ERROR_SOURCE)));
+ }
}