You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by 覃洪军 <fs...@gmail.com> on 2012/04/03 13:11:03 UTC

Why doesn't StrutsJunit4TestCase invoke index() method

---------- 已转发邮件 ----------
发件人: 覃洪军 <fs...@gmail.com>
日期: 2012年4月3日 下午7:06
主题: Why doesn't StrutsJunit4TestCase invoke index() method
收件人: user-info@struts.apache.org


---------- Forwarded message ----------
From: 覃洪军 <fs...@gmail.com>
Date: 2012/4/3
Subject: Why doesn't StrutsJunit4TestCase invoke index() method
To: user-faq@struts.apache.org


Hi, I wrote a test for a web application with Struts2 REST, and got a
error message:

"java.lang.NoSuchMethodException:
cn.fshk.stock.struts.biz.admin.AuthorizationController.execute()"

Dose it suppose to invoke the index() method in a Struts2 REST controller?

Can anyone give me some help?

* The test 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);
   }

}



* The struts.xml fragment:

 ...
<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

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Why doesn't StrutsJunit4TestCase invoke index() method

Posted by Tsin Eduardo <fs...@gmail.com>.
I found out where is my problem:

I should set the request method to be "GET"  explicitly.

e.g.

request.setMethod("GET");
excuteAction( myUrl);



2012/4/4 Tsin Eduardo <fs...@gmail.com>:
> Hi,  Łukasz, I configurate as <constant name="struts.mapper.class"
> value="rest" /> early, I got that error too.
>
> Thank you for the reply anyway.
>
> Best Regards
>
> 2012/4/4 Łukasz Lenart <lu...@googlemail.com>:
>>>  <constant name="struts.mapper.class"
>>> value="org.apache.struts2.rest.RestActionMapper" />
>>
>> It should be rather
>>
>> <constant name="struts.mapper.class" value="rest" />
>>
>>
>> Kind regards
>> --
>> Łukasz http://www.lenart.org.pl/
>> mobile +48 606 323 122, office +27 11 0838747
>> Warszawa JUG conference - Confitura http://confitura.pl/
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Why doesn't StrutsJunit4TestCase invoke index() method

Posted by Tsin Eduardo <fs...@gmail.com>.
Hi,  Łukasz, I configurate as <constant name="struts.mapper.class"
value="rest" /> early, I got that error too.

Thank you for the reply anyway.

Best Regards

2012/4/4 Łukasz Lenart <lu...@googlemail.com>:
>>  <constant name="struts.mapper.class"
>> value="org.apache.struts2.rest.RestActionMapper" />
>
> It should be rather
>
> <constant name="struts.mapper.class" value="rest" />
>
>
> Kind regards
> --
> Łukasz http://www.lenart.org.pl/
> mobile +48 606 323 122, office +27 11 0838747
> Warszawa JUG conference - Confitura http://confitura.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Why doesn't StrutsJunit4TestCase invoke index() method

Posted by Łukasz Lenart <lu...@googlemail.com>.
>  <constant name="struts.mapper.class"
> value="org.apache.struts2.rest.RestActionMapper" />

It should be rather

<constant name="struts.mapper.class" value="rest" />


Kind regards
-- 
Łukasz http://www.lenart.org.pl/
mobile +48 606 323 122, office +27 11 0838747
Warszawa JUG conference - Confitura http://confitura.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org