use of com.thoughtworks.go.presentation.FlashMessageModel 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 com.thoughtworks.go.presentation.FlashMessageModel 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 com.thoughtworks.go.presentation.FlashMessageModel in project gocd by gocd.
the class FlashLoadingFilterTest 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 com.thoughtworks.go.presentation.FlashMessageModel in project gocd by gocd.
the class FlashLoadingFilterTest 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 FlashLoadingFilterTest 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."));
}
}
Aggregations