dion        02/05/28 17:18:03

  Modified:    src/test/org/apache/maven/struts Struts10WarFileTest.java
               src/java/org/apache/maven/struts Struts10WarValidator.java
                        Struts10WarFile.java
  Added:       src/test/org/apache/maven/struts ForwardTest.java
               src/java/org/apache/maven/struts Forward.java
  Log:
  Added basic validation for forwards
  
  Revision  Changes    Path
  1.7       +12 -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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Struts10WarFileTest.java  27 May 2002 14:00:19 -0000      1.6
  +++ Struts10WarFileTest.java  29 May 2002 00:18:02 -0000      1.7
  @@ -65,7 +65,7 @@
    * Unit tests for {@link Struts10WarFile}
    *
    * @author dion
  - * @version $Id: Struts10WarFileTest.java,v 1.6 2002/05/27 14:00:19 dion Exp $
  + * @version $Id: Struts10WarFileTest.java,v 1.7 2002/05/29 00:18:02 dion Exp $
    */
   public class Struts10WarFileTest extends TestCase {
   
  @@ -206,5 +206,16 @@
           assertEquals("Global forwards type is not correct",
               "org.apache.struts.action.ActionForward",
               instance.getGlobalForwardsType());
  +        assertEquals("Wrong number of forwards found", 3, 
  +            instance.getForwards().size());
  +        String[] names = new String[] {"logoff", "logon", "success"};
  +        Forward forward = null;
  +        List forwards = instance.getForwards();
  +        for (int index = 0; index < names.length; index++)
  +        {
  +            forward = (Forward) forwards.get(index);
  +            assertEquals("Forward number " + index + " isn't "+ names[index], 
  +                names[index], forward.getName());
  +        }
       }
   }
  
  
  
  1.1                  
jakarta-turbine-maven/src/test/org/apache/maven/struts/ForwardTest.java
  
  Index: ForwardTest.java
  ===================================================================
  package org.apache.maven.struts;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Maven" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Maven", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  import junit.framework.TestCase;
  
  /**
   * Unit tests for the {@link Forward} class
   *
   * @author dion
   * @version $Id: ForwardTest.java,v 1.1 2002/05/29 00:18:02 dion Exp $
   */
  public class ForwardTest extends TestCase
  {
      /** the instance being tested */
      private Forward instance;
      
      /** Creates a new instance of Struts10WarFileTest 
       * @param testName the name of the test
       */
      public ForwardTest(String testName)
      {
          super(testName);
      }
      
      /**
       * Initialize per test data
       * @throws Exception when there is an unexpected problem
       */
      public void setUp() throws Exception
      {
          instance = new Forward();
      }
      
      /** test the constructor
       * @throws Exception when there is an unexpected problem
       */
      public void testConstructor() throws Exception
      {
          assertNotNull("instance not created", instance);
          assertNull("name property is not null", instance.getName());
          assertNull("className property is not null", instance.getClassName());
          assertNull("path property is not null", instance.getPath());
          assertNull("redirect property is not null", instance.getRedirect());
      }
      
      /** test the name property
       * @throws Exception when there is an unexpected problem
       */
      public void testName() throws Exception
      { 
          testConstructor();
          String dummy = "dummyName";
          instance.setName(dummy);
          assertEquals("set or get failed", dummy, instance.getName());
      }
      
      /** test the class name property
       * @throws Exception when there is an unexpected problem
       */
      public void testClassName() throws Exception
      { 
          testConstructor();
          String dummy = "dummyClassName";
          instance.setClassName(dummy);
          assertEquals("set or get failed", dummy, instance.getClassName());
      }
      
      /** test the path property
       * @throws Exception when there is an unexpected problem
       */
      public void testPath() throws Exception
      { 
          testConstructor();
          String dummy = "dummyPath";
          instance.setPath(dummy);
          assertEquals("set or get failed", dummy, instance.getPath());
      }
      
      /** test the redirect property
       * @throws Exception when there is an unexpected problem
       */
      public void testRedirect() throws Exception
      { 
          testConstructor();
          String dummy = "dummyRedirect";
          instance.setRedirect(dummy);
          assertEquals("set or get failed", dummy, instance.getRedirect());
      }
  }
  
  
  
  1.8       +43 -3     
