use of org.codice.ddf.platform.filter.http.HttpFilter in project ddf by codice.
the class DelegatingHttpFilterHandlerTest method mockHttpFilter.
private HttpFilter mockHttpFilter() throws Exception {
HttpFilter mockFilter = mock(HttpFilter.class);
doAnswer(invocationOnMock -> {
HttpServletRequest request = invocationOnMock.getArgument(0);
HttpServletResponse response = invocationOnMock.getArgument(1);
HttpFilterChain filterChain = invocationOnMock.getArgument(2);
filterChain.doFilter(request, response);
return null;
}).when(mockFilter).doFilter(any(), any(), any());
return mockFilter;
}
use of org.codice.ddf.platform.filter.http.HttpFilter in project ddf by codice.
the class ProxyHttpFilterChain method doFilter.
@Override
public void doFilter(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (iterator.hasNext()) {
HttpFilter filter = iterator.next();
LOGGER.debug("Calling filter {}.doFilter({}, {}, {}, {}, {})", filter.getClass().getName(), target, baseRequest, request, response, this);
filter.doFilter(request, response, this);
} else {
handler.handle(target, baseRequest, request, response);
}
}
use of org.codice.ddf.platform.filter.http.HttpFilter in project ddf by codice.
the class DelegatingHttpFilterHandlerTest method testDelegatingHttpFilterHandler.
@Test
public void testDelegatingHttpFilterHandler() throws Exception {
Request mockBaseRequest = mock(Request.class);
HttpServletRequest mockRequest = mock(HttpServletRequest.class);
HttpServletResponse mockResponse = mock(HttpServletResponse.class);
HttpFilter mockFilter = mockHttpFilter();
ServiceReference<HttpFilter> mockServiceReference = mock(ServiceReference.class);
BundleContext mockBundleContext = mock(BundleContext.class);
when(mockBundleContext.getServiceReferences(any(Class.class), anyString())).thenReturn(Collections.singletonList(mockServiceReference));
when(mockBundleContext.getService(mockServiceReference)).thenReturn(mockFilter);
Handler handler = mock(Handler.class);
DelegatingHttpFilterHandler underTest = new DelegatingHttpFilterHandler(mockBundleContext);
underTest.setHandler(handler);
underTest.handle("/", mockBaseRequest, mockRequest, mockResponse);
verify(mockFilter).doFilter(any(), any(), any());
verify(handler).handle("/", mockBaseRequest, mockRequest, mockResponse);
}
use of org.codice.ddf.platform.filter.http.HttpFilter in project ddf by codice.
the class DelegatingHttpFilterHandlerTest method testDelegatingHttpFilterHandlerWithServiceRanking.
@Test
public void testDelegatingHttpFilterHandlerWithServiceRanking() throws Exception {
Request mockBaseRequest = mock(Request.class);
HttpServletRequest mockRequest = mock(HttpServletRequest.class);
HttpServletResponse mockResponse = mock(HttpServletResponse.class);
HttpFilter filter1 = mockHttpFilter();
HttpFilter filter2 = mockHttpFilter();
HttpFilter filter3 = mockHttpFilter();
ServiceReference<HttpFilter> reference1 = mock(ServiceReference.class);
ServiceReference<HttpFilter> reference2 = mock(ServiceReference.class);
ServiceReference<HttpFilter> reference3 = mock(ServiceReference.class);
rankServiceReferences(reference1, reference2, reference3);
BundleContext mockBundleContext = mock(BundleContext.class);
when(mockBundleContext.getService(reference1)).thenReturn(filter1);
when(mockBundleContext.getService(reference2)).thenReturn(filter2);
when(mockBundleContext.getService(reference3)).thenReturn(filter3);
when(mockBundleContext.getServiceReferences(any(Class.class), anyString())).thenReturn(Arrays.asList(reference2, reference3, reference1));
Handler handler = mock(Handler.class);
DelegatingHttpFilterHandler underTest = new DelegatingHttpFilterHandler(mockBundleContext);
underTest.setHandler(handler);
underTest.handle("/", mockBaseRequest, mockRequest, mockResponse);
InOrder inOrder = Mockito.inOrder(filter1, filter2, filter3);
inOrder.verify(filter1).doFilter(any(), any(), any());
inOrder.verify(filter2).doFilter(any(), any(), any());
inOrder.verify(filter3).doFilter(any(), any(), any());
inOrder.verifyNoMoreInteractions();
}
Aggregations