summaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-common
diff options
context:
space:
mode:
authorMerkel, Jeff <jeff.merkel@att.com>2019-10-31 08:55:57 -0400
committerBenjamin, Max (mb388a) <mb388a@att.com>2019-10-31 08:55:57 -0400
commite2d43da8e26857b36faf57032d668bb5ad5eb10d (patch)
tree454c4d82b92aa5c16f2c7f40b53db12b6ddd5b43 /mso-api-handlers/mso-api-handler-common
parent47cb6260f222c2f0cb0c95a53646e3196a930a8b (diff)
- Skip requestId lookup when uri is
- Skip requestId lookup when uri is orchestrationRequests. - Reformatted code to fix the build error. - Updated mockContext in TC to mock up URI path. - Added a test that skips the requestId lookup. - Added verify to ensure the lookup method is not called. - Fixed the formatting to pass the verify build. Issue-ID: SO-2499 Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com> Change-Id: I12a991032a8cd1b3664cc807fde568f89bf779fa
Diffstat (limited to 'mso-api-handlers/mso-api-handler-common')
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/RequestIdFilter.java20
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java30
2 files changed, 43 insertions, 7 deletions
diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/RequestIdFilter.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/RequestIdFilter.java
index 2fd426dec2..b81ee58aa4 100644
--- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/RequestIdFilter.java
+++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/RequestIdFilter.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import javax.annotation.Priority;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.core.UriInfo;
import javax.ws.rs.ext.Provider;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.onap.so.apihandler.common.ErrorNumbers;
@@ -52,15 +53,20 @@ public class RequestIdFilter implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext context) throws IOException {
String requestId = MDC.get(ONAPLogConstants.MDCs.REQUEST_ID);
+ UriInfo uriInfo = context.getUriInfo();
+ String requestURI = uriInfo.getPath();
- logger.info("Checking if requestId: {} already exists in requestDb InfraActiveRequests table", requestId);
- InfraActiveRequests infraActiveRequests = infraActiveRequestsClient.getInfraActiveRequestbyRequestId(requestId);
+ if (!requestURI.contains("orchestrationRequests")) {
+ logger.info("Checking if requestId: {} already exists in requestDb InfraActiveRequests table", requestId);
+ InfraActiveRequests infraActiveRequests =
+ infraActiveRequestsClient.getInfraActiveRequestbyRequestId(requestId);
- if (infraActiveRequests != null) {
- logger.error(
- "RequestId: {} already exists in RequestDB InfraActiveRequests table, throwing DuplicateRequestIdException",
- requestId);
- throw new DuplicateRequestIdException(createRequestError(requestId, "InfraActiveRequests"));
+ if (infraActiveRequests != null) {
+ logger.error(
+ "RequestId: {} already exists in RequestDB InfraActiveRequests table, throwing DuplicateRequestIdException",
+ requestId);
+ throw new DuplicateRequestIdException(createRequestError(requestId, "InfraActiveRequests"));
+ }
}
}
diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java
index 8716047603..421136d402 100644
--- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java
+++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java
@@ -23,9 +23,13 @@ package org.onap.so.apihandler.filters;
import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
import java.io.IOException;
+import java.net.URI;
import java.util.Collections;
import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.core.UriInfo;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -53,6 +57,9 @@ public class RequestIdFilterTest {
@Mock
private RequestsDbClient requestsDbClient;
+ @Mock
+ private UriInfo uriInfo;
+
@InjectMocks
@Spy
private RequestIdFilter requestIdFilter;
@@ -87,12 +94,35 @@ public class RequestIdFilterTest {
doReturn(infraActiveRequests).when(requestsDbClient).getInfraActiveRequestbyRequestId(requestId);
doReturn(error).when(requestIdFilter).createRequestError(REQUEST_ID, "InfraActiveRequests");
+ doReturn("/onap/so/infra/serviceInstantiation/v7/serviceInstances").when(uriInfo).getPath();
+ doReturn(uriInfo).when(mockContext).getUriInfo();
thrown.expect(DuplicateRequestIdException.class);
thrown.expectMessage("HTTP 400 Bad Request");
+
+
requestIdFilter.filter(mockContext);
}
+
+ @Test
+ public void filterTestInfraSkipRequestIdLookup() throws IOException {
+ String requestId = REQUEST_ID;
+ MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId);
+
+ // ExpectedRecord InfraActiveRequests
+ InfraActiveRequests infraActiveRequests = new InfraActiveRequests();
+ infraActiveRequests.setRequestId(REQUEST_ID);
+
+ doReturn("onap/so/infra/orchestrationRequests/v7/" + REQUEST_ID).when(uriInfo).getPath();
+ doReturn(uriInfo).when(mockContext).getUriInfo();
+
+ verify(requestsDbClient, never()).getInfraActiveRequestbyRequestId(REQUEST_ID);
+
+ requestIdFilter.filter(mockContext);
+ }
+
+
@Test
public void createRequestErrorTest() throws IOException {
RequestError requestError = getRequestError();