List of usage examples for org.springframework.mock.web MockServletContext MockServletContext
public MockServletContext(@Nullable ResourceLoader resourceLoader)
From source file:org.apache.struts2.StrutsJUnit4TestCase.java
protected void initServletMockObjects() { servletContext = new MockServletContext(resourceLoader); response = new MockHttpServletResponse(); request = new MockHttpServletRequest(); pageContext = new MockPageContext(servletContext, request, response); }
From source file:org.devproof.portal.test.MockContextLoader.java
@Override public ConfigurableApplicationContext loadContext(String... locations) throws Exception { registerResource(CommonConstants.JNDI_MAIL_SESSION, Session.getDefaultInstance(new Properties())); registerResource(CommonConstants.JNDI_PROP_EMAIL_DISABLED, "true"); registerResource(CommonConstants.JNDI_PROP_HIBERNATE_DIALECT, "org.hibernate.dialect.H2Dialect"); registerResource(CommonConstants.JNDI_PROP_HIBERNATE_SECOND_LEVEL_CACHE, "false"); registerResource(CommonConstants.JNDI_PROP_HIBERNATE_QUERY_CACHE, "false"); ConfigurableWebApplicationContext context = new XmlWebApplicationContext(); MockServletContext servletContext = new MockServletContext("") { @Override//ww w . jav a 2 s.co m public String getRealPath(String arg0) { return System.getProperty("java.io.tmpdir"); } }; servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context); context.setServletContext(servletContext); String[] configLocations = PortalContextLoaderListener.locateConfigLocations(locations); context.setConfigLocations(configLocations); context.refresh(); context.registerShutdownHook(); return context; }
From source file:org.gwtwidgets.server.spring.test.TestHandler.java
@Override protected void setUp() throws Exception { super.setUp(); ServletContext servletContext = new MockServletContext(new FileSystemResourceLoader()); requestService = new MockHttpServletRequest("PUT", "/service"); applicationContext = new XmlWebApplicationContext(); applicationContext.setServletContext(servletContext); applicationContext.setConfigLocations(new String[] { "src/test/webapp/WEB-INF/handler-servlet.xml", "src/test/webapp/WEB-INF/applicationContext.xml" }); try {//from w ww . ja v a 2 s.c o m applicationContext.refresh(); } catch (Throwable e) { e.printStackTrace(); } handler = (GWTHandler) applicationContext.getBean("urlMapping", GWTHandler.class); }
From source file:org.gwtwidgets.server.spring.test.TestRPCExporter.java
@Override protected void setUp() throws Exception { requestPayload = readResource("request_add.txt"); responsePayload = readResource("response_add.txt"); MockServletContext servletContext = new MockServletContext(new TestResourceLoader()); MockServletConfig servletConfig = new MockServletConfig(servletContext); applicationContext = new XmlWebApplicationContext(); applicationContext.setServletContext(servletContext); applicationContext.setServletConfig(servletConfig); applicationContext.setConfigLocations(new String[] { "src/test/webapp/WEB-INF/exporter-servlet.xml", "src/test/webapp/WEB-INF/applicationContext.xml" }); applicationContext.refresh();/*from w ww . j a v a 2 s .c om*/ handlerMapping = (SimpleUrlHandlerMapping) applicationContext .getBean("org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"); }
From source file:org.opennms.web.rest.AbstractSpringJerseyRestTestCase.java
@Before public void setUp() throws Throwable { beforeServletStart();//from www. j a v a 2 s .com DaoTestConfigBean bean = new DaoTestConfigBean(); bean.afterPropertiesSet(); MockDatabase db = new MockDatabase(true); DataSourceFactory.setInstance(db); setServletContext(new MockServletContext("file:src/main/webapp")); getServletContext().addInitParameter("contextConfigLocation", "classpath:/org/opennms/web/rest/applicationContext-test.xml " + "classpath:/META-INF/opennms/applicationContext-commonConfigs.xml " + "classpath:/META-INF/opennms/applicationContext-soa.xml " + "classpath*:/META-INF/opennms/component-service.xml " + "classpath*:/META-INF/opennms/component-dao.xml " + "classpath:/META-INF/opennms/applicationContext-reportingCore.xml " + "classpath:/META-INF/opennms/applicationContext-databasePopulator.xml " + "classpath:/org/opennms/web/svclayer/applicationContext-svclayer.xml " + "classpath:/META-INF/opennms/applicationContext-mockEventProxy.xml " + "classpath:/applicationContext-jersey-test.xml " + "classpath:/META-INF/opennms/applicationContext-reporting.xml " + "classpath:/META-INF/opennms/applicationContext-mock-usergroup.xml " + "classpath:/META-INF/opennms/applicationContext-minimal-conf.xml " + "/WEB-INF/applicationContext-spring-security.xml " + "/WEB-INF/applicationContext-jersey.xml"); getServletContext().addInitParameter("parentContextKey", "daoContext"); ServletContextEvent e = new ServletContextEvent(getServletContext()); setContextListener(new ContextLoaderListener()); getContextListener().contextInitialized(e); getServletContext().setContextPath(contextPath); setServletConfig(new MockServletConfig(getServletContext(), "dispatcher")); getServletConfig().addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig"); getServletConfig().addInitParameter("com.sun.jersey.config.property.packages", "org.opennms.web.rest"); try { MockFilterConfig filterConfig = new MockFilterConfig(getServletContext(), "openSessionInViewFilter"); setFilter(new OpenSessionInViewFilter()); getFilter().init(filterConfig); setDispatcher(new SpringServlet()); getDispatcher().init(getServletConfig()); } catch (ServletException se) { throw se.getRootCause(); } setWebAppContext(WebApplicationContextUtils.getWebApplicationContext(getServletContext())); afterServletStart(); System.err.println("------------------------------------------------------------------------------"); }
From source file:ubic.gemma.web.util.WebContextLoader.java
@Override public ApplicationContext loadContext(String... locations) { if (WebContextLoader.logger.isDebugEnabled()) { WebContextLoader.logger.debug("Loading WebApplicationContext for locations [" + StringUtils.arrayToCommaDelimitedString(locations) + "]."); }//from w w w. jav a 2 s. c o m ConfigurableWebApplicationContext context = new XmlWebApplicationContext(); context.setConfigLocations(locations); context.setServletContext(new MockServletContext("")); context.refresh(); AnnotationConfigUtils.registerAnnotationConfigProcessors((BeanDefinitionRegistry) context.getBeanFactory()); context.registerShutdownHook(); return context; }