List of usage examples for org.springframework.mock.web MockPageContext MockPageContext
public MockPageContext(@Nullable ServletContext servletContext, @Nullable HttpServletRequest request,
@Nullable HttpServletResponse response)
From source file:com.gantzgulch.taglibs.html.BodyTagRunner.java
public BodyTagRunner(BodyTag bodyTag, String contextPath) throws JspException { servletRequest = new MockHttpServletRequest(); servletResponse = new MockHttpServletResponse(); servletContext = new MockServletContext(); servletContext.setContextPath(contextPath); pageContext = new MockPageContext(servletContext, servletRequest, servletResponse); this.bodyTag = bodyTag; state = doInitializeState.execute(); }
From source file:org.parancoe.web.test.junit4.AbstractJspTest.java
/** * Reset all contexts./*from w ww .j a va2 s.c o m*/ */ protected void resetContexts() { GenericWebApplicationContext context = (GenericWebApplicationContext) applicationContext; ServletContext servletContext = context.getServletContext(); pageContext = new MockPageContext(servletContext, request, response); requestContext = new JspAwareRequestContext(pageContext); pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, requestContext); }
From source file:com.amashchenko.struts2.actionflow.ActionFlowAwareTest.java
/** Initializes servlet mock objects but preserves session. */ private void initServletMockObjectsPreserveSession() { servletContext = new MockServletContext(resourceLoader); response = new MockHttpServletResponse(); // preserve session HttpSession session = null;//from www. jav a2 s.c om if (request != null && request.getSession() != null) { session = request.getSession(); } request = new MockHttpServletRequest(); request.setSession(session); pageContext = new MockPageContext(servletContext, request, response); }
From source file:org.hdiv.web.servlet.tags.AbstractTagTests.java
protected MockPageContext createPageContext() { MockServletContext sc = new MockServletContext(); SimpleWebApplicationContext wac = new SimpleWebApplicationContext(); wac.setServletContext(sc);/*from w w w . j a v a 2 s. c o m*/ 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); }
From source file:org.openmrs.web.taglib.OpenmrsMessageTagTest.java
@Before public void createMockPageContext() throws Exception { MockServletContext sc = new MockServletContext(); SimpleWebApplicationContext wac = new SimpleWebApplicationContext(); wac.setServletContext(sc);/*from w w w . j a v a 2 s .co m*/ wac.setNamespace("test"); wac.refresh(); MockHttpServletRequest request = new MockHttpServletRequest(sc); request.addPreferredLocale(Context.getLocale()); MockHttpServletResponse response = new MockHttpServletResponse(); request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); openmrsMessageTag = new OpenmrsMessageTag(); mockPageContext = new MockPageContext(sc, request, response); openmrsMessageTag.setPageContext(mockPageContext); }
From source file:org.parancoe.web.test.TagTest.java
/** * Reset the request and the response, maintaining the same session. Useful, for example, to * call a post after calling the get of the form. *//*from ww w . jav a2 s.com*/ protected void resetRequestAndResponse() { HttpSession httpSession = null; // preparing the multipart request if (mpReq != null) { httpSession = mpReq.getSession(); } mpReq = new MockMultipartHttpServletRequest(); mpReq.setSession(httpSession); mpReq.setMethod("GET"); // preparing the normal request if (req != null) { httpSession = req.getSession(); } req = new MockHttpServletRequest(); req.setSession(httpSession); req.setMethod("GET"); req.setContextPath("/testctx"); req.setRequestURI("/testctx/test/request/uri"); req.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/testctx/test/forward/request/uri"); req.setQueryString("p1=v1&p2=v2&p3=v3"); res = new MockHttpServletResponse(); pc = new MockPageContext(((WebApplicationContext) this.getApplicationContext()).getServletContext(), req, res); rc = new JspAwareRequestContext(pc); pc.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, rc); }
From source file:org.sventon.web.tags.UrlTagTest.java
protected MockPageContext createPageContext() { final MockServletContext sc = new MockServletContext(); final MockHttpServletRequest request = new MockHttpServletRequest(sc); final MockHttpServletResponse response = new MockHttpServletResponse(); request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, Mockito.mock(WebApplicationContext.class)); return new MockPageContext(sc, request, response); }
From source file:org.terasoluna.gfw.web.pagination.PaginationTagTest.java
protected MockPageContext createPageContext() { MockServletContext sc = new MockServletContext(); WebApplicationContext wac = mock(WebApplicationContext.class); when(wac.getServletContext()).thenReturn(sc); MockHttpServletRequest request = new MockHttpServletRequest(sc); MockHttpServletResponse response = new MockHttpServletResponse(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); return new MockPageContext(sc, request, response); }
From source file:org.terasoluna.gfw.web.message.MessagesPanelTagTest.java
/** * create mock PageContext./*from w w w . j a va 2 s .c o m*/ */ protected MockPageContext createPageContext() { MockServletContext sc = new MockServletContext(); wac = mock(WebApplicationContext.class); when(wac.getMessage(eq("hello.world"), eq(new Object[] {}), (Locale) anyObject())) .thenReturn("hello world!"); when(wac.getMessage(eq("foo.bar"), eq(new Object[] { 1, 2 }), (Locale) anyObject())) .thenReturn("foo1 and bar2"); when(wac.getServletContext()).thenReturn(sc); request = new MockHttpServletRequest(sc); MockHttpServletResponse response = new MockHttpServletResponse(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); return new MockPageContext(sc, request, response); }
From source file:com.javaetmoi.core.mvc.tag.TestHtml5InputTag.java
protected MockPageContext createPageContext() { MockServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc);/*from w w w . ja v a2 s . co m*/ wac.setNamespace("test"); wac.registerSingleton("validator", org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.class); wac.refresh(); MockHttpServletRequest request = new MockHttpServletRequest(sc); MockHttpServletResponse response = new MockHttpServletResponse(); 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); return new MockPageContext(sc, request, response); }