craigmcc    01/07/24 21:27:11

  Modified:    tester/src/bin tester.xml
               tester/src/tester/org/apache/tester SessionBean.java
               tester/src/tester/org/apache/tester/shared
                        SharedSessionBean.java
               tester/web/WEB-INF web.xml
  Added:       tester/src/tester/org/apache/tester ContextListener02.java
                        DatePropertyEditor.java
               tester/web Property01.jsp Property02.jsp
  Log:
  Add unit tests (positive and negative) for setting a bean property through
  a PropertyEditor, per JSP 1.2 PFD2, Section 2.13.2.1.
  
  Revision  Changes    Path
  1.63      +10 -0     jakarta-tomcat-4.0/tester/src/bin/tester.xml
  
  Index: tester.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/tester/src/bin/tester.xml,v
  retrieving revision 1.62
  retrieving revision 1.63
  diff -u -r1.62 -r1.63
  --- tester.xml        2001/07/23 23:46:01     1.62
  +++ tester.xml        2001/07/25 04:27:11     1.63
  @@ -537,6 +537,16 @@
            request="${context.path}/Encoding03.jsp" debug="${debug}"
             golden="${golden.path}/Encoding03.txt"/>
   
  +    <!-- ========== Property Editor Support =============================== -->
  +
  +    <tester host="${host}" port="${port}" protocol="HTTP/1.0"
  +         request="${context.path}/Property01.jsp" debug="${debug}"
  +          golden="${golden.path}/Property01.txt"/>
  +
  +    <tester host="${host}" port="${port}" protocol="HTTP/1.0"
  +         request="${context.path}/Property02.jsp" debug="${debug}"
  +          status="500"/>
  +
     </target>
   
   
  
  
  
  1.5       +19 -1     
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/SessionBean.java
  
  Index: SessionBean.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/SessionBean.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SessionBean.java  2001/06/22 21:57:08     1.4
  +++ SessionBean.java  2001/07/25 04:27:11     1.5
  @@ -59,6 +59,7 @@
   
   
   import java.io.Serializable;
  +import java.sql.Date;
   import javax.servlet.http.HttpSessionActivationListener;
   import javax.servlet.http.HttpSessionBindingEvent;
   import javax.servlet.http.HttpSessionBindingListener;
  @@ -70,7 +71,7 @@
    * so that instances can be saved and restored across server restarts.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.4 $ $Date: 2001/06/22 21:57:08 $
  + * @version $Revision: 1.5 $ $Date: 2001/07/25 04:27:11 $
    */
   
   public class SessionBean implements
  @@ -81,6 +82,21 @@
   
   
       /**
  +     * A date property for use with property editor tests.
  +     */
  +    protected Date dateProperty =
  +        new Date(System.currentTimeMillis());
  +
  +    public Date getDateProperty() {
  +        return (this.dateProperty);
  +    }
  +
  +    public void setDateProperty(Date dateProperty) {
  +        this.dateProperty = dateProperty;
  +    }
  +
  +
  +    /**
        * The lifecycle events that have happened on this bean instance.
        */
       protected String lifecycle = "";
  @@ -118,6 +134,8 @@
   
           StringBuffer sb = new StringBuffer("SessionBean[lifecycle=");
           sb.append(this.lifecycle);
  +        sb.append(",dateProperty=");
  +        sb.append(dateProperty);
           sb.append(",stringProperty=");
           sb.append(this.stringProperty);
           sb.append("]");
  
  
  
  1.1                  
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/ContextListener02.java
  
  Index: ContextListener02.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *      Copyright (c) 1999, 2000, 2001  The Apache Software Foundation.      *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    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 acknowlegement:                             *
   *                                                                           *
   *       "This product includes  software developed  by the Apache  Software *
   *        Foundation <http://www.apache.org/>."                              *
   *                                                                           *
   *    Alternately, this acknowlegement may appear in the software itself, if *
   *    and wherever such third-party acknowlegements normally appear.         *
   *                                                                           *
   * 4. The names  "The  Jakarta  Project",  "Tomcat",  and  "Apache  Software *
   *    Foundation"  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" nor may *
   *    "Apache" appear in their names 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 indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  
  package org.apache.tester;
  
  
  import java.beans.PropertyEditorManager;
  import java.sql.Date;
  import javax.servlet.ServletContext;
  import javax.servlet.ServletContextEvent;
  import javax.servlet.ServletContextListener;
  
  
  /**
   * Application event listener for context events.  Ensures that the property
   * editor classes for this web application are appropriately registered.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2001/07/25 04:27:11 $
   */
  
  public class ContextListener02
      implements ServletContextListener {
  
  
      private ServletContext context = null;
  
  
      public void contextDestroyed(ServletContextEvent event) {
          context.log("ContextListener02: contextDestroyed()");
          context = null;
      }
  
      public void contextInitialized(ServletContextEvent event) {
          context = (ServletContext) event.getSource();
          context.log("ContextListener02: contextInitialized()");
          PropertyEditorManager.registerEditor(Date.class,
                                               DatePropertyEditor.class);
          context.log("ContextListener02: getEditorSearchPath() -->");
          String search[] = PropertyEditorManager.getEditorSearchPath();
          if (search == null)
              search = new String[0];
          for (int i = 0; i < search.length; i++)
              context.log("ContextListener02:   " + search[i]);
          context.log("ContextListener02: findEditor() --> " +
                      PropertyEditorManager.findEditor(Date.class));
                 
      }
  
  
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/DatePropertyEditor.java
  
  Index: DatePropertyEditor.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *         Copyright (c) 1999, 2000  The Apache Software Foundation.         *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    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 acknowlegement:                             *
   *                                                                           *
   *       "This product includes  software developed  by the Apache  Software *
   *        Foundation <http://www.apache.org/>."                              *
   *                                                                           *
   *    Alternately, this acknowlegement may appear in the software itself, if *
   *    and wherever such third-party acknowlegements normally appear.         *
   *                                                                           *
   * 4. The names  "The  Jakarta  Project",  "Tomcat",  and  "Apache  Software *
   *    Foundation"  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" nor may *
   *    "Apache" appear in their names 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 indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  
  package org.apache.tester;
  
  import java.beans.PropertyEditorSupport;
  import java.text.ParsePosition;
  import java.text.SimpleDateFormat;
  import java.sql.Date;
  
  /**
   * PropertyEditor implementation for a java.sql.Date property.
   *
   * @author Craig R. McClanahan
   * @revision $Date: 2001/07/25 04:27:11 $ $Revision: 1.1 $
   */
  public class DatePropertyEditor extends PropertyEditorSupport {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The date format to which dates converted by this property editor
       * must conform.
       */
      private SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Convert our Date object into a String that conforms to our
       * specified <code>format</code>, and return it.  If this is not
       * possible, return <code>null</code>.
       */
      public String getAsText() {
  
          try {
              Date date = (Date) getValue();
              return (format.format(date));
          } catch (ClassCastException e) {
              return (null);
          } catch (IllegalArgumentException e) {
              return (null);
          }
  
      }
  
  
      /**
       * Convert the specified String value into a Date, if it conforms to
       * our specified <code>format</code> , else throw IllegalArgumentException.
       *
       * @param value String value to be converted
       *
       * @exception IllegalArgumentException if a conversion error occurs
       */
      public void setAsText(String value) throws IllegalArgumentException {
  
          // Validate the format of the input string
          if (value == null)
              throw new IllegalArgumentException
                  ("Cannot convert null String to a Date");
          if (value.length() != 10)
              throw new IllegalArgumentException
                  ("String '" + value + "' has invalid length " +
                   value.length());
          for (int i = 0; i < 10; i++) {
              char ch = value.charAt(i);
              if ((i == 2) || (i == 5)) {
                  if (ch != '/')
                      throw new IllegalArgumentException
                          ("String '" + value + "' missing slash at index " +
                           i);
              } else {
                  if (!Character.isDigit(ch))
                      throw new IllegalArgumentException
                          ("String '" + value + "' missing digit at index " +
                           i);
              }
          }
  
          // Convert the incoming value to a java.sql.Date
          java.util.Date temp = format.parse(value, new ParsePosition(0)); 
          java.sql.Date date = new java.sql.Date(temp.getTime());
          setValue(date);
      }
  
          
  }
  
  
  
  1.3       +19 -1     
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/shared/SharedSessionBean.java
  
  Index: SharedSessionBean.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/shared/SharedSessionBean.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SharedSessionBean.java    2001/06/23 00:14:44     1.2
  +++ SharedSessionBean.java    2001/07/25 04:27:11     1.3
  @@ -59,6 +59,7 @@
   
   
   import java.io.Serializable;
  +import java.sql.Date;
   import javax.servlet.http.HttpSessionActivationListener;
   import javax.servlet.http.HttpSessionBindingEvent;
   import javax.servlet.http.HttpSessionBindingListener;
  @@ -74,7 +75,7 @@
    * <code>$CATALINA_HOME/lib</code>.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2001/06/23 00:14:44 $
  + * @version $Revision: 1.3 $ $Date: 2001/07/25 04:27:11 $
    */
   
   public class SharedSessionBean implements
  @@ -85,6 +86,21 @@
   
   
       /**
  +     * A date property for use with property editor tests.
  +     */
  +    protected Date dateProperty =
  +        new Date(System.currentTimeMillis());
  +
  +    public Date getDateProperty() {
  +        return (this.dateProperty);
  +    }
  +
  +    public void setDateProperty(Date dateProperty) {
  +        this.dateProperty = dateProperty;
  +    }
  +
  +
  +    /**
        * The lifecycle events that have happened on this bean instance.
        */
       protected String lifecycle = "";
  @@ -122,6 +138,8 @@
   
           StringBuffer sb = new StringBuffer("SharedSessionBean[lifecycle=");
           sb.append(this.lifecycle);
  +        sb.append(",dateProperty=");
  +        sb.append(dateProperty);
           sb.append(",stringProperty=");
           sb.append(this.stringProperty);
           sb.append("]");
  
  
  
  1.1                  jakarta-tomcat-4.0/tester/web/Property01.jsp
  
  Index: Property01.jsp
  ===================================================================
  <html>
  <head>
  <title>Property01.jsp - Positive PropertyEditor Test</title>
  </head>
  <body bgcolor="white">
  <jsp:useBean id="bean" scope="request"
            class="org.apache.tester.SessionBean"/>
  <jsp:setProperty name="bean" property="dateProperty"
                  value="07/25/2001"/>
  Date property is '<jsp:getProperty name="bean" property="dateProperty"/>'.
  </body>
  </html>
  
  
  
  1.1                  jakarta-tomcat-4.0/tester/web/Property02.jsp
  
  Index: Property02.jsp
  ===================================================================
  <html>
  <head>
  <title>Property02.jsp - Negative PropertyEditor Test</title>
  </head>
  <body bgcolor="white">
  <jsp:useBean id="bean" scope="request"
            class="org.apache.tester.SessionBean"/>
  <jsp:setProperty name="bean" property="dateProperty"
                  value="07/25/200A"/>
  Date property is '<jsp:getProperty name="bean" property="dateProperty"/>'.
  </body>
  </html>
  
  
  
  1.45      +4 -0      jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- web.xml   2001/07/19 18:37:41     1.44
  +++ web.xml   2001/07/25 04:27:11     1.45
  @@ -407,6 +407,10 @@
       </listener>
   
       <listener>
  +        <listener-class>org.apache.tester.ContextListener02</listener-class>
  +    </listener>
  +
  +    <listener>
           <listener-class>org.apache.tester.SessionListener01</listener-class>
       </listener>
   
  
  
  

Reply via email to