use of org.apache.struts2.spring.StrutsSpringObjectFactory 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);
}
Aggregations