diff options
Diffstat (limited to 'mso-api-handlers')
2 files changed, 131 insertions, 10 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java index e14b01792a..b4a3128de8 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java @@ -94,8 +94,8 @@ public class OrchestrationRequests { @Produces(MediaType.APPLICATION_JSON) @Transactional public Response getOrchestrationRequest(@PathParam("requestId") String requestId, - @PathParam("version") String version, @QueryParam("includeCloudRequest") boolean includeCloudRequest) - throws ApiException { + @PathParam("version") String version, @QueryParam("includeCloudRequest") boolean includeCloudRequest, + @QueryParam("extSystemErrorSource") boolean extSystemErrorSource) throws ApiException { String apiVersion = version.substring(1); GetOrchestrationResponse orchestrationResponse = new GetOrchestrationResponse(); @@ -142,7 +142,8 @@ public class OrchestrationRequests { throw validateException; } - Request request = mapInfraActiveRequestToRequest(infraActiveRequest, includeCloudRequest); + Request request = mapInfraActiveRequestToRequest(infraActiveRequest, includeCloudRequest, extSystemErrorSource); + if (!requestProcessingData.isEmpty()) { request.setRequestProcessingData(mapRequestProcessingData(requestProcessingData)); } @@ -158,7 +159,8 @@ public class OrchestrationRequests { @Produces(MediaType.APPLICATION_JSON) @Transactional public Response getOrchestrationRequest(@Context UriInfo ui, @PathParam("version") String version, - @QueryParam("includeCloudRequest") boolean includeCloudRequest) throws ApiException { + @QueryParam("includeCloudRequest") boolean includeCloudRequest, + @QueryParam("extSystemErrorSource") boolean extSystemErrorSource) throws ApiException { long startTime = System.currentTimeMillis(); @@ -195,7 +197,8 @@ public class OrchestrationRequests { List<RequestProcessingData> requestProcessingData = requestsDbClient.getRequestProcessingDataBySoRequestId(infraActive.getRequestId()); RequestList requestList = new RequestList(); - Request request = mapInfraActiveRequestToRequest(infraActive, includeCloudRequest); + Request request = mapInfraActiveRequestToRequest(infraActive, includeCloudRequest, extSystemErrorSource); + if (!requestProcessingData.isEmpty()) { request.setRequestProcessingData(mapRequestProcessingData(requestProcessingData)); } @@ -290,8 +293,8 @@ public class OrchestrationRequests { return Response.status(HttpStatus.SC_NO_CONTENT).entity("").build(); } - protected Request mapInfraActiveRequestToRequest(InfraActiveRequests iar, boolean includeCloudRequest) - throws ApiException { + protected Request mapInfraActiveRequestToRequest(InfraActiveRequests iar, boolean includeCloudRequest, + boolean extSystemErrorSource) throws ApiException { String requestBody = iar.getRequestBody(); Request request = new Request(); @@ -427,10 +430,19 @@ public class OrchestrationRequests { }); } + mapExtSystemErrorSourceToRequest(iar, status, extSystemErrorSource); + request.setRequestStatus(status); return request; } + protected void mapExtSystemErrorSourceToRequest(InfraActiveRequests iar, RequestStatus status, + boolean extSystemErrorSource) { + if (extSystemErrorSource) { + status.setExtSystemErrorSource(iar.getExtSystemErrorSource()); + } + } + public List<org.onap.so.serviceinstancebeans.RequestProcessingData> mapRequestProcessingData( List<org.onap.so.db.request.beans.RequestProcessingData> processingData) { List<org.onap.so.serviceinstancebeans.RequestProcessingData> addedRequestProcessingData = new ArrayList<>(); 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))); + } } |