curcuru     02/04/17 07:56:04

  Modified:    test/java/src/org/apache/qetest FileDatalet.java
                        FileTestletDriver.java
  Added:       test/java/src/org/apache/qetest FileDataletManager.java
  Log:
  Implement -fileList processing: new worker class FileDataletManager
  reads in qetest-style fileLists and creates updated FileDatalets therefrom
  
  Revision  Changes    Path
  1.6       +86 -21    
xml-xalan/test/java/src/org/apache/qetest/FileDatalet.java
  
  Index: FileDatalet.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/test/java/src/org/apache/qetest/FileDatalet.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FileDatalet.java  9 Apr 2002 20:34:54 -0000       1.5
  +++ FileDatalet.java  17 Apr 2002 14:56:04 -0000      1.6
  @@ -66,51 +66,58 @@
   /**
    * Datalet representing set of paths to files: input, output, gold.
    * 
  - * This is a fairly simplistic Datalet implementation that's 
  + * <p>This is a fairly simplistic Datalet implementation that's 
    * useful for the many programs where the test requires reading 
    * an input file, performing an operation with the program, and 
  - * then verifying an output file.
  + * then verifying an output file.</p>
    *
  - * We normally operate on local path/filenames, since the Java 
  + * <p>We normally operate on local path/filenames, since the Java 
    * SDK's implementation of URLs and File objects is so poor at 
  - * handling proper URI/URL's according to the RFCs.
  + * handling proper URI/URL's according to the RFCs.  A potential 
  + * future improvement is to add convenience accessor methods, like 
  + * getInputName() (just the bare filename) etc. but I'm not quite 
  + * convinced we need them yet.</p>
    * 
  + * @see FileTestlet
  + * @see FileTestletDriver
  + * @see FileDataletManager
    * @author [EMAIL PROTECTED]
  - * @version $Id: FileDatalet.java,v 1.5 2002/04/09 20:34:54 curcuru Exp $
  + * @version $Id: FileDatalet.java,v 1.6 2002/04/17 14:56:04 curcuru Exp $
    */
   public class FileDatalet implements Datalet
   {
       /** Path of the location to get input resources from.  */
       protected String input = "tests/defaultInput";
   
  -    /** Accessor method for input.  */
  +    /** Accessor method for input; never null.  */
       public String getInput() { return input; }
   
       /** Path to put actual output resources into.  */
       protected String output = "output/defaultOutput";
   
  -    /** Accessor method for output.  */
  +    /** Accessor method for output; never null.  */
       public String getOutput() { return output; }
   
       /** Path of the location to get gold or reference resources from.  */
       protected String gold = "gold/defaultGold";
   
  -    /** Accessor method for gold.  */
  +    /** Accessor method for gold; never null.  */
       public String getGold() { return gold; }
   
   
       /** 
        * Worker method to validate the files/dirs we represent.  
        * 
  -     * By default, ensures that the input already exists in some 
  +     * <p>By default, ensures that the input already exists in some 
        * format; and attempts to create the output.  If asked to be 
        * strict, then we will fail if the output cannot be created, 
        * and we additionally will attempt to create the gold and 
  -     * will fail if it can't be created.
  +     * will fail if it can't be created.</p>
        *
  -     * Note that we only attempt to create the gold if asked to 
  +     * <p>Note that we only attempt to create the gold if asked to 
        * be strict, since users may simply want to run a 'crash test' 
  -     * and get all AMBG results when prototyping new tests.
  +     * and get all [EMAIL PROTECTED] org.apache.qetest.Logger#AMBG_RESULT 
AMBG}
  +     * results when prototyping new tests.</p>
        *
        * @param strict if true, requires that output and gold must 
        * be created; otherwise they're optional
  @@ -152,19 +159,21 @@
       /** 
        * Generic placeholder for any additional options.  
        * 
  -     * This allows FileDatalets to support additional kinds 
  +     * <p>This allows FileDatalets to support additional kinds 
        * of tests, like performance tests, without having to change 
        * this data model.  These options can serve as a catch-all 
        * for any new properties or options or what-not that new 
        * tests need, without having to change how the most basic 
  -     * member variables here work.
  -     * Note that while this needs to be a Properties object to 
  +     * member variables here work.</p>
  +     * <p>Note that while this needs to be a Properties object to 
        * take advantage of the parent/default behavior in 
        * getProperty(), this doesn't necessarily mean they can only 
        * store Strings; however only String-valued items can make 
  -     * use of the default properties mechanisim.
  +     * use of the default properties mechanisim.</p>
        *
  -     * Default is a null object.
  +     * <p>Default is a null object; note that getOptions() will 
  +     * never return null, but will create a blank Properties 
  +     * block if needed.</p>
        */
       protected Properties options = null;
   
  @@ -182,7 +191,12 @@
           return options;
       }
   
  -    /** Accessor method for optional properties; settable.  */
  +    /** 
  +     * Accessor method for optional properties; settable.  
  +     * <p>Note this method simply points our options at the 
  +     * caller's Properties; it does not do a clone since that 
  +     * would be quite costly.</p>
  +     */
       public void setOptions(Properties p) { options = p; }
   
   
  @@ -213,6 +227,7 @@
       /** Description of what this Datalet tests.  */
       protected String description = "FileDatalet: default description";
   
  +
       /**
        * Accesor method for a brief description of this Datalet.  
        *
  @@ -239,6 +254,7 @@
   
       /**
        * Worker method to auto-set the description of this Datalet.  
  +     * Conglomeration of input, output, gold values.
        */
       protected void setDescription()
       {
  @@ -258,9 +274,10 @@
        * Initialize this datalet from another FileDatalet which 
        * serves as a 'base' location, and a filename.  
        * 
  -     * We set each of our input, output, gold to be concatenations 
  +     * <p>We set each of our input, output, gold to be concatenations 
        * of the base + File.separator + fileName, and also copy 
  -     * over the options from the base.
  +     * over the options from the base.  Note we always attempt to 
  +     * deal with local path/filename conventions.</p>
        *
        * @param base FileDatalet object to serve as base directories
        * @param fileName to concatenate for each of input/output/gold
  @@ -283,7 +300,7 @@
       /**
        * Initialize this datalet from a list of paths.
        *
  -     * Our options are not initialized, and left as null.  
  +     * <p>Our options are not initialized, and left as null.<p>
        * 
        * @param i path for input
        * @param o path for output
  @@ -296,6 +313,54 @@
           gold = g;
           
           setDescription(); 
  +    }
  +
  +
  +    /**
  +     * Initialize this datalet from a string and defaults.
  +     *
  +     * <p>Our options are created as a new Properties block that 
  +     * defaults to the existing one passed in, then 
  +     * we parse the string for input, output, gold, and 
  +     * optionally add additional args to the options.</p>
  +     * 
  +     * @param args command line to initialize from
  +     * @param defaults for our options
  +     */
  +    public FileDatalet(String args, Properties defaults)
  +    {
  +        options = new Properties(defaults);
  +
  +        StringTokenizer st = new StringTokenizer(args);
  +
  +        // Fill in as many items as we can; leave as default otherwise
  +        // Note that order is important!
  +        if (st.hasMoreTokens())
  +        {
  +            input = st.nextToken();
  +            if (st.hasMoreTokens())
  +            {
  +                output = st.nextToken();
  +                if (st.hasMoreTokens())
  +                {
  +                    gold = st.nextToken();
  +                }
  +            }
  +        }
  +        // EXPERIMENTAL add extra name value pairs to our options
  +        while (st.hasMoreTokens())
  +        {
  +            String name = st.nextToken();
  +            if (st.hasMoreTokens())
  +            {
  +                options.put(name, st.nextToken());
  +            }
  +            else
  +            {
  +                // Just put it as 'true' for boolean options
  +                options.put(name, "true");
  +            }
  +        }
       }
   
   
  
  
  
  1.4       +19 -33    
xml-xalan/test/java/src/org/apache/qetest/FileTestletDriver.java
  
  Index: FileTestletDriver.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/test/java/src/org/apache/qetest/FileTestletDriver.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FileTestletDriver.java    9 Apr 2002 20:35:44 -0000       1.3
  +++ FileTestletDriver.java    17 Apr 2002 14:56:04 -0000      1.4
  @@ -86,7 +86,7 @@
    * our testProps object.</p>
    * 
    * @author [EMAIL PROTECTED]
  - * @version $Id: FileTestletDriver.java,v 1.3 2002/04/09 20:35:44 curcuru 
Exp $
  + * @version $Id: FileTestletDriver.java,v 1.4 2002/04/17 14:56:04 curcuru 
Exp $
    */
   public class FileTestletDriver extends XSLProcessorTestBase
   {
  @@ -233,11 +233,10 @@
               // Process the specific list of tests the user supplied
               String desc = "User-supplied fileList: " + fileList; // provide 
default value
               // Use static worker class to process the list
  -            // Vector datalets = FileDataletManager.readFileList(reporter, 
fileList, desc);
  -            throw new RuntimeException("fileList not supported yet! Need a 
FileDataletManager");
  +            Vector datalets = FileDataletManager.readFileList(reporter, 
fileList, desc, testProps);
   
               // Actually process the specified files in a testCase
  -            // processFileList(datalets, desc);
  +            processFileList(datalets, desc);
           }
           else
           {
  @@ -283,21 +282,11 @@
               }
           }
   
  -        FileDatalet subdir = new FileDatalet(topInputDir.getPath(), 
outputDir, goldDir);
  -        // By default, we don't process the topmost inputDir, but 
  -        //  we always want to recurse downwards from here
  -        //  If user asks us to 'processTop', then also process this one
  -        //@todo define better this property and meaning
  -        String top = testProps.getProperty("processTop");
  -        if ((null != top)
  -            && (top.equalsIgnoreCase("true")))
  -        {
  -            recurseSubDir(subdir, true, true);
  -        }
  -        else            
  -        {
  -            recurseSubDir(subdir, false, true);
  -        }
  +        FileDatalet topDirs = new FileDatalet(topInputDir.getPath(), 
outputDir, goldDir);
  +
  +        // Optionally process this topDirs, and always recurse at 
  +        //  least one level below it
  +        recurseSubDir(topDirs, getProcessTopDir(), true);
       }
   
   
  @@ -355,20 +344,9 @@
               }
               FileDatalet subdir = new FileDatalet(base, subdirs[i]);
   
  -            // Always process subdirs, only top level might have 
  -            //  had process=false
  -            // Read property to determine if we should continue 
  -            //  to recurse downwards from here
  -            String down = testProps.getProperty("recurse");
  -            if ((null != down)
  -                && (down.equalsIgnoreCase("true")))
  -            {
  -                recurseSubDir(subdir, true, true);
  -            }
  -            else            
  -            {
  -                recurseSubDir(subdir, true, false);
  -            }
  +            // Process each other directory, and optionally continue 
  +            //  to recurse downwards
  +            recurseSubDir(subdir, true, getRecurseDirs());
           } // end of for...
       }
   
  @@ -628,6 +606,14 @@
           //  put the fileChecker directly into their options
           base.getOptions().put("fileCheckerImpl", fileChecker);
       }
  +
  +    /** If we should process the top level directory (default:false).   */
  +    protected boolean getProcessTopDir()
  +    { return false; }
  +
  +    /** If we should always recurse lower level directories (default:false). 
  */
  +    protected boolean getRecurseDirs()
  +    { return false; }
   
       /** Default FilenameFilter FQCN for directories.   */
       protected String getDefaultDirFilter()
  
  
  
  1.1                  