jakarta-turbine-maven/src/java/org/apache/maven/struts/Struts10WarValidator.java
  
  Index: Struts10WarValidator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/struts/Struts10WarValidator.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Struts10WarValidator.java 27 May 2002 12:40:58 -0000      1.7
  +++ Struts10WarValidator.java 29 May 2002 00:18:03 -0000      1.8
  @@ -73,7 +73,7 @@
    * </ol>
    *
    * @author  dion
  - * @version $Id: Struts10WarValidator.java,v 1.7 2002/05/27 12:40:58 dion Exp $
  + * @version $Id: Struts10WarValidator.java,v 1.8 2002/05/29 00:18:03 dion Exp $
    */
   public class Struts10WarValidator extends WarValidator
   {
  @@ -256,11 +256,51 @@
       private void validateForwards(Struts10WarFile war) throws IOException
       {
           info("validating global forwards");
  +        ClassLoader loader = new WarClassLoader(war, 
  +            getClass().getClassLoader());
  +
           if (war.getGlobalForwardsType() != null)
           {
  -            ClassLoader loader = new WarClassLoader(war, getClass().
  -                getClassLoader());
               validateClass(war.getGlobalForwardsType(), loader);
  +        }
  +        List forwards = war.getForwards();
  +        Forward forward = null;
  +        for (int index = 0; index < forwards.size(); index++)
  +        {
  +            forward = (Forward) forwards.get(index);
  +            info("validating forward '" + forward.getName() + "'");
  +            validateForward(war, forward, loader);
  +        }
  +    }
  +    
  +    /** validate a single global forward
  +     * @param war the war file the forward is from
  +     * @param forward the forward to be validated
  +     * @param loader a class loader for validating classes are in the war
  +     */
  +    private void validateForward(Struts10WarFile war, Forward forward,
  +        ClassLoader loader)
  +    {
  +        // check className, if provided
  +        if (forward.getClassName() != null)
  +        {
  +            validateClass(forward.getClassName(), loader);
  +        }
  +        // check path
  +        String path = forward.getPath();
  +        int queryStringStart = path.indexOf("?");
  +        if (queryStringStart != -1)
  +        {
  +            path = path.substring(0, queryStringStart);
  +        }
  +        if (!war.hasFile(path))
  +        {
  +            // could be an action - check to see if it matches the 
  +        }
  +        // check redirect
  +        if (!isBoolean(forward.getRedirect()))
  +        {
  +            error("redirect attribute is not 'true' or 'false'");
           }
       }
   } // end class
  
  
  
  1.10      +32 -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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Struts10WarFile.java      27 May 2002 12:40:58 -0000      1.9
  +++ Struts10WarFile.java      29 May 2002 00:18:03 -0000      1.10
  @@ -75,7 +75,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.9 2002/05/27 12:40:58 dion Exp $
  + * @version $Id: Struts10WarFile.java,v 1.10 2002/05/29 00:18:03 dion Exp $
    */
   public class Struts10WarFile extends WarFile
   {
  @@ -283,4 +283,35 @@
           return type;
       }
   
  +    /** retrieve the global forwards defined in the struts configuration
  +     * @return a {@link List} of {@link Forward forwards}
  +     * @throws IOException when there are problems reading from the war
  +     */
  +    public List getForwards() throws IOException
  +    {
  +        List forwards = new ArrayList();
  +        Document config = getStrutsConfig();
  +        List nodes = config.selectNodes(
  +            "/struts-config/global-forwards/forward");
  +        Element element = null;
  +        Forward forward = null;
  +        for (int index = 0; index < nodes.size(); index++)
  +        {
  +            element = (Element) nodes.get(index);
  +            forward = new Forward();
  +            forward.setName(element.attributeValue("name"));
  +            forward.setPath(element.attributeValue("path"));
  +            if (element.attribute("className") != null)
  +            {
  +                forward.setClassName(element.attributeValue("className"));
  +            }
  +            if (element.attribute("redirect") != null)
  +            {
  +                forward.setRedirect(element.attributeValue("redirect"));
  +            }
  +            forwards.add(forward);
  +        }
  +        
  +        return forwards;
  +    }
    }
  
  
  
  1.1                  
jakarta-turbine-maven/src/java/org/apache/maven/struts/Forward.java
  
  Index: Forward.java
  ===================================================================
  package org.apache.maven.struts;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Maven" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Maven", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  /**
   * A class to represent a global forward as stored in the Struts configuration
   *
   * @author  dion
   * @version $Id: Forward.java,v 1.1 2002/05/29 00:18:03 dion Exp $
   */
  public class Forward
  {
      /** unique name for the forward */
      private String name;
      /** optional, fully qualified class name of the forward implementation */
      private String className;
      /** path to forward or redirect to */
      private String path;
      /** whether to redirect or forward to the path*/
      private String redirect;
      
      /** Creates a new instance of Forward */
      public Forward()
      {
      }
      
      /** Getter for property className.
       * @return Value of property className.
       */
      public String getClassName()
      {
          return className;
      }
      
      /** Setter for property className.
       * @param className New value of property className.
       */
      public void setClassName(String className)
      {
          this.className = className;
      }
      
      /** Getter for property name.
       * @return Value of property name.
       */
      public String getName()
      {
          return name;
      }
      
      /** Setter for property name.
       * @param name New value of property name.
       */
      public void setName(String name)
      {
          this.name = name;
      }
      
      /** Getter for property path.
       * @return Value of property path.
       */
      public String getPath()
      {
          return path;
      }
      
      /** Setter for property path.
       * @param path New value of property path.
       */
      public void setPath(String path)
      {
          this.path = path;
      }
      
      /** Getter for property redirect.
       * @return Value of property redirect.
       */
      public String getRedirect()
      {
          return redirect;
      }
      
      /** Setter for property redirect.
       * @param redirect New value of property redirect.
       */
      public void setRedirect(String redirect)
      {
          this.redirect = redirect;
      }
      
  }
  
  
  

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

Reply via email to