Package org.springframework.mock.web

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


  private void doTestInitLogging(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 {
      doTestLogOutput();
View Full Code Here


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

    MockServletContext sc = new MockServletContext("", new FileSystemResourceLoader());
    sc.addInitParameter(Log4jWebConfigurer.CONFIG_LOCATION_PARAM,
        "test/org/springframework/util/testlog4j.properties");
    listener.contextInitialized(new ServletContextEvent(sc));

    try {
      doTestLogOutput();
View Full Code Here

  public void testLog4jConfigServlet() throws ServletException {
    Log4jConfigServlet servlet = new Log4jConfigServlet();

    MockServletContext sc = new MockServletContext("", new FileSystemResourceLoader());
    sc.addInitParameter(Log4jWebConfigurer.CONFIG_LOCATION_PARAM,
        "test/org/springframework/util/testlog4j.properties");
    servlet.init(new MockServletConfig(sc));

    try {
      doTestLogOutput();
View Full Code Here

*/
public class ContextLoaderTests extends TestCase {

  public void testContextLoaderListenerWithDefaultContext() throws Exception {
    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

   */
  public void testContextLoaderListenerWithCustomizedContextLoader() throws Exception {
    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");
    final ServletContextListener listener = new ContextLoaderListener() {
      protected ContextLoader createContextLoader() {
        return new ContextLoader() {
          protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) {
View Full Code Here

    assertEquals("customizeContext() should have been called.", expectedContents, buffer.toString());
  }

  public void testContextLoaderServletWithDefaultContext() throws Exception {
    MockServletContext sc = new MockServletContext("");
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
        "/org/springframework/web/context/WEB-INF/applicationContext.xml");
    HttpServlet servlet = new ContextLoaderServlet();
    ServletConfig config = new MockServletConfig(sc, "test");
    servlet.init(config);
    WebApplicationContext context = (WebApplicationContext) sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
View Full Code Here

    assertTrue("Destroyed", lb.isDestroyed());
  }

  public void testContextLoaderWithDefaultContextAndParent() throws Exception {
    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");
    sc.addInitParameter(ContextLoader.LOCATOR_FACTORY_SELECTOR_PARAM,
        "classpath:org/springframework/beans/factory/access/ref1.xml");
    sc.addInitParameter(ContextLoader.LOCATOR_FACTORY_KEY_PARAM, "a.qualified.name.of.some.sort");
View Full Code Here

  public void testContextLoaderWithDefaultContextAndParent() throws Exception {
    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");
    sc.addInitParameter(ContextLoader.LOCATOR_FACTORY_SELECTOR_PARAM,
        "classpath:org/springframework/beans/factory/access/ref1.xml");
    sc.addInitParameter(ContextLoader.LOCATOR_FACTORY_KEY_PARAM, "a.qualified.name.of.some.sort");
    ServletContextListener listener = new ContextLoaderListener();
    ServletContextEvent event = new ServletContextEvent(sc);
    listener.contextInitialized(event);
View Full Code Here

    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
        "/org/springframework/web/context/WEB-INF/applicationContext.xml "
            + "/org/springframework/web/context/WEB-INF/context-addition.xml");
    sc.addInitParameter(ContextLoader.LOCATOR_FACTORY_SELECTOR_PARAM,
        "classpath:org/springframework/beans/factory/access/ref1.xml");
    sc.addInitParameter(ContextLoader.LOCATOR_FACTORY_KEY_PARAM, "a.qualified.name.of.some.sort");
    ServletContextListener listener = new ContextLoaderListener();
    ServletContextEvent event = new ServletContextEvent(sc);
    listener.contextInitialized(event);
    WebApplicationContext context = (WebApplicationContext) sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    assertTrue("Correct WebApplicationContext exposed in ServletContext",
View Full Code Here

    assertTrue("Destroyed", lb.isDestroyed());
  }

  public void testContextLoaderWithCustomContext() throws Exception {
    MockServletContext sc = new MockServletContext("");
    sc.addInitParameter(ContextLoader.CONTEXT_CLASS_PARAM,
        "org.springframework.web.servlet.SimpleWebApplicationContext");
    ServletContextListener listener = new ContextLoaderListener();
    ServletContextEvent event = new ServletContextEvent(sc);
    listener.contextInitialized(event);
    WebApplicationContext wc = (WebApplicationContext) sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
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.