use of org.springframework.web.testfixture.servlet.MockPageContext in project spring-framework by spring-projects.
the class ErrorsTagTests method exposeBindingResult.
@Override
protected void exposeBindingResult(Errors errors) {
// wrap errors in a Model
Map model = new HashMap();
model.put(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, errors);
// replace the request context with one containing the errors
MockPageContext pageContext = getPageContext();
RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
}
use of org.springframework.web.testfixture.servlet.MockPageContext in project spring-framework by spring-projects.
the class AbstractTagTests method createPageContext.
protected MockPageContext createPageContext() {
MockServletContext sc = new MockServletContext();
SimpleWebApplicationContext wac = new SimpleWebApplicationContext();
wac.setServletContext(sc);
wac.setNamespace("test");
wac.refresh();
MockHttpServletRequest request = new MockHttpServletRequest(sc);
MockHttpServletResponse response = new MockHttpServletResponse();
if (inDispatcherServlet()) {
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
LocaleResolver lr = new AcceptHeaderLocaleResolver();
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, lr);
ThemeResolver tr = new FixedThemeResolver();
request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, tr);
request.setAttribute(DispatcherServlet.THEME_SOURCE_ATTRIBUTE, wac);
} else {
sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
}
return new MockPageContext(sc, request, response);
}
use of org.springframework.web.testfixture.servlet.MockPageContext in project spring-framework by spring-projects.
the class AbstractHtmlElementTagTests method createAndPopulatePageContext.
protected MockPageContext createAndPopulatePageContext() throws JspException {
MockPageContext pageContext = createPageContext();
MockHttpServletRequest request = (MockHttpServletRequest) pageContext.getRequest();
((StaticWebApplicationContext) RequestContextUtils.findWebApplicationContext(request)).registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
extendRequest(request);
extendPageContext(pageContext);
RequestContext requestContext = new JspAwareRequestContext(pageContext);
pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, requestContext);
return pageContext;
}
use of org.springframework.web.testfixture.servlet.MockPageContext in project spring-framework by spring-projects.
the class TagIdGeneratorTests method assertNextId.
private void assertNextId() {
PageContext pageContext = new MockPageContext();
assertThat(TagIdGenerator.nextId("foo", pageContext)).isEqualTo("foo1");
assertThat(TagIdGenerator.nextId("foo", pageContext)).isEqualTo("foo2");
assertThat(TagIdGenerator.nextId("foo", pageContext)).isEqualTo("foo3");
assertThat(TagIdGenerator.nextId("foo", pageContext)).isEqualTo("foo4");
assertThat(TagIdGenerator.nextId("bar", pageContext)).isEqualTo("bar1");
}
use of org.springframework.web.testfixture.servlet.MockPageContext in project spring-framework by spring-projects.
the class OptionsTagTests method exposeBindingResult.
@Override
protected void exposeBindingResult(Errors errors) {
// wrap errors in a Model
Map model = new HashMap();
model.put(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, errors);
// replace the request context with one containing the errors
MockPageContext pageContext = getPageContext();
RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
}
Aggregations