1. Perform unit tests using the 2.8.1struts2-JUnit-plugin provided by struts2.
Maven package:
<Dependency>
<Groupid> org. Apache. Struts </groupid>
<Artifactid> struts2-junit-plugin </artifactid>
<Version> 2.1.8 </version>
</Dependency>
<Dependency>
<Groupid> aspectj </groupid>
<Artifactid> aspectjweaver </artifactid>
<Version> 1.5.3 </version>
</Dependency>
TestCode:
Import COM. opensymphony. xwork2.action; import COM. opensymphony. xwork2.actionproxy; public class testmultitaskaction extends strutsspringtestcase {Public String getcontextlocations () {return "classpath *: COM/fsti/mailmanager/config/spring/applicationcontext -*. XML ";} // public void testgetactionmapping () throws exception {// actionmapping mapping = getactionmapping ("/multicasttask! Emailmulticasttasksaveandupdate. action "); // assertnotnull (Mapping); // assertequals ("/begin ", mapping. getnamespace (); // assertequals ("multicasttask", mapping. getname (); //} public void testgetactionproxy () throws exception {// request httpsession session = new mockhttpsession (); String sessionid = UUID. randomuuid (). tostring (); Session. setattribute (constparameter. user_session, sessionid); Request. setsession (session); Request. setparameter ("subject", "test"); Request. setparameter ("content", "testcontent"); Request. setparameter ("serviceid", "1000000000"); Request. setparameter ("curruseraccount", "sys"); Request. setparameter ("mailtypeid", "1000000031"); Request. setparameter ("mailtypeid", "1000000031"); Request. setparameter ("Se Ndtime "," 2011-06-30 "); Request. setparameter ("startdate", new string [] {"08:30", "13:00"}); Request. setparameter ("enddate", new string [] {"12:30", "18:00"}); Request. setparameter ("groupids", new string [] {"1000000870"}); Request. setparameter ("flag", "add"); Request. setparameter ("creator", "sys"); Request. setparameter ("currusergroup", "isp_sys"); actionproxy proxy = getactionproxy ("/multicasttask/multic Asttask! Emailmulticasttasksaveandupdate. action "); assertnotnull (proxy); multicasttaskaction action = (multicasttaskaction) proxy. getaction (); assertnotnull (action); string result = proxy.exe cute (); assertequals (action. success, result );}}
If you encounter: there is no action mapping... refer to this article.Article:
There is no Action mapped for action
Favorites
After struts2 configures multiple configuration files, it always reports there is no action mapped for action
After checking for a long time, I found the namespace problem:
Originally:
Struts2 configuration file: <package name = "admin" extends = "struts-Default" namespace ="Admin">
JSP: <s: Form Action = "adminuseraction" method = "Post" namespace ="Admin">
After correction:
Struts2 configuration file: <package name = "admin" extends = "struts-Default" namespace= "/Admin">
JSP: <s: Form Action = "adminuseraction" method = "Post" namespace= "/Admin">
Struts2 import file path:
The main struts2 file is introduced to the struts2 file of other branches. During the page test, the following path is valid.
<Include file= "/CN/AO/Action/admin/struts. xml "> </include>
However, in JUnit testing:
Run getactionproxy ("/admin/adminuseraction. Action ")
Error: there is no action mapped for action
Modify the following lines to test the page and JUnit.
<Include file ="CN/AO/Action/admin/struts. xml "> </include>
It seems that it is generally the path or file name of the configuration file!