Search in sources :

Example 51 with MockServletContext

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

the class JythonScriptTemplateTests method setup.

@Before
public void setup() {
    this.webAppContext = mock(WebApplicationContext.class);
    this.servletContext = new MockServletContext();
    this.servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.webAppContext);
}
Also used : MockServletContext(org.springframework.mock.web.test.MockServletContext) WebApplicationContext(org.springframework.web.context.WebApplicationContext) Before(org.junit.Before)

Example 52 with MockServletContext

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

the class NashornScriptTemplateTests method setup.

@Before
public void setup() {
    this.webAppContext = mock(WebApplicationContext.class);
    this.servletContext = new MockServletContext();
    this.servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.webAppContext);
}
Also used : MockServletContext(org.springframework.mock.web.test.MockServletContext) WebApplicationContext(org.springframework.web.context.WebApplicationContext) Before(org.junit.Before)

Example 53 with MockServletContext

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

the class TestValidator method loadBeanDefinitions.

private void loadBeanDefinitions(String fileName) {
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.appContext);
    ClassPathResource resource = new ClassPathResource(fileName, MessageBrokerBeanDefinitionParserTests.class);
    reader.loadBeanDefinitions(resource);
    this.appContext.setServletContext(new MockServletContext());
    this.appContext.refresh();
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ClassPathResource(org.springframework.core.io.ClassPathResource) MockServletContext(org.springframework.mock.web.test.MockServletContext)

Example 54 with MockServletContext

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

the class ResourceTests method testServletContextResourceWithRelativePath.

@Test
public void testServletContextResourceWithRelativePath() throws IOException {
    MockServletContext sc = new MockServletContext();
    Resource resource = new ServletContextResource(sc, "dir/");
    Resource relative = resource.createRelative("subdir");
    assertEquals(new ServletContextResource(sc, "dir/subdir"), relative);
}
Also used : Resource(org.springframework.core.io.Resource) MockServletContext(org.springframework.mock.web.test.MockServletContext) Test(org.junit.Test)

Example 55 with MockServletContext

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

the class Spr8510Tests method abstractRefreshableWAC_respectsProgrammaticConfigLocations.

@Test
public void abstractRefreshableWAC_respectsProgrammaticConfigLocations() {
    XmlWebApplicationContext ctx = new XmlWebApplicationContext();
    ctx.setConfigLocation("programmatic.xml");
    ContextLoaderListener cll = new ContextLoaderListener(ctx);
    MockServletContext sc = new MockServletContext();
    try {
        cll.contextInitialized(new ServletContextEvent(sc));
        fail("expected exception");
    } catch (Throwable t) {
        // assert that an attempt was made to load the correct XML
        assertTrue(t.getMessage(), t.getMessage().endsWith("Could not open ServletContext resource [/programmatic.xml]"));
    }
}
Also used : ContextLoaderListener(org.springframework.web.context.ContextLoaderListener) MockServletContext(org.springframework.mock.web.test.MockServletContext) ServletContextEvent(javax.servlet.ServletContextEvent) Test(org.junit.Test)

Aggregations

MockServletContext (org.springframework.mock.web.test.MockServletContext)152 Test (org.junit.Test)120 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)56 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)50 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)41 ServletContext (javax.servlet.ServletContext)22 ServletContextEvent (javax.servlet.ServletContextEvent)21 HashMap (java.util.HashMap)18 Before (org.junit.Before)18 HttpServletResponse (javax.servlet.http.HttpServletResponse)16 MockFilterConfig (org.springframework.mock.web.test.MockFilterConfig)16 TestBean (org.springframework.tests.sample.beans.TestBean)15 XmlWebApplicationContext (org.springframework.web.context.support.XmlWebApplicationContext)14 MockServletConfig (org.springframework.mock.web.test.MockServletConfig)13 View (org.springframework.web.servlet.View)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 WebApplicationContext (org.springframework.web.context.WebApplicationContext)12 Resource (org.springframework.core.io.Resource)11 ServletContextAwareProcessor (org.springframework.web.context.support.ServletContextAwareProcessor)10 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)9