Skip to content
Snippets Groups Projects
Commit a734da82 authored by Alok Joshi's avatar Alok Joshi Committed by David Diederich
Browse files

unit tests

(cherry picked from commit 56c336c7)
parent 0ec487b0
No related branches found
No related tags found
2 merge requests!680Merge branch 'aws-integration-eks' into 'master',!629Cherry-pick 'Bypass info and swagger apis in collaboration filter' into release/0.19
......@@ -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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment