Package org.springframework.mock.web.test

Examples of org.springframework.mock.web.test.MockServletContext


  }

  @Test
  public void withServletContextAndFilter() throws Exception {
    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(new MockServletContext());
    wac.registerSingleton("filterMultipartResolver", MockCommonsMultipartResolver.class, new MutablePropertyValues());
    wac.getServletContext().setAttribute(WebUtils.TEMP_DIR_CONTEXT_ATTRIBUTE, new File("mytemp"));
    wac.refresh();
    wac.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    CommonsMultipartResolver resolver = new CommonsMultipartResolver(wac.getServletContext());
View Full Code Here


  }

  @Test
  public void withServletContextAndFilterWithCustomBeanName() throws Exception {
    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(new MockServletContext());
    wac.refresh();
    wac.registerSingleton("myMultipartResolver", MockCommonsMultipartResolver.class, new MutablePropertyValues());
    wac.getServletContext().setAttribute(WebUtils.TEMP_DIR_CONTEXT_ATTRIBUTE, new File("mytemp"));
    wac.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    CommonsMultipartResolver resolver = new CommonsMultipartResolver(wac.getServletContext());
View Full Code Here

    URL url = Log4jWebConfigurerTests.class.getResource(TESTLOG4J_PROPERTIES);
    initLogging(url.getFile(), true);
  }

  private void initLogging(String location, boolean refreshInterval) {
    MockServletContext sc = new MockServletContext("", new FileSystemResourceLoader());
    sc.addInitParameter(Log4jWebConfigurer.CONFIG_LOCATION_PARAM, location);
    if (refreshInterval) {
      sc.addInitParameter(Log4jWebConfigurer.REFRESH_INTERVAL_PARAM, "10");
    }
    Log4jWebConfigurer.initLogging(sc);

    try {
      assertLogOutput();
View Full Code Here

  @Test
  public void testLog4jConfigListener() {
    Log4jConfigListener listener = new Log4jConfigListener();

    MockServletContext sc = new MockServletContext("", new FileSystemResourceLoader());
    sc.addInitParameter(Log4jWebConfigurer.CONFIG_LOCATION_PARAM, RELATIVE_PATH);
    listener.contextInitialized(new ServletContextEvent(sc));

    try {
      assertLogOutput();
    } finally {
View Full Code Here

*/
public class ServletContextPropertyUtilsTests {

    @Test
    public void resolveAsServletContextInitParameter() {
        MockServletContext servletContext = new MockServletContext();
        servletContext.setInitParameter("test.prop", "bar");
        String resolved = ServletContextPropertyUtils.resolvePlaceholders("${test.prop:foo}", servletContext);
        assertEquals(resolved, "bar");
    }
View Full Code Here

        assertEquals(resolved, "bar");
    }

    @Test
    public void fallbackToSystemProperties() {
        MockServletContext servletContext = new MockServletContext();
        System.setProperty("test.prop", "bar");
        try {
            String resolved = ServletContextPropertyUtils.resolvePlaceholders("${test.prop:foo}", servletContext);
            assertEquals(resolved, "bar");
        }
View Full Code Here

*/
public class ServletContextSupportTests {

  @Test
  public void testServletContextAttributeFactoryBean() {
    MockServletContext sc = new MockServletContext();
    sc.setAttribute("myAttr", "myValue");

    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(sc);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("attributeName", "myAttr");
View Full Code Here

    assertEquals("myValue", value);
  }

  @Test
  public void testServletContextAttributeFactoryBeanWithAttributeNotFound() {
    MockServletContext sc = new MockServletContext();

    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(sc);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("attributeName", "myAttr");
View Full Code Here

    }
  }

  @Test
  public void testServletContextParameterFactoryBean() {
    MockServletContext sc = new MockServletContext();
    sc.addInitParameter("myParam", "myValue");

    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(sc);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("initParamName", "myParam");
View Full Code Here

    assertEquals("myValue", value);
  }

  @Test
  public void testServletContextParameterFactoryBeanWithAttributeNotFound() {
    MockServletContext sc = new MockServletContext();

    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(sc);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("initParamName", "myParam");
View Full Code Here

TOP

Related Classes of org.springframework.mock.web.test.MockServletContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.