Search in sources :

Example 81 with MockHttpServletResponse

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

the class FreeMarkerMacroTests method setUp.

@Before
public void setUp() throws Exception {
    wac = new StaticWebApplicationContext();
    wac.setServletContext(new MockServletContext());
    // final Template expectedTemplate = new Template();
    fc = new FreeMarkerConfigurer();
    fc.setTemplateLoaderPaths("classpath:/", "file://" + System.getProperty("java.io.tmpdir"));
    fc.afterPropertiesSet();
    wac.getDefaultListableBeanFactory().registerSingleton("freeMarkerConfigurer", fc);
    wac.refresh();
    request = new MockHttpServletRequest();
    request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
    request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
    response = new MockHttpServletResponse();
}
Also used : FixedThemeResolver(org.springframework.web.servlet.theme.FixedThemeResolver) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) AcceptHeaderLocaleResolver(org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver) MockServletContext(org.springframework.mock.web.test.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Before(org.junit.Before)

Example 82 with MockHttpServletResponse

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

the class MappingJackson2XmlViewTests method setUp.

@Before
public void setUp() {
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    jsContext = ContextFactory.getGlobal().enterContext();
    jsScope = jsContext.initStandardObjects();
    view = new MappingJackson2XmlView();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Before(org.junit.Before)

Example 83 with MockHttpServletResponse

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

the class TilesConfigurerTests method simpleBootstrap.

@Test
public void simpleBootstrap() {
    MockServletContext servletContext = new MockServletContext();
    TilesConfigurer tc = new TilesConfigurer();
    tc.setDefinitions("/org/springframework/web/servlet/view/tiles3/tiles-definitions.xml");
    tc.setCheckRefresh(true);
    tc.setServletContext(servletContext);
    tc.afterPropertiesSet();
    ApplicationContext tilesContext = ServletUtil.getApplicationContext(servletContext);
    BasicTilesContainer container = (BasicTilesContainer) TilesAccess.getContainer(tilesContext);
    Request requestContext = new ServletRequest(container.getApplicationContext(), new MockHttpServletRequest(), new MockHttpServletResponse());
    assertNotNull(container.getDefinitionsFactory().getDefinition("test", requestContext));
    tc.destroy();
}
Also used : ServletRequest(org.apache.tiles.request.servlet.ServletRequest) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) ApplicationContext(org.apache.tiles.request.ApplicationContext) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) BasicTilesContainer(org.apache.tiles.impl.BasicTilesContainer) ServletRequest(org.apache.tiles.request.servlet.ServletRequest) Request(org.apache.tiles.request.Request) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MockServletContext(org.springframework.mock.web.test.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 84 with MockHttpServletResponse

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

the class MappingJackson2JsonViewTests method setUp.

@Before
public void setUp() {
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    jsContext = ContextFactory.getGlobal().enterContext();
    jsScope = jsContext.initStandardObjects();
    view = new MappingJackson2JsonView();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Before(org.junit.Before)

Example 85 with MockHttpServletResponse

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

the class JythonScriptTemplateTests method renderViewWithModel.

private MockHttpServletResponse renderViewWithModel(String viewUrl, Map<String, Object> model) throws Exception {
    ScriptTemplateView view = createViewWithUrl(viewUrl);
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockHttpServletRequest request = new MockHttpServletRequest();
    view.renderMergedOutputModel(model, request, response);
    return response;
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse)

Aggregations

MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)171 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)162 Test (org.junit.Test)140 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)33 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)28 Before (org.junit.Before)19 MockServletContext (org.springframework.mock.web.test.MockServletContext)14 HttpServletResponse (javax.servlet.http.HttpServletResponse)13 ModelAndView (org.springframework.web.servlet.ModelAndView)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)10 TestBean (org.springframework.tests.sample.beans.TestBean)9 HashMap (java.util.HashMap)8 FilterChain (javax.servlet.FilterChain)8 ServletException (javax.servlet.ServletException)7 HttpSession (javax.servlet.http.HttpSession)7 IOException (java.io.IOException)6 Map (java.util.Map)6 ServletRequest (javax.servlet.ServletRequest)6 ServletResponse (javax.servlet.ServletResponse)6