use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class SessionLocaleResolverTests method testSetAndResolveLocale.
@Test
public void testSetAndResolveLocale() {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
SessionLocaleResolver resolver = new SessionLocaleResolver();
resolver.setLocale(request, response, Locale.GERMAN);
assertEquals(Locale.GERMAN, resolver.resolveLocale(request));
HttpSession session = request.getSession();
request = new MockHttpServletRequest();
request.setSession(session);
resolver = new SessionLocaleResolver();
assertEquals(Locale.GERMAN, resolver.resolveLocale(request));
}
use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class SessionLocaleResolverTests method testSetLocaleToNullLocale.
@Test
public void testSetLocaleToNullLocale() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addPreferredLocale(Locale.TAIWAN);
request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, Locale.GERMAN);
MockHttpServletResponse response = new MockHttpServletResponse();
SessionLocaleResolver resolver = new SessionLocaleResolver();
resolver.setLocale(request, response, null);
Locale locale = (Locale) request.getSession().getAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME);
assertNull(locale);
HttpSession session = request.getSession();
request = new MockHttpServletRequest();
request.addPreferredLocale(Locale.TAIWAN);
request.setSession(session);
resolver = new SessionLocaleResolver();
assertEquals(Locale.TAIWAN, resolver.resolveLocale(request));
}
use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class ControllerTests method parameterizableViewController.
@Test
public void parameterizableViewController() throws Exception {
String viewName = "viewName";
ParameterizableViewController pvc = new ParameterizableViewController();
pvc.setViewName(viewName);
// We don't care about the params.
ModelAndView mv = pvc.handleRequest(new MockHttpServletRequest("GET", "foo.html"), new MockHttpServletResponse());
assertTrue("model has no data", mv.getModel().size() == 0);
assertTrue("model has correct viewname", mv.getViewName().equals(viewName));
assertTrue("getViewName matches", pvc.getViewName().equals(viewName));
}
use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class ControllerTests method servletWrappingController.
@Test
public void servletWrappingController() throws Exception {
HttpServletRequest request = new MockHttpServletRequest("GET", "/somePath");
HttpServletResponse response = new MockHttpServletResponse();
ServletWrappingController swc = new ServletWrappingController();
swc.setServletClass(TestServlet.class);
swc.setServletName("action");
Properties props = new Properties();
props.setProperty("config", "myValue");
swc.setInitParameters(props);
swc.afterPropertiesSet();
assertNotNull(TestServlet.config);
assertEquals("action", TestServlet.config.getServletName());
assertEquals("myValue", TestServlet.config.getInitParameter("config"));
assertNull(TestServlet.request);
assertFalse(TestServlet.destroyed);
assertNull(swc.handleRequest(request, response));
assertEquals(request, TestServlet.request);
assertEquals(response, TestServlet.response);
assertFalse(TestServlet.destroyed);
swc.destroy();
assertTrue(TestServlet.destroyed);
}
use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class AcceptHeaderLocaleResolverTests method request.
private HttpServletRequest request(Locale... locales) {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setPreferredLocales(Arrays.asList(locales));
return request;
}
Aggregations