use of org.springframework.core.io.FileSystemResourceLoader in project entando-core by entando.
the class ApsAdminBaseTestCase method setUp.
@Override
protected void setUp() throws Exception {
boolean refresh = false;
if (null == applicationContext) {
// Link the servlet context and the Spring context
servletContext = new MockServletContext("", new FileSystemResourceLoader());
applicationContext = this.getConfigUtils().createApplicationContext(servletContext);
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext);
} else {
refresh = true;
}
RequestContext reqCtx = BaseTestCase.createRequestContext(applicationContext, servletContext);
this.request = new MockHttpServletRequest();
this.request.setAttribute(RequestContext.REQCTX, reqCtx);
this.response = new MockHttpServletResponse();
this.request.setSession(new MockHttpSession(servletContext));
if (refresh) {
try {
ApsWebApplicationUtils.executeSystemRefresh(this.request);
this.waitNotifyingThread();
} catch (Throwable e) {
}
}
// Use spring as the object factory for Struts
StrutsSpringObjectFactory ssf = new StrutsSpringObjectFactory(null, null, null, null, servletContext, null, this.createContainer());
ssf.setApplicationContext(applicationContext);
// Dispatcher is the guy that actually handles all requests. Pass in
// an empty Map as the parameters but if you want to change stuff like
// what config files to read, you need to specify them here
// (see Dispatcher's source code)
java.net.URL url = ClassLoader.getSystemResource("struts.properties");
Properties props = new Properties();
props.load(url.openStream());
this.setInitParameters(props);
Map params = new HashMap(props);
this.dispatcher = new Dispatcher(servletContext, params);
this.dispatcher.init();
Dispatcher.setInstance(this.dispatcher);
}
use of org.springframework.core.io.FileSystemResourceLoader in project entando-core by entando.
the class BaseTestCase method setUp.
@Override
protected void setUp() throws Exception {
try {
super.setUp();
ServletContext srvCtx = new MockServletContext("", new FileSystemResourceLoader());
ApplicationContext applicationContext = this.getConfigUtils().createApplicationContext(srvCtx);
this.setApplicationContext(applicationContext);
RequestContext reqCtx = createRequestContext(applicationContext, srvCtx);
this.setRequestContext(reqCtx);
this.setUserOnSession("guest");
} catch (Exception e) {
throw e;
}
}
use of org.springframework.core.io.FileSystemResourceLoader in project entando-core by entando.
the class UserProfileManagerTest method setUp.
@Before
public void setUp() throws Exception {
MockServletContext servletContext = new MockServletContext("", new FileSystemResourceLoader());
new ConfigTestUtils().createApplicationContext(servletContext);
MockitoAnnotations.initMocks(this);
this.userProfileManager.setEntityClassName(className);
this.userProfileManager.setConfigItemName(configItemName);
this.userProfileManager.setBeanName(this.beanName);
}
use of org.springframework.core.io.FileSystemResourceLoader in project spring-framework by spring-projects.
the class AbstractGenericWebContextLoader method configureWebResources.
/**
* 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).
* <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>
* </ul>
* @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();
// set the current context as the root WebApplicationContext:
if (!(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);
}
}
use of org.springframework.core.io.FileSystemResourceLoader in project spring-framework by spring-projects.
the class WebMvcConfigurationSupportExtensionTests method setUp.
@BeforeEach
public void setUp() {
this.context = new StaticWebApplicationContext();
this.context.setServletContext(new MockServletContext(new FileSystemResourceLoader()));
this.context.registerSingleton("controller", TestController.class);
this.context.registerSingleton("userController", UserController.class);
this.config = new TestWebMvcConfigurationSupport();
this.config.setApplicationContext(this.context);
this.config.setServletContext(this.context.getServletContext());
}
Aggregations