I am trying to write JUnit test cases for an application written in Struts2. I am trying to follow the process given in these 2 links :
https://struts.apache.org/docs/testing-actions.html
https://glindholm.wordpress.com/2008/06/30/unit-testing-struts-2-actions/
I am using mockrunner-servlet.jar, struts2-junit-plugin-2.3.15.jar, junit-4.8.2.jar apart from many other jars.
Basically the problem that I am facing is at these 2 places in both the approaches :
ActionProxy proxy = getActionProxy("/<namespace>/<action-name>");
and
dispatcher.getContainer() .getInstance(ActionProxyFactory.class) .createActionProxy( namespace, actionName, null, true, // execute result false);
The exception I'm getting is :
There is no Action mapped for action name <action-name>. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
... ...
Basically I suspect that while creating proxy, it is not able to location struts.xml. The struts.xml is located in src folder. src/struts.xml
Also in struts.xml, we have included various xml files which contain the action-mappings for struts2.
struts.xml
<struts>
<constant name="struts.devMode" value="true"/>
<include file="/strutsConfig/module1/module-struts-config.xml"></include>
...
...
</struts>
I also tried to use this solution, which I found at one of the links, but still not able to resolve it.
@Override
protected String getConfigPath() {
return "struts.xml";
}
Please help me resolve this such that proxy object is created.