use of javax.servlet.FilterChain in project gocd by gocd.
the class FlashLoadingFilterIntegrationTest method shouldLoadExistingFlashFromSession.
@Test
public void shouldLoadExistingFlashFromSession() throws IOException, ServletException {
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpSession session = new MockHttpSession();
FlashMessageService.Flash oldFlash = new FlashMessageService.Flash();
oldFlash.put("my_key", new FlashMessageModel("my other message", "warning"));
session.putValue(FlashLoadingFilter.FLASH_SESSION_KEY, oldFlash);
req.setSession(session);
MockHttpServletResponse res = new MockHttpServletResponse();
FilterChain filterChain = new MockFilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) {
flash = service.get("my_key");
}
};
filter.doFilter(req, res, filterChain);
assertThat(flash.toString(), is("my other message"));
assertThat(flash.getFlashClass(), is("warning"));
}
use of javax.servlet.FilterChain in project gocd by gocd.
the class FlashLoadingFilterIntegrationTest method shouldClearThreadContext.
@Test
public void shouldClearThreadContext() throws IOException, ServletException {
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpServletResponse res = new MockHttpServletResponse();
FilterChain filterChain = new MockFilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) {
messageKey = service.add(new FlashMessageModel("my message", "error"));
flash = service.get(messageKey);
}
};
filter.doFilter(req, res, filterChain);
assertThat(flash.toString(), is("my message"));
try {
service.get(messageKey);
fail("attempt to load flash message should fail, as no thread local is cleared out");
} catch (Exception e) {
assertThat(e.getMessage(), is("No flash context found, this call should only be made within a request."));
}
}
use of javax.servlet.FilterChain in project gocd by gocd.
the class LocaleResolverTest method shouldSetLocaleStringToCurrentThread.
@Test
public void shouldSetLocaleStringToCurrentThread() throws IOException, ServletException {
when(req.getLocale()).thenReturn(new Locale("ja"));
CurrentLocale.setLocaleString("en");
localeResolver.doFilter(req, res, new FilterChain() {
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {
localeInside = CurrentLocale.getLocaleString();
}
});
assertThat(CurrentLocale.getLocaleString(), is("en"));
assertThat(localeInside, is("ja"));
}
use of javax.servlet.FilterChain in project gocd by gocd.
the class LocaleResolverTest method shouldFixThreadLocaleEvenIfFilterFails.
@Test
public void shouldFixThreadLocaleEvenIfFilterFails() throws IOException, ServletException {
when(req.getLocale()).thenReturn(new Locale("ja"));
CurrentLocale.setLocaleString("en");
final RuntimeException exception = new RuntimeException("Oh no!");
try {
localeResolver.doFilter(req, res, new FilterChain() {
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {
throw exception;
}
});
fail("exception should have been bubbled up");
} catch (RuntimeException e) {
assertThat(e, sameInstance(exception));
}
assertThat(CurrentLocale.getLocaleString(), is("en"));
}
use of javax.servlet.FilterChain in project simba-os by cegeka.
the class DoFilterAndSetPrincipalActionTest method testExecute_withPrincipal.
@Test
public void testExecute_withPrincipal() throws Exception {
FilterChain filterChain = mock(FilterChain.class);
ActionDescriptor actionDescriptor = new ActionDescriptor(new HashSet<ActionType>(), new HashMap<String, String>(), null, null, null, null);
actionDescriptor.getActionTypes().add(ActionType.DO_FILTER_AND_SET_PRINCIPAL);
actionDescriptor.setPrincipal("principal");
DoFilterAndSetPrincipalAction action = new DoFilterAndSetPrincipalAction(actionDescriptor);
action.setRequest(request);
action.setResponse(response);
action.setFilterChain(filterChain);
action.execute();
verify(filterChain).doFilter(any(HttpServletRequestWithPrincipal.class), any(HttpServletResponse.class));
}
Aggregations