Announcement Announcement Module
Collapse
No announcement yet.
Struts Test Case with Spring Plugin Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Struts Test Case with Spring Plugin

    I am trying to extend MockStrutsTestCase so that the Spring Framework's plugin loads properly.

    Basically, the plugin is failing its load because an XmlWebApplicationContext hasn't been created and stored in the ServletContext. Any help in getting this to work would be greatly appreciated. Thanks, Tom Tibbetts

    I have the plugin properly defined in struts-config.xml as:
    <plug-in className="org.springframework.web.struts.ContextL oaderPlugIn">
    <set-property property="contextConfigLocation" value="/WEB-INF/spring/beanRefContext.xml" />
    </plug-in>

    and, I'm using the following code:
    public class MandatoryStrutsTestCase extends MockStrutsTestCase
    {
    protected StaticWebApplicationContext wac = null;

    /**
    * getter for WebApplicationContext.
    */
    protected StaticWebApplicationContext getWebApplicationContext() {
    return this.wac;
    }

    /**
    * finalize the initialization of the WebApplicationContext.
    */
    public void finalizeSetUp() {
    //bind the WebApplicationContext to the servletContext
    ServletContext sc = getActionServlet().getServletContext();
    wac.setServletContext(sc);

    wac.refresh();
    sc.setAttribute(StaticWebApplicationContext.ROOT_W EB_APPLICATION_CONTEXT_ATTRIBUTE, this.wac);
    }

    /**
    *
    */
    public MandatoryStrutsTestCase()
    {
    super();
    }

    /**
    * @param testName
    */
    public MandatoryStrutsTestCase(String testName)
    {
    super(testName);
    }

    public void setUp() throws Exception
    {
    super.setUp();

    ServletContextSimulator context = (ServletContextSimulator) config.getServletContext();
    context.setContextDirectory(new File("webApplication"));

    setInitParameter("validating", "false");
    wac = new StaticWebApplicationContext();
    }


    protected void tearDown() throws Exception {
    wac = null;
    super.tearDown();
    }

    }


    The file structure for Spring's definition files are:
    /WEB-INF/spring/beanRefContext.xml
    /WEB-INF/spring/spring-config.xml
    /WEB-INF/spring/spring-db.xml
    /WEB-INF/spring/spring-struts.xml
    /WEB-INF/spring/spring-quartz.xml
    /WEB-INF/spring/spring-transaction.xml


    my web.xml looks like:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
    <web-app id="WebApp">
    <display-name>mandatory</display-name>
    <context-param>
    <param-name>appName</param-name>
    <param-value>mandatory</param-value>
    </context-param>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/spring/spring-config.xml
    /WEB-INF/spring/spring-db.xml
    /WEB-INF/spring/spring-transaction.xml
    /WEB-INF/spring/spring-struts.xml
    /WEB-INF/spring/spring-quartz.xml
    </param-value>
    </context-param>
    <servlet>
    <servlet-name>action</servlet-name>
    <display-name>action</display-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
    <param-name>config</param-name>
    <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
    <param-name>debug</param-name>
    <param-value>0</param-value>
    </init-param>
    <init-param>
    <param-name>detail</param-name>
    <param-value>0</param-value>
    </init-param>
    <init-param>
    <param-name>validating</param-name>
    <param-value>false</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet>
    <servlet-name>InitServlet</servlet-name>
    <display-name>InitServlet</display-name>
    <servlet-class>com.wellsfargo.mortgage.mandatory.frontend.w eb.InitServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
    <servlet-name>ContextLoaderServlet</servlet-name>
    <display-name>ContextLoaderServlet</display-name>
    <servlet-class>org.springframework.web.context.ContextLoade rServlet</servlet-class>
    <load-on-startup>-1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <error-page>
    <error-code>500</error-code>
    <location>/error.jsp</location>
    </error-page>
    <error-page>
    <error-code>404</error-code>
    <location>/index.jsp</location>
    </error-page>
    <error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/error.jsp</location>
    </error-page>
    <taglib>
    <taglib-uri>struts-bean</taglib-uri>
    <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>struts-html</taglib-uri>
    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>struts-logic</taglib-uri>
    <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>struts-tiles</taglib-uri>
    <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>app</taglib-uri>
    <taglib-location>/WEB-INF/appl.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>displaytag</taglib-uri>
    <taglib-location>/WEB-INF/displaytag-11.tld</taglib-location>
    </taglib>
    </web-app>
Working...
X