diff options
author | Plummer, Brittany <brittany.plummer@att.com> | 2019-06-06 16:02:00 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2019-06-06 16:02:10 -0400 |
commit | 65ca9cb2cc392dcd9793f7758d9d1fd0dd592fb7 (patch) | |
tree | ef7f0fff315a4c9d4b1209a45f2e6da783da6636 | |
parent | c4b90365d5c117bc6fd64af421a1468539a8aec3 (diff) |
resume request support
copy request body rewrite requestorid
added missing curly brace case to regex
Updated how we are updating requestorId in requestBody
Removed unused imports from RequestHandlerUtils
Replaced requestorId in requestBody string
Began updating requestorId in requestBody
Change-Id: I54bd8097b196899b271956f03395bb98d295e1e0
Issue-ID: SO-1990
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
4 files changed, 48 insertions, 12 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 4e910e5382..f88d244a88 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 @@ -52,6 +52,7 @@ import org.onap.so.apihandler.common.RequestClientFactory; import org.onap.so.apihandler.common.RequestClientParameter; import org.onap.so.apihandler.common.ResponseBuilder; import org.onap.so.apihandler.common.ResponseHandler; +import org.onap.so.apihandlerinfra.TestApi; import org.onap.so.apihandlerinfra.exceptions.ApiException; import org.onap.so.apihandlerinfra.exceptions.BPMNFailureException; import org.onap.so.apihandlerinfra.exceptions.ClientConnectionException; @@ -638,7 +639,7 @@ public class RequestHandlerUtils { request.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER); if (infraActiveRequest != null) { request.setTenantId(infraActiveRequest.getTenantId()); - request.setRequestBody(infraActiveRequest.getRequestBody()); + request.setRequestBody(updateRequestorIdInRequestBody(infraActiveRequest, requestorId)); request.setAicCloudRegion(infraActiveRequest.getAicCloudRegion()); request.setRequestScope(infraActiveRequest.getRequestScope()); request.setRequestAction(infraActiveRequest.getRequestAction()); @@ -707,4 +708,10 @@ public class RequestHandlerUtils { } } + protected String updateRequestorIdInRequestBody(InfraActiveRequests infraActiveRequest, String newRequestorId) { + String requestBody = infraActiveRequest.getRequestBody(); + return requestBody.replaceAll( + "(?s)(\"requestInfo\"\\s*?:\\s*?\\{.*?\"requestorId\"\\s*?:\\s*?\")(.*?)(\"[ ]*(?:,|\\R|\\}))", + "$1" + newRequestorId + "$3"); + } } 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 e92417728c..3cb4e0c9c2 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 @@ -114,14 +114,14 @@ public class RequestHandlerUtilsUnitTest { currentActiveRequest.setSource("VID"); currentActiveRequest.setStartTime(startTimeStamp); currentActiveRequest.setTenantId("tenant-id"); - currentActiveRequest.setRequestBody(getRequestBody("/RequestBody.json")); + currentActiveRequest.setRequestBody(getRequestBody("/RequestBodyNewRequestorId.json")); currentActiveRequest.setAicCloudRegion("cloudRegion"); currentActiveRequest.setRequestScope("service"); currentActiveRequest.setRequestStatus(Status.IN_PROGRESS.toString()); currentActiveRequest.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER); currentActiveRequest.setRequestAction(Action.createInstance.toString()); currentActiveRequest.setRequestUrl(requestUri); - currentActiveRequest.setRequestorId("xxxxxx"); + currentActiveRequest.setRequestorId("yyyyyy"); currentActiveRequest.setProgress(new Long(5)); currentActiveRequest.setOriginalRequestId(RESUMED_REQUEST_ID); } @@ -140,10 +140,12 @@ public class RequestHandlerUtilsUnitTest { @Test - public void createNewRecordCopyFromInfraActiveRequestTest() { + public void createNewRecordCopyFromInfraActiveRequestTest() throws IOException { doNothing().when(requestHandler).setInstanceIdAndName(infraActiveRequest, currentActiveRequest); + doReturn(getRequestBody("/RequestBodyNewRequestorId.json")).when(requestHandler) + .updateRequestorIdInRequestBody(infraActiveRequest, "yyyyyy"); InfraActiveRequests result = requestHandler.createNewRecordCopyFromInfraActiveRequest(infraActiveRequest, - CURRENT_REQUEST_ID, startTimeStamp, "VID", requestUri, "xxxxxx", RESUMED_REQUEST_ID); + CURRENT_REQUEST_ID, startTimeStamp, "VID", requestUri, "yyyyyy", RESUMED_REQUEST_ID); assertThat(currentActiveRequest, sameBeanAs(result)); } @@ -396,4 +398,12 @@ public class RequestHandlerUtilsUnitTest { assertEquals(modelTypeResult, modelTypeExpected); } + @Test + public void updateRequestorIdInRequestBodyTest() throws IOException { + String newRequestorId = "yyyyyy"; + String expected = getRequestBody("/RequestBodyNewRequestorId.json"); + String result = requestHandler.updateRequestorIdInRequestBody(infraActiveRequest, newRequestorId); + assertEquals(expected, result); + } + } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/ResumeOrchestrationRequest/RequestBody.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ResumeOrchestrationRequest/RequestBody.json index 7e8ed4dee1..d6406338a0 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/ResumeOrchestrationRequest/RequestBody.json +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ResumeOrchestrationRequest/RequestBody.json @@ -1,5 +1,11 @@ { "requestDetails":{ + "modelInfo":{ + "modelInvariantId": "f7ce78bb-423b-11e7-93f8-0050569a7965", + "modelVersion": "1.0", + "modelType":"service", + "modelName":"serviceModel" + }, "requestInfo":{ "source":"VID", "requestorId":"xxxxxx", @@ -8,12 +14,6 @@ }, "requestParameters":{ "aLaCarte":"false" - }, - "modelInfo":{ - "modelInvariantId": "f7ce78bb-423b-11e7-93f8-0050569a7965", - "modelVersion": "1.0", - "modelType":"service", - "modelName":"serviceModel" - } + } } }
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/ResumeOrchestrationRequest/RequestBodyNewRequestorId.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ResumeOrchestrationRequest/RequestBodyNewRequestorId.json new file mode 100644 index 0000000000..740d4e2ec2 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ResumeOrchestrationRequest/RequestBodyNewRequestorId.json @@ -0,0 +1,19 @@ +{ + "requestDetails":{ + "modelInfo":{ + "modelInvariantId": "f7ce78bb-423b-11e7-93f8-0050569a7965", + "modelVersion": "1.0", + "modelType":"service", + "modelName":"serviceModel" + }, + "requestInfo":{ + "source":"VID", + "requestorId":"yyyyyy", + "instanceName":"testService", + "productFamilyId":"test" + }, + "requestParameters":{ + "aLaCarte":"false" + } + } +}
\ No newline at end of file |