use of javax.servlet.ServletResponse in project sling by apache.
the class LogTracerTest method noTurboFilterRegisteredUnlessTracingRequested.
@Test
public void noTurboFilterRegisteredUnlessTracingRequested() throws Exception {
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
activateTracer();
FilterChain chain = new FilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
assertNull(context.getService(TurboFilter.class));
}
};
Filter filter = getFilter(false);
filter.doFilter(request, response, chain);
}
use of javax.servlet.ServletResponse in project ddf by codice.
the class LoginFilterTest method testBadSubject.
/**
* Test with a bad subject - shouldn't call the filter chain, just returns.
*
* @throws IOException
* @throws ServletException
*/
@Test
public void testBadSubject() throws IOException, ServletException {
FilterConfig filterConfig = mock(FilterConfig.class);
LoginFilter loginFilter = new LoginFilter();
loginFilter.setSessionFactory(sessionFactory);
try {
loginFilter.init(filterConfig);
} catch (ServletException e) {
fail(e.getMessage());
}
HttpServletRequest servletRequest = new TestHttpServletRequest();
servletRequest.setAttribute("ddf.security.securityToken", mock(SecurityToken.class));
HttpServletResponse servletResponse = mock(HttpServletResponse.class);
FilterChain filterChain = new FilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
fail("Should not have continued down the filter chain without a valid Subject");
}
};
loginFilter.doFilter(servletRequest, servletResponse, filterChain);
}
use of javax.servlet.ServletResponse in project ddf by codice.
the class DelegateServletFilterTest method testDoFilterWithFilters.
/**
* Tests the main logic of performing the filter with adding filters.
*
* @throws ServletException
* @throws IOException
* @throws InvalidSyntaxException
*/
@Test
public void testDoFilterWithFilters() throws IOException, ServletException, InvalidSyntaxException {
ServletRequest request = mock(HttpServletRequest.class);
ServletResponse response = mock(HttpServletResponse.class);
final BundleContext context = createMockContext(true);
DelegateServletFilter filter = new DelegateServletFilter() {
@Override
protected BundleContext getContext() {
return context;
}
};
filter.doFilter(request, response, initialChain);
verifyFiltersCalled(request, response, initialChain);
}
use of javax.servlet.ServletResponse in project ddf by codice.
the class ProxyFilterChainTest method testDoFilter.
/**
* Tests that all of the filters are properly called.
*
* @throws ServletException
* @throws IOException
*/
@Test
public void testDoFilter() throws IOException, ServletException {
FilterChain initialChain = mock(FilterChain.class);
ProxyFilterChain proxyChain = new ProxyFilterChain(initialChain);
Filter filter1 = createMockFilter("filter1");
Filter filter2 = createMockFilter("filter2");
Filter filter3 = createMockFilter("filter3");
ServletRequest request = mock(ServletRequest.class);
ServletResponse response = mock(ServletResponse.class);
proxyChain.addFilter(filter1);
proxyChain.addFilters(Arrays.asList(filter2, filter3));
proxyChain.doFilter(request, response);
// Verify that all of the filters were called once.
verify(filter1).doFilter(request, response, proxyChain);
verify(filter2).doFilter(request, response, proxyChain);
verify(filter3).doFilter(request, response, proxyChain);
// the initial chain should have also been called once (at the end).
verify(initialChain).doFilter(request, response);
}
use of javax.servlet.ServletResponse in project ddf by codice.
the class ProxyFilterChainTest method createMockFilter.
private Filter createMockFilter(final String name) throws IOException, ServletException {
Filter mockFilter = mock(Filter.class);
Mockito.when(mockFilter.toString()).thenReturn(name);
Mockito.doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
LOGGER.debug("{} was called.", name);
((FilterChain) args[2]).doFilter(((ServletRequest) args[0]), ((ServletResponse) args[1]));
return null;
}
}).when(mockFilter).doFilter(any(ServletRequest.class), any(ServletResponse.class), any(FilterChain.class));
return mockFilter;
}
Aggregations