Search in sources :

Example 1 with MockPageContext

use of org.springframework.mock.web.test.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);
}
Also used : LocaleResolver(org.springframework.web.servlet.LocaleResolver) AcceptHeaderLocaleResolver(org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver) FixedThemeResolver(org.springframework.web.servlet.theme.FixedThemeResolver) ThemeResolver(org.springframework.web.servlet.ThemeResolver) FixedThemeResolver(org.springframework.web.servlet.theme.FixedThemeResolver) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) SimpleWebApplicationContext(org.springframework.web.servlet.SimpleWebApplicationContext) MockPageContext(org.springframework.mock.web.test.MockPageContext) AcceptHeaderLocaleResolver(org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver) MockServletContext(org.springframework.mock.web.test.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse)

Example 2 with MockPageContext

use of org.springframework.mock.web.test.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 wac = (StaticWebApplicationContext) RequestContextUtils.findWebApplicationContext(request);
    wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
    extendRequest(request);
    extendPageContext(pageContext);
    RequestContext requestContext = new JspAwareRequestContext(pageContext);
    pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, requestContext);
    return pageContext;
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MockPageContext(org.springframework.mock.web.test.MockPageContext) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) JspAwareRequestContext(org.springframework.web.servlet.support.JspAwareRequestContext) JspAwareRequestContext(org.springframework.web.servlet.support.JspAwareRequestContext) RequestContext(org.springframework.web.servlet.support.RequestContext)

Example 3 with MockPageContext

use of org.springframework.mock.web.test.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);
}
Also used : HashMap(java.util.HashMap) MockPageContext(org.springframework.mock.web.test.MockPageContext) RequestContext(org.springframework.web.servlet.support.RequestContext) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with MockPageContext

use of org.springframework.mock.web.test.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);
}
Also used : HashMap(java.util.HashMap) MockPageContext(org.springframework.mock.web.test.MockPageContext) RequestContext(org.springframework.web.servlet.support.RequestContext) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with MockPageContext

use of org.springframework.mock.web.test.MockPageContext in project spring-framework by spring-projects.

the class TagIdGeneratorTests method assertNextId.

private void assertNextId() {
    PageContext pageContext = new MockPageContext();
    assertEquals("foo1", TagIdGenerator.nextId("foo", pageContext));
    assertEquals("foo2", TagIdGenerator.nextId("foo", pageContext));
    assertEquals("foo3", TagIdGenerator.nextId("foo", pageContext));
    assertEquals("foo4", TagIdGenerator.nextId("foo", pageContext));
    assertEquals("bar1", TagIdGenerator.nextId("bar", pageContext));
}
Also used : MockPageContext(org.springframework.mock.web.test.MockPageContext) MockPageContext(org.springframework.mock.web.test.MockPageContext) PageContext(javax.servlet.jsp.PageContext)

Aggregations

MockPageContext (org.springframework.mock.web.test.MockPageContext)6 RequestContext (org.springframework.web.servlet.support.RequestContext)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)2 JspAwareRequestContext (org.springframework.web.servlet.support.JspAwareRequestContext)2 PageContext (javax.servlet.jsp.PageContext)1 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)1 MockServletContext (org.springframework.mock.web.test.MockServletContext)1 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)1 LocaleResolver (org.springframework.web.servlet.LocaleResolver)1 SimpleWebApplicationContext (org.springframework.web.servlet.SimpleWebApplicationContext)1 ThemeResolver (org.springframework.web.servlet.ThemeResolver)1 AcceptHeaderLocaleResolver (org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver)1 FixedThemeResolver (org.springframework.web.servlet.theme.FixedThemeResolver)1