View Javadoc

1   package org.apache.struts2.components;
2   
3   import org.apache.struts2.views.jsp.AbstractTagTest;
4   import org.apache.struts2.TestConfigurationProvider;
5   import org.apache.struts2.StrutsException;
6   
7   /***
8    * Describe your class here
9    *
10   * @author $Author$
11   *         <p/>
12   *         $Id$
13   */
14  public class AnotherActionComponentTest extends AbstractTagTest  {
15  
16      public void testRethrowException() throws Exception {
17          request.setupGetServletPath(TestConfigurationProvider.TEST_NAMESPACE + "/"
18                  + "foo.action" );
19          ActionComponent ac = new ActionComponent(stack, request, response) ;
20          container.inject(ac);
21          ac.setNamespace(TestConfigurationProvider.TEST_NAMESPACE);
22          ac.setName(TestConfigurationProvider.TEST_ACTION_NAME + "!executeThrowsException");
23          ac.setRethrowException(true);
24          boolean exceptionCaught = false;
25          try {
26              ac.executeAction();
27          }
28          catch (Exception e) {
29              if (e instanceof StrutsException)
30                  exceptionCaught = true;
31          }
32          assertTrue(exceptionCaught);
33      }
34  
35      public void testDoesNotThrowException() throws Exception {
36          request.setupGetServletPath(TestConfigurationProvider.TEST_NAMESPACE + "/"
37                  + "foo.action" );
38          ActionComponent ac = new ActionComponent(stack, request, response) ;
39          container.inject(ac);
40          ac.setNamespace(TestConfigurationProvider.TEST_NAMESPACE);
41          ac.setName(TestConfigurationProvider.TEST_ACTION_NAME+ "!executeThrowsException");
42          ac.setRethrowException(false);
43          boolean exceptionCaught = false;
44          try {
45              ac.executeAction();
46          }
47          catch (Exception e) {
48              if (e instanceof StrutsException)
49                  exceptionCaught = true;
50          }
51          assertTrue(! exceptionCaught);    
52      }
53  }