Note that there are some explanatory texts on larger screens.

plurals
  1. PONull Pointer when running Junit4 with Struts 2.3.12 and Spring 3.1.1
    primarykey
    data
    text
    <p>I am trying to develop JUnit4 test scripts for our application that uses Spring 3.2.2 and Struts 2.3.12. I think I am close to getting this working but for some reason when executeAction is called or getActionProxy is called I am getting a null pointer error because method does not exist. Am I not passing the correct uri? or is it something more I am missing. This is a maven project so all of the I am using the following:</p> <p>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)</p> <p>This is my simple test:</p> <pre><code>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&lt;DashboardAction&gt; { @Test public void executeTest() throws Exception { String result = executeAction("/administration/dashboard.action"); System.out.println("result = " + result); //DashboardAction action = getAction(); assertFalse(containsErrors()); } /** * Override this method to return a comma separated list of paths to a configuration * file. * &lt;p&gt;The default implementation simply returns &lt;code&gt;null&lt;/code&gt;. * * @return a comma separated list of config locations */ @Override protected String getConfigPath() { return "classpath:struts.xml"; } } </code></pre> <p>All of our context*.xml files are in the src/main/resources folder:</p> <pre><code>applicationContextDao.xml applicationContextMail.xml applicationContextSecurity.xml applicationContextService.xml applicationContextWeb.xml struts.xml </code></pre> <p>This is our struts file:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"&gt; &lt;struts&gt; &lt;!-- Constants --&gt; &lt;constant name="struts.locale" value="en"/&gt; &lt;constant name="struts.devMode" value="false" /&gt; &lt;constant name="struts.i18n.encoding" value="UTF-8" /&gt; &lt;constant name="struts.action.extension" value="action" /&gt; &lt;constant name="struts.objectFactory" value="spring" /&gt; &lt;constant name="struts.objectFactory.spring.autoWire" value="name" /&gt; &lt;constant name="struts.objectFactory.spring.useClassCache" value="true" /&gt; &lt;constant name="struts.custom.i18n.resources" value="app_resources" /&gt; &lt;constant name="struts.multipart.maxSize" value="12000000" /&gt; &lt;constant name="struts.multipart.saveDir" value="/LMS_Media" /&gt; &lt;constant name="struts.multipart.parser" value="jakarta" /&gt; &lt;constant name="struts.codebehind.pathPrefix" value="/WEB-INF/jsp/" /&gt; &lt;constant name="struts.enable.SlashesInActionNames" value="true" /&gt; &lt;constant name="struts.url.http.port" value="80" /&gt; &lt;constant name="struts.date.format" value="MM/dd/yyyy" /&gt; &lt;!-- Configuration for the default package. --&gt; &lt;package name="default" extends="struts-default,json-default" namespace="/"&gt; &lt;interceptors&gt; &lt;interceptor name="permissionsInterceptor" class="com.execupharm.lms.web.interceptor.PermissionsInterceptor" /&gt; &lt;interceptor name="employeeIdResolverInterceptor" class="com.execupharm.lms.web.interceptor.EmployeeIdResolverInterceptor" /&gt; &lt;!-- Copied from struts-default.xml and changed validation exclude methods --&gt; &lt;interceptor-stack name="defaultStack"&gt; &lt;interceptor-ref name="exception"&gt; &lt;param name="logEnabled"&gt;true&lt;/param&gt; &lt;param name="logLevel"&gt;ERROR&lt;/param&gt; &lt;param name="logCategory"&gt;com.execupharm.lms&lt;/param&gt; &lt;/interceptor-ref&gt; &lt;interceptor-ref name="alias" /&gt; &lt;interceptor-ref name="servletConfig" /&gt; &lt;interceptor-ref name="params"&gt; &lt;!-- Excludes the jQuery no-cache _ parameter and our own search. params --&gt; &lt;param name="excludeParams"&gt; _,search\..* &lt;/param&gt; &lt;/interceptor-ref&gt; &lt;interceptor-ref name="prepare" /&gt; &lt;interceptor-ref name="i18n" /&gt; &lt;interceptor-ref name="chain" /&gt; &lt;interceptor-ref name="debugging" /&gt; &lt;interceptor-ref name="profiling" /&gt; &lt;interceptor-ref name="scopedModelDriven" /&gt; &lt;interceptor-ref name="modelDriven" /&gt; &lt;interceptor-ref name="fileUpload" /&gt; &lt;interceptor-ref name="checkbox" /&gt; &lt;interceptor-ref name="staticParams" /&gt; &lt;interceptor-ref name="params"&gt; &lt;param name="excludeParams"&gt;dojo\..*&lt;/param&gt; &lt;/interceptor-ref&gt; &lt;interceptor-ref name="conversionError" /&gt; &lt;interceptor-ref name="validation"&gt; &lt;param name="excludeMethods"&gt;cancel,execute,delete,edit,list&lt;/param&gt; &lt;/interceptor-ref&gt; &lt;interceptor-ref name="workflow"&gt; &lt;param name="excludeMethods"&gt;input,back,cancel,browse,execute&lt;/param&gt; &lt;/interceptor-ref&gt; &lt;interceptor-ref name="permissionsInterceptor" /&gt; &lt;interceptor-ref name="employeeIdResolverInterceptor" /&gt; &lt;/interceptor-stack&gt; &lt;/interceptors&gt; &lt;global-results&gt; &lt;result name="error"&gt;/error.jsp&lt;/result&gt; &lt;result name="forbidden"&gt;/forbidden.jsp&lt;/result&gt; &lt;/global-results&gt; &lt;action name="login" class="loginAction"&gt; &lt;result name="success"&gt;/login.jsp&lt;/result&gt; &lt;/action&gt; &lt;action name="logout" class="logoutAction"&gt; &lt;result name="success" type="redirect"&gt;/login.action&lt;/result&gt; &lt;/action&gt; &lt;/package&gt; &lt;!-- End Default Package --&gt; &lt;!-- Administration --&gt; &lt;package name="administration" extends="default" namespace="/administration"&gt; &lt;action name="dashboard" class="dashboardAction"&gt; &lt;result name="success"&gt;/WEB-INF/jsp/administration/dashboard.jsp &lt;/result&gt; &lt;/action&gt; &lt;action name="addTraining" class="addTrainingAction"&gt; &lt;result name="success"&gt;/WEB-INF/jsp/training/addTraining.jsp &lt;/result&gt; &lt;/action&gt; &lt;action name="searchSOPs" class="searchSOPsAction"&gt; &lt;result name="success"&gt;/WEB-INF/jsp/training/searchSOPs.jsp &lt;/result&gt; &lt;/action&gt; &lt;action name="searchTests" class="searchTestsAction"&gt; &lt;result name="success"&gt;/WEB-INF/jsp/training/searchTests.jsp &lt;/result&gt; &lt;/action&gt; &lt;action name="viewTraining" class="viewTrainingAction"&gt; &lt;result name="success"&gt;/WEB-INF/jsp/training/viewTraining.jsp &lt;/result&gt; &lt;/action&gt; &lt;action name="viewSOP" class="viewSOPAction"&gt; &lt;result name="success"&gt;/WEB-INF/jsp/training/viewSOP.jsp &lt;/result&gt; &lt;/action&gt; &lt;action name="viewSOPSave" class="viewSOPAction" method="save"&gt; &lt;result name="input"&gt;/WEB-INF/jsp/training/viewSOP.jsp &lt;/result&gt; &lt;result name="success" type="redirect"&gt;dashboard.action &lt;/result&gt; &lt;/action&gt; &lt;action name="viewTest" class="viewTestAction"&gt; &lt;result name="success"&gt;/WEB-INF/jsp/training/viewTest.jsp &lt;/result&gt; &lt;/action&gt; &lt;action name="viewMedia" class="viewMediaAction"&gt; &lt;result name="success"&gt;/WEB-INF/jsp/training/viewMedia.jsp &lt;/result&gt; &lt;/action&gt; &lt;/package&gt; &lt;package name="training" extends="default" namespace="/training"&gt; &lt;/package&gt; &lt;/struts&gt; </code></pre> <p>applicationContextWeb.xml</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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"&gt; &lt;bean id="loginAction" class="com.execupharm.lms.web.action.LoginAction" scope="prototype"/&gt; &lt;bean id="logoutAction" class="com.execupharm.lms.web.action.LogoutAction" scope="prototype"/&gt; &lt;bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/&gt; &lt;context:annotation-config /&gt; &lt;bean id="dashboardAction" class="com.execupharm.lms.web.action.administration.DashboardAction" scope="prototype" /&gt; &lt;bean id="addTrainingAction" class="com.execupharm.lms.web.action.training.AddTrainingAction" scope="prototype" /&gt; &lt;bean id="searchSOPsAction" class="com.execupharm.lms.web.action.training.SearchSOPsAction" scope="prototype" /&gt; &lt;bean id="searchTestsAction" class="com.execupharm.lms.web.action.training.SearchTestsAction" scope="prototype" /&gt; &lt;bean id="viewTrainingAction" class="com.execupharm.lms.web.action.training.ViewTrainingAction" scope="prototype" /&gt; &lt;bean id="viewSOPAction" class="com.execupharm.lms.web.action.training.ViewSOPAction" scope="prototype" /&gt; &lt;bean id="viewTestAction" class="com.execupharm.lms.web.action.training.ViewTestAction" scope="prototype" /&gt; &lt;bean id="viewMediaAction" class="com.execupharm.lms.web.action.training.ViewMediaAction" scope="prototype" /&gt; &lt;/beans&gt; </code></pre> <p>This is the error we are getting that we are getting:</p> <pre><code>java.lang.NullPointerException at org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69) at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185) at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63) at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39) at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58) at org.apache.struts2.StrutsJUnit4TestCase.getActionProxy(StrutsJUnit4TestCase.java:149) at com.execupharm.lms.web.action.administration.test.DashboardActionTest.executeTest(DashboardActionTest.java:24) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) </code></pre> <p>I have tried calling the executeAction with the following as well:</p> <pre><code>String result = executeAction("/administration/dashboard.action"); String result = executeAction("/dashboardAction"); String result = executeAction("/administration/dashboard"); </code></pre> <p>Maybe I need to take a new approach to this. Just thought the plugin was going to make this easy, but it is not looking like that.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload