Search in sources :

Example 1 with StrutsSpringObjectFactory

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);
}
Also used : HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) FileSystemResourceLoader(org.springframework.core.io.FileSystemResourceLoader) Properties(java.util.Properties) Dispatcher(org.apache.struts2.dispatcher.Dispatcher) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpSession(org.springframework.mock.web.MockHttpSession) StrutsSpringObjectFactory(org.apache.struts2.spring.StrutsSpringObjectFactory) RequestContext(com.agiletec.aps.system.RequestContext) HashMap(java.util.HashMap) Map(java.util.Map) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Aggregations

RequestContext (com.agiletec.aps.system.RequestContext)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Dispatcher (org.apache.struts2.dispatcher.Dispatcher)1 StrutsSpringObjectFactory (org.apache.struts2.spring.StrutsSpringObjectFactory)1 FileSystemResourceLoader (org.springframework.core.io.FileSystemResourceLoader)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 MockHttpSession (org.springframework.mock.web.MockHttpSession)1 MockServletContext (org.springframework.mock.web.MockServletContext)1