Package org.springframework.mock.web.test

Examples of org.springframework.mock.web.test.MockServletContext.addInitParameter()


public final class ContextLoaderTests {

  @Test
  public void testContextLoaderListenerWithDefaultContext() {
    MockServletContext sc = new MockServletContext("");
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
        "/org/springframework/web/context/WEB-INF/applicationContext.xml " +
        "/org/springframework/web/context/WEB-INF/context-addition.xml");
    ServletContextListener listener = new ContextLoaderListener();
    ServletContextEvent event = new ServletContextEvent(sc);
    listener.contextInitialized(event);
View Full Code Here


  @Test
  public void testContextLoaderListenerWithCustomizedContextLoader() {
    final StringBuffer buffer = new StringBuffer();
    final String expectedContents = "customizeContext() was called";
    final MockServletContext sc = new MockServletContext("");
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
        "/org/springframework/web/context/WEB-INF/applicationContext.xml");
    ServletContextListener listener = new ContextLoaderListener() {
      @Override
      protected void customizeContext(ServletContext sc, ConfigurableWebApplicationContext wac) {
        assertNotNull("The ServletContext should not be null.", sc);
View Full Code Here

  }

  @Test
  public void testContextLoaderListenerWithLocalContextInitializers() {
    MockServletContext sc = new MockServletContext("");
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
        "org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml");
    sc.addInitParameter(ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, StringUtils.arrayToCommaDelimitedString(
        new Object[] {TestContextInitializer.class.getName(), TestWebContextInitializer.class.getName()}));
    ContextLoaderListener listener = new ContextLoaderListener();
    listener.contextInitialized(new ServletContextEvent(sc));
View Full Code Here

  @Test
  public void testContextLoaderListenerWithLocalContextInitializers() {
    MockServletContext sc = new MockServletContext("");
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
        "org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml");
    sc.addInitParameter(ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, StringUtils.arrayToCommaDelimitedString(
        new Object[] {TestContextInitializer.class.getName(), TestWebContextInitializer.class.getName()}));
    ContextLoaderListener listener = new ContextLoaderListener();
    listener.contextInitialized(new ServletContextEvent(sc));
    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
    TestBean testBean = wac.getBean(TestBean.class);
View Full Code Here

  }

  @Test
  public void testContextLoaderListenerWithGlobalContextInitializers() {
    MockServletContext sc = new MockServletContext("");
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
        "org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml");
    sc.addInitParameter(ContextLoader.GLOBAL_INITIALIZER_CLASSES_PARAM, StringUtils.arrayToCommaDelimitedString(
        new Object[] {TestContextInitializer.class.getName(), TestWebContextInitializer.class.getName()}));
    ContextLoaderListener listener = new ContextLoaderListener();
    listener.contextInitialized(new ServletContextEvent(sc));
View Full Code Here

  @Test
  public void testContextLoaderListenerWithGlobalContextInitializers() {
    MockServletContext sc = new MockServletContext("");
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
        "org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml");
    sc.addInitParameter(ContextLoader.GLOBAL_INITIALIZER_CLASSES_PARAM, StringUtils.arrayToCommaDelimitedString(
        new Object[] {TestContextInitializer.class.getName(), TestWebContextInitializer.class.getName()}));
    ContextLoaderListener listener = new ContextLoaderListener();
    listener.contextInitialized(new ServletContextEvent(sc));
    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
    TestBean testBean = wac.getBean(TestBean.class);
View Full Code Here

  }

  @Test
  public void testContextLoaderListenerWithMixedContextInitializers() {
    MockServletContext sc = new MockServletContext("");
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
        "org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml");
    sc.addInitParameter(ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, TestContextInitializer.class.getName());
    sc.addInitParameter(ContextLoader.GLOBAL_INITIALIZER_CLASSES_PARAM, TestWebContextInitializer.class.getName());
    ContextLoaderListener listener = new ContextLoaderListener();
    listener.contextInitialized(new ServletContextEvent(sc));
View Full Code Here

  @Test
  public void testContextLoaderListenerWithMixedContextInitializers() {
    MockServletContext sc = new MockServletContext("");
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
        "org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml");
    sc.addInitParameter(ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, TestContextInitializer.class.getName());
    sc.addInitParameter(ContextLoader.GLOBAL_INITIALIZER_CLASSES_PARAM, TestWebContextInitializer.class.getName());
    ContextLoaderListener listener = new ContextLoaderListener();
    listener.contextInitialized(new ServletContextEvent(sc));
    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
    TestBean testBean = wac.getBean(TestBean.class);
View Full Code Here

  public void testContextLoaderListenerWithMixedContextInitializers() {
    MockServletContext sc = new MockServletContext("");
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
        "org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml");
    sc.addInitParameter(ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, TestContextInitializer.class.getName());
    sc.addInitParameter(ContextLoader.GLOBAL_INITIALIZER_CLASSES_PARAM, TestWebContextInitializer.class.getName());
    ContextLoaderListener listener = new ContextLoaderListener();
    listener.contextInitialized(new ServletContextEvent(sc));
    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
    TestBean testBean = wac.getBean(TestBean.class);
    assertThat(testBean.getName(), equalTo("testName"));
View Full Code Here

  @Test
  public void testRegisteredContextInitializerCanAccessServletContextParamsViaEnvironment() {
    MockServletContext sc = new MockServletContext("");
    // config file doesn't matter - just a placeholder
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
        "/org/springframework/web/context/WEB-INF/empty-context.xml");

    sc.addInitParameter("someProperty", "someValue");
    sc.addInitParameter(ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, EnvApplicationContextInitializer.class.getName());
    ContextLoaderListener listener = new ContextLoaderListener();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.