THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
Code Block | ||||
---|---|---|---|---|
| ||||
<action name="movie/*" className="app.MovieAction"> <param name="id">{01}</param> ... </action> |
This mapper supports the following parameters:
...
To achieve that we have to rely on nampespaces namespaces and the PrefixBasedActionMapper that can choose which action mapper to use for a particular url based on a prefix (the action namespace).
...
Code Block | ||||
---|---|---|---|---|
| ||||
<package name="rest" namespace="/rest" extends="struts-default"> ....interceptor config <action name="movie/*" class="app.MovieAction"> <param name="id">{01}</param> ....results </action> .... </package> |
...
Code Block | ||||
---|---|---|---|---|
| ||||
<constant name="struts.enable.SlashesInActionNames" value="true" />
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false" />
|
Unit testing
Below you will find a simple unit test to test how to test actions when Restful2ActionMapper
is used.
Code Block | ||||
---|---|---|---|---|
| ||||
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 to Antonios Gkogkakis for the examples!