From 56c336c78cd48928f1a8741a212c06bb17aeaf5f Mon Sep 17 00:00:00 2001 From: Alok Joshi <AJoshi19@slb.com> Date: Thu, 16 Feb 2023 09:28:01 -0600 Subject: [PATCH] unit tests --- .../storage/util/CollaborationFilterTest.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/util/CollaborationFilterTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/util/CollaborationFilterTest.java index f928753f0..39ba11271 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/util/CollaborationFilterTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/util/CollaborationFilterTest.java @@ -18,6 +18,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; @@ -48,17 +49,16 @@ public class CollaborationFilterTest { @Before public void setup() { initMocks(this); - } @Test public void shouldThrowException_ifCollaborationHeaderProvided_whenCollaborationFeatureFlagDisabled() throws IOException, ServletException { when(httpServletRequest.getHeader(DATA_PARTITION_ID)).thenReturn(DATA_PARTITION); + when(httpServletRequest.getRequestURI()).thenReturn("https://my-service-url"); when(iCollaborationFeatureFlag.isFeatureEnabled(FEATURE_NAME)).thenReturn(false); when(httpServletRequest.getHeader(X_COLLABORATION_HEADER_NAME)).thenReturn(COLLABORATION_DIRECTIVES); when(httpServletResponse.getWriter()).thenReturn(writer); - collaborationFilter.doFilter(httpServletRequest, httpServletResponse, filterChain); verify(httpServletResponse).setContentType("application/json"); @@ -66,4 +66,28 @@ public class CollaborationFilterTest { AppError errorResponse = new AppError(HttpStatus.SC_LOCKED, "Locked", "Feature is not enabled on this environment"); verify(writer).write(CollaborationFilter.appErrorToJson(errorResponse)); } + + @Test + public void shouldSkipFilter_ifUrlContainsHealthEndpoint() { + when(httpServletRequest.getRequestURI()).thenReturn("https://my-service-url/api/storage/v2/health"); + verify(iCollaborationFeatureFlag, never()).isFeatureEnabled(FEATURE_NAME); + } + + @Test + public void shouldSkipFilter_ifUrlContainsInfoEndpoint() { + when(httpServletRequest.getRequestURI()).thenReturn("https://my-service-url/api/storage/v2/info"); + verify(iCollaborationFeatureFlag, never()).isFeatureEnabled(FEATURE_NAME); + } + + @Test + public void shouldSkipFilter_ifUrlContainsSwaggerEndpoint() { + when(httpServletRequest.getRequestURI()).thenReturn("https://my-service-url/api/storage/v2/swagger-ui/index.html"); + verify(iCollaborationFeatureFlag, never()).isFeatureEnabled(FEATURE_NAME); + } + + @Test + public void shouldSkipFilter_ifUrlContainsApiDocsEndpoint() { + when(httpServletRequest.getRequestURI()).thenReturn("https://my-service-url/api/storage/v2/v3/api-docs"); + verify(iCollaborationFeatureFlag, never()).isFeatureEnabled(FEATURE_NAME); + } } -- GitLab