xml-xalan/test/java/src/org/apache/qetest/FileDataletManager.java
  
  Index: FileDataletManager.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2000-2001 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 "Xalan" 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 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 and was
   * originally based on software copyright (c) 2001, Lotus
   * Development Corporation., http://www.lotus.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.qetest;
  
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileReader;
  import java.io.IOException;
  import java.util.Properties;
  import java.util.StringTokenizer;
  import java.util.Vector;
  
  /**
   * Simple services for getting lists of FileDatalets.
   * 
   * <p>Provides static worker methods for reading 
   * [EMAIL PROTECTED] FileTestletDriver#OPT_FILELIST -fileList} lists 
   * of input/output/gold files and creating lists of 
   * corresponding FileDatalets from them.  We provide the logic 
   * for reading the actual fileList line-by-line; the 
   * [EMAIL PROTECTED] FileDatalet} class provides the logic for initializing 
   * itself from a line of text.</p>
   *
   * @see FileTestletDriver
   * @see FileDatalet
   * @author [EMAIL PROTECTED]
   * @version $Id: FileDataletManager.java,v 1.1 2002/04/17 14:56:04 curcuru 
Exp $
   */
  public abstract class FileDataletManager // provide static services only
  {
  
      /** '#' character, comment char in qetest fileList.  */
      public static final String QETEST_COMMENT_CHAR = "#";
  
  
      /**
       * Read in a file specifying a list of files to test.  
       *
       * <p>File format is fixed to be a qetest-style fileList; 
       * optional worker methods may allow other formats.  
       * Essentially we simply read the file line-by-line and 
       * create a FileDatalet from each line.</p>
       *
       * @param logger to report problems to
       * @param fileName String; name of the file
       * @param desc description; caller's copy changed
       * @param defaults default properties to potentially add to each datalet
       * @return Vector of FileDatalets; null if error
       */
      public static Vector readFileList(Logger logger, String fileName, 
              String desc, Properties defaults)
      {
          // Verify the file is there
          File f = new File(fileName);
          if (!f.exists())
          {
              logger.logMsg(Logger.ERRORMSG, "readFileList: " + fileName  
                            + " does not exist!");
              return null;
          }
  
          BufferedReader br = null;
          String line = null;
          try
          {
              br = new BufferedReader(new FileReader(f));
              line = br.readLine(); // read just first line
          }
          catch (IOException ioe)
          {
              logger.logMsg(Logger.ERRORMSG, "readFileList: " + fileName 
                            + " threw: " + ioe.toString());
              return null;
          }
  
          // Verify the first line
          if (line == null)
          {
              logger.logMsg(Logger.ERRORMSG, "readFileList: " + fileName
                            + " appears to be blank!");
              return null;
          }
  
          // Determine which kind of fileList this is
          Vector vec = null;
          if (line.startsWith(QETEST_COMMENT_CHAR))
          {
              // This is a native qetest style file
              vec = readQetestFileList(logger, br, line, fileName, desc, 
defaults);
          }
          else
          {
              //@todo: add a worker method that allows users to plug 
              //  in their own fileList reader that creates Datalets
              logger.logMsg(Logger.WARNINGMSG, "readFileList: " + fileName
                            + " could not determine file type; assuming 
qetest!");
              vec = readQetestFileList(logger, br, line, fileName, desc, 
defaults);
          }
  
          if ((null == vec) 
              || (vec.size() == 0))
          {
              logger.logMsg(Logger.ERRORMSG, "readFileList: " + fileName
                            + " did not have any non-comment lines!");
              // Explicitly return null so caller knows we had error
              return null;
          }
          return vec;
      }
      
  
      /**
       * Read in a qetest fileList specifying a list of files to test.
       *
       * <p>File format is pretty simple:</p>
       * <ul>
       * <li># first line of comments is copied into desc</li>
       * <li># beginning a line is a comment</li>
       * <li># rest of lines are whitespace delimited filenames and options</li>
       * <li>inputName outName goldName [options...]</li>
       * <li><b>Note:</b> see [EMAIL PROTECTED] FileDatalet} for
       * details on how the file lines are parsed!</li>
       * </ul>
       *
       * @param logger to report problems to
       * @param br BufferedReader to read from
       * @param firstLine already read from br
       * @param fileName String; name of the file
       * @param desc to use of this file
       * @param defaults default properties to potentially add to each datalet
       * @return Vector of FileDatalets, or null if error
       */
      protected static Vector readQetestFileList(Logger logger, BufferedReader 
br, 
                                                 String firstLine, String 
fileName, 
                                                 String desc, Properties 
defaults)
      {
          final String ABSOLUTE = "absolute";
          final String RELATIVE = "relative";
  
          Vector vec = new Vector();
          String line = firstLine;
          // Check if the first line is a comment 
          if (line.startsWith(QETEST_COMMENT_CHAR))
          {
              // Save it as the description
              desc = line;
              // Parse the next line
              try
              {
                  line = br.readLine();
              } 
              catch (IOException ioe)
              {
                  logger.logMsg(Logger.ERRORMSG, "readQetestFileList-desc: " 
                                + fileName + " threw: " + ioe.toString());
                  return null;
              }
          }
  
          // Load each line into a FileDatalet
          for (;;)
          {
              // Skip any lines beginning with # comment char or that are blank
              if ((!line.startsWith(QETEST_COMMENT_CHAR)) && (line.length() > 
0))
              {
                  // Create a Datalet and initialize with the line's 
                  //  contents and default properties
                  FileDatalet d = new FileDatalet(line, defaults);
  
                  // Also pass over the global runId, if set
                  //@todo this should be standardized and removed; 
                  //  or at least have global constants for it
                  d.getOptions().put("runId", defaults.getProperty("runId"));
  
                  // Add it to our vector
                  vec.addElement(d);
              }
  
              // Read next line and loop
              try
              {
                  line = br.readLine();
              }
              catch (IOException ioe2)
              {
                  // Just force us out of the loop; if we've already 
                  //  read part of the file, fine
                  logger.logMsg(Logger.WARNINGMSG, "readQetestFileList-body: " 
                                + fileName + " threw: " + ioe2.toString());
                  break;
              }
  
              if (line == null)
                  break;
          } // end of for (;;)
  
          // Return our Vector of created datalets
          return vec;
      }
  
  }
  
  
  

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

Reply via email to