You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Antonios Gkogkakis <gk...@tcd.ie> on 2013/06/14 13:31:33 UTC
Restful2ActionMapper tests
Hi all,
I've made a documentation contribution on the Restful2ActionMapper a few
months ago,
https://cwiki.apache.org/WW/restfulactionmapper.html
Could someone that has access to the wiki (Lukasz :D) append that, in order
to test
an action using the Restful2ActionMapper with StrutsJUnit4TestCase someone
has to
set the http method on the protected mock http object, e.g., request.
setMethod("get")
It makes sense now, but it took me a couple of hours to figure it out :D
Thanks,
Antonios
Re: Restful2ActionMapper tests
Posted by Lukasz Lenart <lu...@apache.org>.
Thanks Antonios!
Could you register an issue with the example code?
Thanks in advance
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
2013/6/16 Antonios Gkogkakis <gk...@tcd.ie>:
> I meant to add the paragraph that I sent, but it's more clear to add a unit
> test. (tested with 2.3.1.4.3)
> What I said in my previous email is that the Restful2ActionMapper cannot
> determine which action to call, just
> from the uri, it also needs the http method that should be passed in the
> request mock.
>
> note for the existing documentation : the id in "<param name="id">{0}</
> param>" should change to "<param name="id">{1}</param>"
>
> public class MovieActionTest extends StrutsJUnit4TestCase<MovieActionTest>{
>
> @Before
> public void setUp() throws Exception {
>
> //assumes Basic authentication
> super.setUp();
> String credentials = "username:password";
> request.addHeader("authorization", "BASIC " +
> Base64.encodeBase64String(credentials.getBytes()));
> }
>
>
> @Test
> public void testIndex() throws Exception {
>
>
> request.setMethod("get"); //Http method should be set
>
> ActionProxy proxy = getActionProxy("/rest/movie/");
>
>
> proxy.setExecuteResult(false);
> String result = proxy.execute();
>
> //assertions ...
>
> }
>
> @Test
> public void testView() throws Exception {
>
>
> request.setMethod("get"); //Http method should be set
>
> ActionProxy proxy = getActionProxy("/rest/movie/1");
>
> MovieAction movieAction = MovieAction.class.cast(proxy.getAction());
>
> proxy.setExecuteResult(false);
>
> String result = proxy.execute();
> //assertions ...
> assertEquals("1", movieAction.getId());
>
> }
> }
>
> Thanks,
> Antonios
>
>
> On 14 June 2013 12:36, Lukasz Lenart <lu...@apache.org> wrote:
>
>> You mean to add section about testing? Maybe it would better to show
>> sample code with sample unittest, could you post something like that
>> here?
>>
>>
>> Thanks in advance!
>> --
>> Łukasz
>> + 48 606 323 122 http://www.lenart.org.pl/
>>
>> 2013/6/14 Antonios Gkogkakis <gk...@tcd.ie>:
>> > Hi all,
>> >
>> > I've made a documentation contribution on the Restful2ActionMapper a few
>> > months ago,
>> >
>> > https://cwiki.apache.org/WW/restfulactionmapper.html
>> >
>> > Could someone that has access to the wiki (Lukasz :D) append that, in
>> order
>> > to test
>> > an action using the Restful2ActionMapper with StrutsJUnit4TestCase
>> someone
>> > has to
>> > set the http method on the protected mock http object, e.g., request.
>> > setMethod("get")
>> >
>> > It makes sense now, but it took me a couple of hours to figure it out :D
>> >
>> > Thanks,
>> > Antonios
>>
>> ---------------------------------------------------------------------
>> 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: Restful2ActionMapper tests
Posted by Antonios Gkogkakis <gk...@tcd.ie>.
I meant to add the paragraph that I sent, but it's more clear to add a unit
test. (tested with 2.3.1.4.3)
What I said in my previous email is that the Restful2ActionMapper cannot
determine which action to call, just
from the uri, it also needs the http method that should be passed in the
request mock.
note for the existing documentation : the id in "<param name="id">{0}</
param>" should change to "<param name="id">{1}</param>"
public class MovieActionTest extends StrutsJUnit4TestCase<MovieActionTest>{
@Before
public void setUp() throws Exception {
//assumes Basic authentication
super.setUp();
String credentials = "username:password";
request.addHeader("authorization", "BASIC " +
Base64.encodeBase64String(credentials.getBytes()));
}
@Test
public void testIndex() throws Exception {
request.setMethod("get"); //Http method should be set
ActionProxy proxy = getActionProxy("/rest/movie/");
proxy.setExecuteResult(false);
String result = proxy.execute();
//assertions ...
}
@Test
public void testView() throws Exception {
request.setMethod("get"); //Http method should be set
ActionProxy proxy = getActionProxy("/rest/movie/1");
MovieAction movieAction = MovieAction.class.cast(proxy.getAction());
proxy.setExecuteResult(false);
String result = proxy.execute();
//assertions ...
assertEquals("1", movieAction.getId());
}
}
Thanks,
Antonios
On 14 June 2013 12:36, Lukasz Lenart <lu...@apache.org> wrote:
> You mean to add section about testing? Maybe it would better to show
> sample code with sample unittest, could you post something like that
> here?
>
>
> Thanks in advance!
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> 2013/6/14 Antonios Gkogkakis <gk...@tcd.ie>:
> > Hi all,
> >
> > I've made a documentation contribution on the Restful2ActionMapper a few
> > months ago,
> >
> > https://cwiki.apache.org/WW/restfulactionmapper.html
> >
> > Could someone that has access to the wiki (Lukasz :D) append that, in
> order
> > to test
> > an action using the Restful2ActionMapper with StrutsJUnit4TestCase
> someone
> > has to
> > set the http method on the protected mock http object, e.g., request.
> > setMethod("get")
> >
> > It makes sense now, but it took me a couple of hours to figure it out :D
> >
> > Thanks,
> > Antonios
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
Re: Restful2ActionMapper tests
Posted by Lukasz Lenart <lu...@apache.org>.
You mean to add section about testing? Maybe it would better to show
sample code with sample unittest, could you post something like that
here?
Thanks in advance!
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
2013/6/14 Antonios Gkogkakis <gk...@tcd.ie>:
> Hi all,
>
> I've made a documentation contribution on the Restful2ActionMapper a few
> months ago,
>
> https://cwiki.apache.org/WW/restfulactionmapper.html
>
> Could someone that has access to the wiki (Lukasz :D) append that, in order
> to test
> an action using the Restful2ActionMapper with StrutsJUnit4TestCase someone
> has to
> set the http method on the protected mock http object, e.g., request.
> setMethod("get")
>
> It makes sense now, but it took me a couple of hours to figure it out :D
>
> Thanks,
> Antonios
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org