I recently write a web application with Struts2 REST, and I ran the junit test for a Action class then I got an error:
java.lang.NoSuchMethodException: cn.fshk.stock.struts.biz.admin.AuthorizationController.execute()
But it seems to run correctly in Tomcat.
Dose it suppose to invoke the index() method in a Struts2 REST controller?
Can anyone give me some help?
here is the struts.xml
<?xml version="1.0" encoding="UTF-8"?> ... <struts> <constant name="struts.convention.action.suffix" value="Controller" /> <constant name="struts.convention.action.mapAllMatches" value="true" /> <constant name="struts.convention.default.parent.package" value="rest-default" /> <constant name="struts.convention.package.locators" value="rest,struts,struts2,action,actions" /> <constant name="struts.convention.result.path" value="/" /> <constant name="struts.convention.action.packages" value="cn.fshk.stock.struts" /> <constant name="struts.action.extension" value="action,do,,xhtml,xml,json" /> <constant name="struts.mapper.class" value="org.apache.struts2.rest.RestActionMapper" /> </struts>
The struts.properties:
struts.i18n.encoding=UTF-8 struts.objectFactory = spring struts.objectFactory.spring.autoWire = name struts.objectFactory.spring.useClassCache = true struts.multipart.parser=jakarta struts.multipart.saveDir= struts.multipart.maxSize=2097152 struts.serve.static=true struts.serve.static.browserCache=true struts.tag.altSyntax=true struts.devMode = true struts.i18n.reload=false struts.ui.theme=xhtml struts.ui.templateDir=template struts.ui.templateSuffix=ftl struts.configuration.xml.reload=false struts.url.http.port = 80 struts.url.https.port = 443 struts.custom.i18n.resources=globalmessages struts.dispatcher.parametersWorkaround = false struts.freemarker.wrapper.altMap=true struts.xslt.nocache=false
The TestCase Class
package cn.fshk.stock2.struts; ... @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath*:application*.xml" }) @TransactionConfiguration(transactionManager = "transactionManager") public class TestStrutsBase<ActionName> extends StrutsSpringJUnit4TestCase<ActionName> { Logger logger = Logger.getLogger("cn.fshk"); @Test public void testStrutsUtil() throws UnsupportedEncodingException, ServletException { String result = executeAction("/biz/admin/authorization"); logger.debug(result); } }
ok, I find out what's wrong.
I need to add
before