diff options
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src')
3 files changed, 47 insertions, 36 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java index e2cee43812..557ae6c619 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java @@ -306,6 +306,22 @@ public class RequestHandlerUtils extends AbstractRestHandler { return requestUri; } + public void checkForDuplicateRequests(Actions action, HashMap<String, String> instanceIdMap, String requestScope, + InfraActiveRequests currentActiveReq, String instanceName) throws ApiException { + InfraActiveRequests dup = null; + boolean inProgress = false; + + dup = duplicateCheck(action, instanceIdMap, instanceName, requestScope, currentActiveReq); + + if (dup != null) { + inProgress = camundaHistoryCheck(dup, currentActiveReq); + } + + if (dup != null && inProgress) { + buildErrorOnDuplicateRecord(currentActiveReq, action, instanceIdMap, instanceName, requestScope, dup); + } + } + public InfraActiveRequests duplicateCheck(Actions action, HashMap<String, String> instanceIdMap, String instanceName, String requestScope, InfraActiveRequests currentActiveReq) throws ApiException { InfraActiveRequests dup = null; diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java index 91c62180fc..bb5013085b 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java @@ -846,19 +846,9 @@ public class ServiceInstances extends AbstractRestHandler { currentActiveReq.setNetworkType(networkType); } - InfraActiveRequests dup = null; - boolean inProgress = false; - - dup = requestHandlerUtils.duplicateCheck(action, instanceIdMap, instanceName, requestScope, currentActiveReq); - - if (dup != null) { - inProgress = requestHandlerUtils.camundaHistoryCheck(dup, currentActiveReq); - } + requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, + instanceName); - if (dup != null && inProgress) { - requestHandlerUtils.buildErrorOnDuplicateRecord(currentActiveReq, action, instanceIdMap, instanceName, - requestScope, dup); - } ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse(); RequestReferences referencesResponse = new RequestReferences(); @@ -1006,18 +996,7 @@ public class ServiceInstances extends AbstractRestHandler { throw validateException; } - InfraActiveRequests dup = - requestHandlerUtils.duplicateCheck(action, instanceIdMap, null, requestScope, currentActiveReq); - boolean inProgress = false; - - if (dup != null) { - inProgress = requestHandlerUtils.camundaHistoryCheck(dup, currentActiveReq); - } - - if (dup != null && inProgress) { - requestHandlerUtils.buildErrorOnDuplicateRecord(currentActiveReq, action, instanceIdMap, null, requestScope, - dup); - } + requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, null); ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse(); @@ -1077,18 +1056,8 @@ public class ServiceInstances extends AbstractRestHandler { requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap); String instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName(); - InfraActiveRequests dup = null; - - dup = requestHandlerUtils.duplicateCheck(action, instanceIdMap, instanceName, requestScope, currentActiveReq); - - if (dup != null) { - inProgress = requestHandlerUtils.camundaHistoryCheck(dup, currentActiveReq); - } - - if (instanceIdMap != null && dup != null && inProgress) { - requestHandlerUtils.buildErrorOnDuplicateRecord(currentActiveReq, action, instanceIdMap, instanceName, - requestScope, dup); - } + requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, + instanceName); ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse(); RequestReferences referencesResponse = new RequestReferences(); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsUnitTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsUnitTest.java index d4b0c3aad1..d0b16cffe6 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsUnitTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsUnitTest.java @@ -25,10 +25,12 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.sql.Timestamp; +import java.util.HashMap; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -441,4 +443,28 @@ public class RequestHandlerUtilsUnitTest { assertEquals(expected, result); } + @Test + public void checkForDuplicateRequestsTest() throws ApiException { + InfraActiveRequests currentActiveReq = new InfraActiveRequests(); + currentActiveReq.setAicCloudRegion("testRegion"); + currentActiveReq.setRequestId("792a3158-d9a3-49fd-b3ac-ab09842d6a1a"); + Action action = Action.createInstance; + String requestScope = ModelType.service.toString(); + + InfraActiveRequests duplicate = new InfraActiveRequests(); + + HashMap<String, String> instanceIdMap = new HashMap<String, String>(); + String instanceName = "instanceName"; + + doReturn(duplicate).when(requestHandler).duplicateCheck(action, instanceIdMap, instanceName, requestScope, + currentActiveReq); + doReturn(true).when(requestHandler).camundaHistoryCheck(duplicate, currentActiveReq); + doNothing().when(requestHandler).buildErrorOnDuplicateRecord(currentActiveReq, action, instanceIdMap, + instanceName, requestScope, duplicate); + + requestHandler.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, instanceName); + verify(requestHandler).buildErrorOnDuplicateRecord(currentActiveReq, action, instanceIdMap, instanceName, + requestScope, duplicate); + } + } |