use of org.springframework.mock.web.test.MockServletContext in project spring-framework by spring-projects.
the class ThemeResolverTests method internalTest.
private void internalTest(ThemeResolver themeResolver, boolean shouldSet, String defaultName) {
// create mocks
MockServletContext context = new MockServletContext();
MockHttpServletRequest request = new MockHttpServletRequest(context);
MockHttpServletResponse response = new MockHttpServletResponse();
// check original theme
String themeName = themeResolver.resolveThemeName(request);
assertEquals(themeName, defaultName);
// set new theme name
try {
themeResolver.setThemeName(request, response, TEST_THEME_NAME);
if (!shouldSet)
fail("should not be able to set Theme name");
// check new theme namelocale
themeName = themeResolver.resolveThemeName(request);
assertEquals(TEST_THEME_NAME, themeName);
themeResolver.setThemeName(request, response, null);
themeName = themeResolver.resolveThemeName(request);
assertEquals(themeName, defaultName);
} catch (UnsupportedOperationException ex) {
if (shouldSet)
fail("should be able to set Theme name");
}
}
use of org.springframework.mock.web.test.MockServletContext in project spring-framework by spring-projects.
the class BaseViewTests method pathVarsOverrideStaticAttributes.
@Test
public void pathVarsOverrideStaticAttributes() throws Exception {
WebApplicationContext wac = mock(WebApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
HttpServletRequest request = new MockHttpServletRequest();
HttpServletResponse response = new MockHttpServletResponse();
TestView tv = new TestView(wac);
tv.setApplicationContext(wac);
Properties p = new Properties();
p.setProperty("one", "bar");
p.setProperty("something", "else");
tv.setAttributes(p);
Map<String, Object> pathVars = new HashMap<>();
pathVars.put("one", new HashMap<>());
pathVars.put("two", new Object());
request.setAttribute(View.PATH_VARIABLES, pathVars);
tv.render(new HashMap<>(), request, response);
checkContainsAll(pathVars, tv.model);
assertEquals(3, tv.model.size());
assertEquals("else", tv.model.get("something"));
assertTrue(tv.initialized);
}
use of org.springframework.mock.web.test.MockServletContext in project spring-framework by spring-projects.
the class BaseViewTests method dynamicModelOverridesPathVariables.
@Test
public void dynamicModelOverridesPathVariables() throws Exception {
WebApplicationContext wac = mock(WebApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
TestView tv = new TestView(wac);
tv.setApplicationContext(wac);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
Map<String, Object> pathVars = new HashMap<>();
pathVars.put("one", "bar");
pathVars.put("something", "else");
request.setAttribute(View.PATH_VARIABLES, pathVars);
Map<String, Object> model = new HashMap<>();
model.put("one", new HashMap<>());
model.put("two", new Object());
tv.render(model, request, response);
checkContainsAll(model, tv.model);
assertEquals(3, tv.model.size());
assertEquals("else", tv.model.get("something"));
assertTrue(tv.initialized);
}
use of org.springframework.mock.web.test.MockServletContext in project spring-framework by spring-projects.
the class BaseViewTests method renderWithStaticAttributesNoCollision.
/**
* Test attribute passing, NOT CSV parsing.
*/
@Test
public void renderWithStaticAttributesNoCollision() throws Exception {
WebApplicationContext wac = mock(WebApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
HttpServletRequest request = new MockHttpServletRequest();
HttpServletResponse response = new MockHttpServletResponse();
TestView tv = new TestView(wac);
tv.setApplicationContext(wac);
Properties p = new Properties();
p.setProperty("foo", "bar");
p.setProperty("something", "else");
tv.setAttributes(p);
Map<String, Object> model = new HashMap<>();
model.put("one", new HashMap<>());
model.put("two", new Object());
tv.render(model, request, response);
checkContainsAll(model, tv.model);
checkContainsAll(p, tv.model);
assertTrue(tv.initialized);
}
use of org.springframework.mock.web.test.MockServletContext in project spring-framework by spring-projects.
the class BaseViewTests method renderWithoutStaticAttributes.
@Test
public void renderWithoutStaticAttributes() throws Exception {
WebApplicationContext wac = mock(WebApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
HttpServletRequest request = new MockHttpServletRequest();
HttpServletResponse response = new MockHttpServletResponse();
TestView tv = new TestView(wac);
// Check superclass handles duplicate init
tv.setApplicationContext(wac);
tv.setApplicationContext(wac);
Map<String, Object> model = new HashMap<>();
model.put("foo", "bar");
model.put("something", new Object());
tv.render(model, request, response);
checkContainsAll(model, tv.model);
assertTrue(tv.initialized);
}
Aggregations