List of usage examples for org.springframework.mock.web MockPageContext MockPageContext
public MockPageContext(@Nullable ServletContext servletContext, @Nullable HttpServletRequest request)
From source file:com.trenako.web.test.AbstractSpringTagsTest.java
@Before public void setup() throws Exception { mockServletContext = new MockServletContext(); // mocking the spring web application context mockWebApplicationContext = mock(WebApplicationContext.class); when(mockWebApplicationContext.getServletContext()).thenReturn(mockServletContext); when(mockWebApplicationContext.getAutowireCapableBeanFactory()) .thenReturn(mock(AutowireCapableBeanFactory.class)); mockServletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, mockWebApplicationContext);/*from ww w . j a va 2 s. c o m*/ // mocking the servlet request mockRequest = new MockHttpServletRequest(); mockRequest.setContextPath("/trenako-web"); mockRequest.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/trenako-web"); mockPageContext = new MockPageContext(mockServletContext, mockRequest); // mocking the message source to always return the default value mockMessageSource = mock(MessageSource.class); when(mockMessageSource.getMessage(anyString(), any(Object[].class), anyString(), any(Locale.class))) .thenAnswer(new Answer<String>() { @Override public String answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); return (String) args[2]; } }); // give the tag under test the chance to setup itself setupTag(mockPageContext, mockMessageSource); }
From source file:ar.com.zauber.commons.web.uri.assets.AssetsTest.java
/** create the {@link PageContext} to test */ private MockPageContext createPageContext(final XmlWebApplicationContext ctx) { final HttpServletRequest request = createRequest(ctx); final MockPageContext pageCtx = new MockPageContext(ctx.getServletContext(), request); pageCtx.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx); return pageCtx; }