Search in sources :

Example 11 with ContextLoaderListener

use of org.springframework.web.context.ContextLoaderListener in project spring-framework by spring-projects.

the class Spr8510Tests method annotationConfigWAC.

/**
	 * Ensure that ContextLoaderListener and AnnotationConfigApplicationContext interact nicely.
	 */
@Test
public void annotationConfigWAC() {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.scan("does.not.matter");
    ContextLoaderListener cll = new ContextLoaderListener(ctx);
    cll.contextInitialized(new ServletContextEvent(new MockServletContext()));
}
Also used : ContextLoaderListener(org.springframework.web.context.ContextLoaderListener) ServletContextEvent(javax.servlet.ServletContextEvent) MockServletContext(org.springframework.mock.web.test.MockServletContext) Test(org.junit.Test)

Example 12 with ContextLoaderListener

use of org.springframework.web.context.ContextLoaderListener in project opennms by OpenNMS.

the class HttpRemotingContextIT method testLoadContext.

public void testLoadContext() throws Throwable {
    DaoTestConfigBean bean = new DaoTestConfigBean();
    bean.afterPropertiesSet();
    MockDatabase db = new MockDatabase(true);
    DataSourceFactory.setInstance(db);
    servletContext = new MockServletContext("file:src/main/webapp");
    servletContext.addInitParameter("contextConfigLocation", "classpath:/META-INF/opennms/applicationContext-commonConfigs.xml " + "classpath:/META-INF/opennms/applicationContext-soa.xml " + "classpath:/META-INF/opennms/applicationContext-mockDao.xml " + "classpath*:/META-INF/opennms/component-service.xml " + "classpath*:/META-INF/opennms/component-dao.xml " + // Contexts within this project
    "/WEB-INF/applicationContext-common.xml " + "/WEB-INF/applicationContext-serviceRegistryRemoting.xml " + "/WEB-INF/applicationContext-spring-security.xml " + "/WEB-INF/applicationContext-svclayer.xml ");
    servletContext.addInitParameter("parentContextKey", "daoContext");
    ServletContextEvent e = new ServletContextEvent(servletContext);
    contextListener = new ContextLoaderListener();
    contextListener.contextInitialized(e);
    servletContext.setContextPath(contextPath);
    servletConfig = new MockServletConfig(servletContext, "dispatcher");
    servletConfig.addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
    servletConfig.addInitParameter("com.sun.jersey.config.property.packages", "org.opennms.web.rest");
    try {
        MockFilterConfig filterConfig = new MockFilterConfig(servletContext, "openSessionInViewFilter");
        filter = new OpenSessionInViewFilter();
        filter.init(filterConfig);
    } catch (ServletException se) {
        throw se.getRootCause();
    }
}
Also used : DaoTestConfigBean(org.opennms.test.DaoTestConfigBean) OpenSessionInViewFilter(org.springframework.orm.hibernate3.support.OpenSessionInViewFilter) ServletException(javax.servlet.ServletException) MockDatabase(org.opennms.core.test.db.MockDatabase) MockServletConfig(org.springframework.mock.web.MockServletConfig) ContextLoaderListener(org.springframework.web.context.ContextLoaderListener) MockServletContext(org.springframework.mock.web.MockServletContext) ServletContextEvent(javax.servlet.ServletContextEvent) MockFilterConfig(org.springframework.mock.web.MockFilterConfig)

Aggregations

ContextLoaderListener (org.springframework.web.context.ContextLoaderListener)12 ServletContextEvent (javax.servlet.ServletContextEvent)10 Test (org.junit.Test)7 MockServletContext (org.springframework.mock.web.test.MockServletContext)7 WebApplicationContext (org.springframework.web.context.WebApplicationContext)2 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)2 ServletException (javax.servlet.ServletException)1 WicketFilter (org.apache.wicket.protocol.http.WicketFilter)1 CoupleKey (org.jessma.util.CoupleKey)1 Server (org.mortbay.jetty.Server)1 Context (org.mortbay.jetty.servlet.Context)1 FilterHolder (org.mortbay.jetty.servlet.FilterHolder)1 MockDatabase (org.opennms.core.test.db.MockDatabase)1 DaoTestConfigBean (org.opennms.test.DaoTestConfigBean)1 ClassPathBeanDefinitionScanner (org.springframework.context.annotation.ClassPathBeanDefinitionScanner)1 MockFilterConfig (org.springframework.mock.web.MockFilterConfig)1 MockServletConfig (org.springframework.mock.web.MockServletConfig)1 MockServletContext (org.springframework.mock.web.MockServletContext)1 OpenSessionInViewFilter (org.springframework.orm.hibernate3.support.OpenSessionInViewFilter)1 RequestContextListener (org.springframework.web.context.request.RequestContextListener)1