dion        02/05/22 02:34:48

  Modified:    src/test/org/apache/maven/struts Struts10WarFileTest.java
               src/java/org/apache/maven/struts Struts10WarFile.java
  Log:
  - added getActions to allow access to the struts actions defined in the config file
  
  Revision  Changes    Path
  1.3       +34 -1     
jakarta-turbine-maven/src/test/org/apache/maven/struts/Struts10WarFileTest.java
  
  Index: Struts10WarFileTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/test/org/apache/maven/struts/Struts10WarFileTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Struts10WarFileTest.java  22 May 2002 06:55:28 -0000      1.2
  +++ Struts10WarFileTest.java  22 May 2002 09:34:47 -0000      1.3
  @@ -63,7 +63,7 @@
    * Unit tests for {@link Struts10WarFile}
    *
    * @author dion
  - * @version $Id: Struts10WarFileTest.java,v 1.2 2002/05/22 06:55:28 dion Exp $
  + * @version $Id: Struts10WarFileTest.java,v 1.3 2002/05/22 09:34:47 dion Exp $
    */
   public class Struts10WarFileTest extends TestCase {
   
  @@ -157,5 +157,38 @@
           assertEquals("third form bean isn't subscriptionForm", 
               "subscriptionForm",
               ((FormBean)formBeans.get(2)).getName());
  +    }
  +    
  +    /** test the retrieval of actions
  +     * @throws Exception when there is an unexpected problem
  +     */
  +    public void testActions() throws Exception
  +    {
  +        testConstructor();
  +        assertEquals("Number of actions returned was wrong", 14, 
  +            instance.getActions().size());
  +        List actions = instance.getActions();
  +        String[] types = new String[] 
  +            {
  +            "org.apache.struts.webapp.example.EditRegistrationAction",
  +            "org.apache.struts.webapp.example.EditSubscriptionAction",
  +            "org.apache.struts.webapp.example.LogoffAction",
  +            "org.apache.struts.webapp.example.LogonAction",
  +            "org.apache.struts.webapp.example.SaveRegistrationAction",
  +            "org.apache.struts.webapp.example.SaveSubscriptionAction",
  +            null,
  +            "org.apache.struts.actions.AddFormBeanAction",
  +            "org.apache.struts.actions.AddForwardAction",
  +            "org.apache.struts.actions.AddMappingAction",
  +            "org.apache.struts.actions.ReloadAction",
  +            "org.apache.struts.actions.RemoveFormBeanAction",
  +            "org.apache.struts.actions.RemoveForwardAction",
  +            "org.apache.struts.actions.RemoveMappingAction"
  +            };
  +        for (int index = 0; index < types.length; index++)
  +        {
  +            assertEquals("action number " + index + " isn't " + types[index], 
  +                types[index], ((Action) actions.get(index)).getType());
  +        }
       }
   }
  
  
  
  1.5       +27 -1     
jakarta-turbine-maven/src/java/org/apache/maven/struts/Struts10WarFile.java
  
  Index: Struts10WarFile.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/struts/Struts10WarFile.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Struts10WarFile.java      22 May 2002 07:48:54 -0000      1.4
  +++ Struts10WarFile.java      22 May 2002 09:34:48 -0000      1.5
  @@ -74,7 +74,7 @@
    * Encapsulates a Struts 1.0 War File. Holds functionality to access Struts
    * specific resources and data in the war.
    * @author  dion
  - * @version $Id: Struts10WarFile.java,v 1.4 2002/05/22 07:48:54 dion Exp $
  + * @version $Id: Struts10WarFile.java,v 1.5 2002/05/22 09:34:48 dion Exp $
    */
   public class Struts10WarFile extends WarFile
   {
  @@ -218,5 +218,31 @@
           }
           
           return formBeans;
  +    }
  +    
  +    /** retrieves the actions defined in the struts configuration file
  +     * @throws IOException when there are problems reading from the war
  +     */
  +    public List getActions() throws IOException
  +    {
  +        List actions = new ArrayList();
  +        Document config = getStrutsConfig();
  +        List actionNodes = config.selectNodes(
  +            "/struts-config/action-mappings/action");
  +        Element actionNode = null;
  +        Action action = null;
  +        for (Iterator nodes = actionNodes.iterator(); nodes.hasNext();)
  +        {
  +            actionNode = (Element) nodes.next();
  +            action = new Action();
  +            action.setClassName(actionNode.attributeValue("className"));
  +            action.setName(actionNode.attributeValue("name"));
  +            action.setScope(actionNode.attributeValue("scope"));
  +            action.setType(actionNode.attributeValue("type"));
  +            action.setUnknown(actionNode.attributeValue("unknown"));
  +            action.setValidate(actionNode.attributeValue("validate"));
  +            actions.add(action);
  +        }
  +        return actions;
       }
    }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to