java - Null Pointer when running Junit4 with Struts 2.3.12 and Spring 3.1.1 -


i trying develop junit4 test scripts our application uses spring 3.2.2 , struts 2.3.12. think close getting working reason when executeaction called or getactionproxy called getting null pointer error because method not exist. not passing correct uri? or more missing. maven project of using following:

struts2-junit-plugin-2.3.13.jar struts 2.3.12 (core, spring plugin, dojo plugin, json plugin, sitemesh plugin) spring 3.2.2 (core, web, context, expression, context-support, aop, aspects, test)

this simple test:

package com.execupharm.lms.web.action.administration.test;  import static org.junit.assert.assertfalse;  import org.apache.struts2.strutsspringjunit4testcase; import org.junit.test; import org.junit.runner.runwith; import org.springframework.test.context.contextconfiguration; import org.springframework.test.context.junit4.springjunit4classrunner;  import com.execupharm.lms.web.action.administration.dashboardaction;  @runwith(springjunit4classrunner.class) @contextconfiguration( { "classpath:applicationcontextweb.xml", "classpath:applicationcontextsecurity.xml",                          "classpath:applicationcontextservice.xml",                          "classpath:applicationcontextdao.xml",                          "classpath:applicationcontextmail.xml" }) public class dashboardactiontest extends strutsspringjunit4testcase<dashboardaction> {     @test     public void executetest() throws exception {         string result = executeaction("/administration/dashboard.action");         system.out.println("result = " + result);         //dashboardaction action = getaction();         assertfalse(containserrors());     }      /**      * override method return comma separated list of paths         configuration      * file.      * <p>the default implementation returns <code>null</code>.      *      * @return comma separated list of config locations      */     @override     protected string getconfigpath() {         return "classpath:struts.xml";      } } 

all of our context*.xml files in src/main/resources folder:

applicationcontextdao.xml applicationcontextmail.xml applicationcontextsecurity.xml applicationcontextservice.xml applicationcontextweb.xml struts.xml 

this our struts file:

<?xml version="1.0" encoding="utf-8"?> <!doctype struts public "-//apache software foundation//dtd struts configuration 2.0//en"     "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts>     <!-- constants -->           <constant name="struts.locale" value="en"/>         <constant name="struts.devmode" value="false" />         <constant name="struts.i18n.encoding" value="utf-8" />         <constant name="struts.action.extension" value="action" />         <constant name="struts.objectfactory" value="spring" />         <constant name="struts.objectfactory.spring.autowire" value="name" />         <constant name="struts.objectfactory.spring.useclasscache" value="true" />         <constant name="struts.custom.i18n.resources" value="app_resources" />         <constant name="struts.multipart.maxsize" value="12000000" />         <constant name="struts.multipart.savedir" value="/lms_media" />         <constant name="struts.multipart.parser" value="jakarta" />         <constant name="struts.codebehind.pathprefix" value="/web-inf/jsp/" />         <constant name="struts.enable.slashesinactionnames" value="true" />         <constant name="struts.url.http.port" value="80" />         <constant name="struts.date.format" value="mm/dd/yyyy" />      <!-- configuration default package. -->     <package name="default" extends="struts-default,json-default" namespace="/">          <interceptors>             <interceptor name="permissionsinterceptor"                 class="com.execupharm.lms.web.interceptor.permissionsinterceptor" />             <interceptor name="employeeidresolverinterceptor"                 class="com.execupharm.lms.web.interceptor.employeeidresolverinterceptor" />             <!--                 copied struts-default.xml , changed validation exclude                 methods             -->             <interceptor-stack name="defaultstack">                 <interceptor-ref name="exception">                     <param name="logenabled">true</param>                     <param name="loglevel">error</param>                     <param name="logcategory">com.execupharm.lms</param>                 </interceptor-ref>                 <interceptor-ref name="alias" />                 <interceptor-ref name="servletconfig" />                 <interceptor-ref name="params">                     <!--                         excludes jquery no-cache _ parameter , our own search.                         params                     -->                     <param name="excludeparams">                         _,search\..*                      </param>                 </interceptor-ref>                 <interceptor-ref name="prepare" />                 <interceptor-ref name="i18n" />                 <interceptor-ref name="chain" />                 <interceptor-ref name="debugging" />                 <interceptor-ref name="profiling" />                 <interceptor-ref name="scopedmodeldriven" />                 <interceptor-ref name="modeldriven" />                 <interceptor-ref name="fileupload" />                 <interceptor-ref name="checkbox" />                 <interceptor-ref name="staticparams" />                 <interceptor-ref name="params">                     <param name="excludeparams">dojo\..*</param>                 </interceptor-ref>                 <interceptor-ref name="conversionerror" />                 <interceptor-ref name="validation">                     <param name="excludemethods">cancel,execute,delete,edit,list</param>                 </interceptor-ref>                 <interceptor-ref name="workflow">                     <param name="excludemethods">input,back,cancel,browse,execute</param>                 </interceptor-ref>                 <interceptor-ref name="permissionsinterceptor" />                 <interceptor-ref name="employeeidresolverinterceptor" />             </interceptor-stack>         </interceptors>          <global-results>             <result name="error">/error.jsp</result>             <result name="forbidden">/forbidden.jsp</result>         </global-results>          <action name="login" class="loginaction">             <result name="success">/login.jsp</result>         </action>          <action name="logout" class="logoutaction">             <result name="success" type="redirect">/login.action</result>         </action>        </package>       <!-- end default package -->      <!-- administration -->      <package name="administration" extends="default" namespace="/administration">         <action name="dashboard" class="dashboardaction">                 <result name="success">/web-inf/jsp/administration/dashboard.jsp                 </result>             </action>               <action name="addtraining" class="addtrainingaction">                 <result name="success">/web-inf/jsp/training/addtraining.jsp                 </result>             </action>               <action name="searchsops" class="searchsopsaction">                 <result name="success">/web-inf/jsp/training/searchsops.jsp                 </result>             </action>               <action name="searchtests" class="searchtestsaction">                 <result name="success">/web-inf/jsp/training/searchtests.jsp                 </result>             </action>                <action name="viewtraining" class="viewtrainingaction">                 <result name="success">/web-inf/jsp/training/viewtraining.jsp                 </result>             </action>              <action name="viewsop" class="viewsopaction">                 <result name="success">/web-inf/jsp/training/viewsop.jsp                 </result>             </action>              <action name="viewsopsave" class="viewsopaction" method="save">                 <result name="input">/web-inf/jsp/training/viewsop.jsp                 </result>                 <result name="success" type="redirect">dashboard.action                 </result>             </action>                     <action name="viewtest" class="viewtestaction">                 <result name="success">/web-inf/jsp/training/viewtest.jsp                 </result>             </action>                <action name="viewmedia" class="viewmediaaction">                 <result name="success">/web-inf/jsp/training/viewmedia.jsp                 </result>             </action>      </package>        <package name="training" extends="default" namespace="/training">                     </package>    </struts> 

applicationcontextweb.xml

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"     xsi:schemalocation="http://www.springframework.org/schema/beans          http://www.springframework.org/schema/beans/spring-beans-3.1.xsd     http://www.springframework.org/schema/tx      http://www.springframework.org/schema/tx/spring-tx-3.1.xsd     http://www.springframework.org/schema/util      http://www.springframework.org/schema/util/spring-util-3.1.xsd     http://www.springframework.org/schema/aop      http://www.springframework.org/schema/aop/spring-aop-3.1.xsd      http://www.springframework.org/schema/context      http://www.springframework.org/schema/context/spring-context-3.1.xsd">      <bean id="loginaction" class="com.execupharm.lms.web.action.loginaction" scope="prototype"/>     <bean id="logoutaction" class="com.execupharm.lms.web.action.logoutaction" scope="prototype"/>      <bean class="org.springframework.beans.factory.annotation.requiredannotationbeanpostprocessor"/>     <context:annotation-config />      <bean id="dashboardaction" class="com.execupharm.lms.web.action.administration.dashboardaction" scope="prototype" />      <bean id="addtrainingaction" class="com.execupharm.lms.web.action.training.addtrainingaction" scope="prototype" />      <bean id="searchsopsaction" class="com.execupharm.lms.web.action.training.searchsopsaction" scope="prototype" />     <bean id="searchtestsaction" class="com.execupharm.lms.web.action.training.searchtestsaction" scope="prototype" />     <bean id="viewtrainingaction" class="com.execupharm.lms.web.action.training.viewtrainingaction" scope="prototype" />     <bean id="viewsopaction" class="com.execupharm.lms.web.action.training.viewsopaction" scope="prototype" />     <bean id="viewtestaction" class="com.execupharm.lms.web.action.training.viewtestaction" scope="prototype" />     <bean id="viewmediaaction" class="com.execupharm.lms.web.action.training.viewmediaaction" scope="prototype" />  </beans> 

this error getting getting:

java.lang.nullpointerexception     @ org.apache.struts2.impl.strutsactionproxy.geterrormessage(strutsactionproxy.java:69)     @ com.opensymphony.xwork2.defaultactionproxy.prepare(defaultactionproxy.java:185)     @ org.apache.struts2.impl.strutsactionproxy.prepare(strutsactionproxy.java:63)     @ org.apache.struts2.impl.strutsactionproxyfactory.createactionproxy(strutsactionproxyfactory.java:39)     @ com.opensymphony.xwork2.defaultactionproxyfactory.createactionproxy(defaultactionproxyfactory.java:58)     @ org.apache.struts2.strutsjunit4testcase.getactionproxy(strutsjunit4testcase.java:149)     @ com.execupharm.lms.web.action.administration.test.dashboardactiontest.executetest(dashboardactiontest.java:24)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25)     @ java.lang.reflect.method.invoke(method.java:597)     @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:47)     @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:12)     @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:44)     @ org.junit.internal.runners.statements.invokemethod.evaluate(invokemethod.java:17)     @ org.junit.internal.runners.statements.runbefores.evaluate(runbefores.java:26)     @ org.springframework.test.context.junit4.statements.runbeforetestmethodcallbacks.evaluate(runbeforetestmethodcallbacks.java:74)     @ org.junit.internal.runners.statements.runafters.evaluate(runafters.java:27)     @ org.springframework.test.context.junit4.statements.runaftertestmethodcallbacks.evaluate(runaftertestmethodcallbacks.java:83)     @ org.springframework.test.context.junit4.statements.springrepeat.evaluate(springrepeat.java:72)     @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:231)     @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:88)     @ org.junit.runners.parentrunner$3.run(parentrunner.java:238)     @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:63)     @ org.junit.runners.parentrunner.runchildren(parentrunner.java:236)     @ org.junit.runners.parentrunner.access$000(parentrunner.java:53)     @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:229)     @ org.springframework.test.context.junit4.statements.runbeforetestclasscallbacks.evaluate(runbeforetestclasscallbacks.java:61)     @ org.springframework.test.context.junit4.statements.runaftertestclasscallbacks.evaluate(runaftertestclasscallbacks.java:71)     @ org.junit.runners.parentrunner.run(parentrunner.java:309)     @ org.springframework.test.context.junit4.springjunit4classrunner.run(springjunit4classrunner.java:174)     @ org.eclipse.jdt.internal.junit4.runner.junit4testreference.run(junit4testreference.java:50)     @ org.eclipse.jdt.internal.junit.runner.testexecution.run(testexecution.java:38)     @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:467)     @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:683)     @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.run(remotetestrunner.java:390)     @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.main(remotetestrunner.java:197) 

i have tried calling executeaction following well:

string result = executeaction("/administration/dashboard.action"); string result = executeaction("/dashboardaction"); string result = executeaction("/administration/dashboard"); 

maybe need take new approach this. thought plugin going make easy, not looking that.

thanks!

i wouldn't call unit test if have struts , spring involved. that's integration test.

looks me containserrors() method in assert isn't checking see if errors null.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -