List of usage examples for org.springframework.core.io FileSystemResourceLoader FileSystemResourceLoader
FileSystemResourceLoader
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 w w .j av a 2 s . c o m applicationContext.refresh(); } catch (Throwable e) { e.printStackTrace(); } handler = (GWTHandler) applicationContext.getBean("urlMapping", GWTHandler.class); }
From source file:org.kuali.rice.test.RiceTestCase.java
/** * configures logging using custom properties file if specified, or the default one. * Log4j also uses any file called log4.properties in the classpath * * <p>To configure a custom logging file, set a JVM system property on using -D. For example * -Dalt.log4j.config.location=file:/home/me/kuali/test/dev/log4j.properties * </p>// w ww .j a va 2 s . c o m * * <p>The above option can also be set in the run configuration for the unit test in the IDE. * To avoid log4j using files called log4j.properties that are defined in the classpath, add the following system property: * -Dlog4j.defaultInitOverride=true * </p> * @throws IOException */ protected void configureLogging() throws IOException { ResourceLoader resourceLoader = new FileSystemResourceLoader(); String altLog4jConfigLocation = System.getProperty(ALT_LOG4J_CONFIG_LOCATION_PROP); Resource log4jConfigResource = null; if (!StringUtils.isEmpty(altLog4jConfigLocation)) { log4jConfigResource = resourceLoader.getResource(altLog4jConfigLocation); } if (log4jConfigResource == null || !log4jConfigResource.exists()) { System.out.println("Alternate Log4j config resource does not exist! " + altLog4jConfigLocation); System.out.println("Using default log4j configuration: " + DEFAULT_LOG4J_CONFIG); log4jConfigResource = resourceLoader.getResource(DEFAULT_LOG4J_CONFIG); } else { System.out.println("Using alternate log4j configuration at: " + altLog4jConfigLocation); } Properties p = new Properties(); p.load(log4jConfigResource.getInputStream()); PropertyConfigurator.configure(p); }
From source file:org.springframework.test.context.support.AbstractGenericWebContextLoader.java
/** * TODO [SPR-9864] Document configureWebResources(). *///from ww w . ja v a 2 s.com protected void configureWebResources(GenericWebApplicationContext context, WebMergedContextConfiguration webMergedConfig) { String resourceBasePath = webMergedConfig.getResourceBasePath(); ResourceLoader resourceLoader = resourceBasePath.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX) ? new DefaultResourceLoader() : new FileSystemResourceLoader(); ServletContext servletContext = new MockServletContext(resourceBasePath, resourceLoader); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context); context.setServletContext(servletContext); }
From source file:org.springframework.test.context.web.AbstractGenericWebContextLoader.java
/** * Configures web resources for the supplied web application context (WAC). * <h4>Implementation Details</h4> * <p>If the supplied WAC has no parent or its parent is not a WAC, the * supplied WAC will be configured as the Root WAC (see "<em>Root WAC * Configuration</em>" below).//w w w . j a v a2 s . c om * <p>Otherwise the context hierarchy of the supplied WAC will be traversed * to find the top-most WAC (i.e., the root); and the {@link ServletContext} * of the Root WAC will be set as the {@code ServletContext} for the supplied * WAC. * <h4>Root WAC Configuration</h4> * <ul> * <li>The resource base path is retrieved from the supplied * {@code WebMergedContextConfiguration}.</li> * <li>A {@link ResourceLoader} is instantiated for the {@link MockServletContext}: * if the resource base path is prefixed with "{@code classpath:}", a * {@link DefaultResourceLoader} will be used; otherwise, a * {@link FileSystemResourceLoader} will be used.</li> * <li>A {@code MockServletContext} will be created using the resource base * path and resource loader.</li> * <li>The supplied {@link GenericWebApplicationContext} is then stored in * the {@code MockServletContext} under the * {@link WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE} key.</li> * <li>Finally, the {@code MockServletContext} is set in the * {@code WebApplicationContext}.</li> * @param context the web application context for which to configure the web resources * @param webMergedConfig the merged context configuration to use to load the web application context */ protected void configureWebResources(GenericWebApplicationContext context, WebMergedContextConfiguration webMergedConfig) { ApplicationContext parent = context.getParent(); // If the WebApplicationContext has no parent or the parent is not a WebApplicationContext, // set the current context as the root WebApplicationContext: if (parent == null || (!(parent instanceof WebApplicationContext))) { String resourceBasePath = webMergedConfig.getResourceBasePath(); ResourceLoader resourceLoader = (resourceBasePath.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX) ? new DefaultResourceLoader() : new FileSystemResourceLoader()); ServletContext servletContext = new MockServletContext(resourceBasePath, resourceLoader); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context); context.setServletContext(servletContext); } else { ServletContext servletContext = null; // Find the root WebApplicationContext while (parent != null) { if (parent instanceof WebApplicationContext && !(parent.getParent() instanceof WebApplicationContext)) { servletContext = ((WebApplicationContext) parent).getServletContext(); break; } parent = parent.getParent(); } Assert.state(servletContext != null, "Failed to find root WebApplicationContext in the context hierarchy"); context.setServletContext(servletContext); } }
From source file:org.springframework.web.util.Log4jWebConfigurerTests.java
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"); }//from w ww. j a v a 2s.com Log4jWebConfigurer.initLogging(sc); try { assertLogOutput(); } finally { Log4jWebConfigurer.shutdownLogging(sc); } assertTrue(MockLog4jAppender.closeCalled); }
From source file:org.springframework.web.util.Log4jWebConfigurerTests.java
@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 {/* w ww. j a va2 s . c o m*/ assertLogOutput(); } finally { listener.contextDestroyed(new ServletContextEvent(sc)); } assertTrue(MockLog4jAppender.closeCalled); }