use of com.thoughtworks.go.presentation.FlashMessageModel in project gocd by gocd.
the class FlashLoadingFilterIntegrationTest method shouldInitializeFlashIfNotPresent.
@Test
public void shouldInitializeFlashIfNotPresent() 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);
}
};
assertThat(messageKey, is(nullValue()));
filter.doFilter(req, res, filterChain);
assertThat(messageKey, not(nullValue()));
assertThat(flash.toString(), is("my message"));
assertThat(flash.getFlashClass(), is("error"));
}
use of com.thoughtworks.go.presentation.FlashMessageModel in project gocd by gocd.
the class FlashLoadingFilterIntegrationTest method shouldClearThreadContextInCaseOfExceptionAsWell.
@Test
public void shouldClearThreadContextInCaseOfExceptionAsWell() 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);
throw new RuntimeException("exception here");
}
};
try {
filter.doFilter(req, res, filterChain);
fail("exception gobbled");
} catch (Exception e) {
assertThat(e.getMessage(), is("exception here"));
}
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 (RuntimeException e) {
assertThat(e.getMessage(), is("No flash context found, this call should only be made within a request."));
}
}
use of com.thoughtworks.go.presentation.FlashMessageModel in project gocd by gocd.
the class FlashLoadingFilterTest method shouldClearThreadContextInCaseOfExceptionAsWell.
@Test
public void shouldClearThreadContextInCaseOfExceptionAsWell() 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);
throw new RuntimeException("exception here");
}
};
try {
filter.doFilter(req, res, filterChain);
fail("exception gobbled");
} catch (Exception e) {
assertThat(e.getMessage(), is("exception here"));
}
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 (RuntimeException e) {
assertThat(e.getMessage(), is("No flash context found, this call should only be made within a request."));
}
}
Aggregations