larryi      01/01/30 18:02:39

  Modified:    src/share/org/apache/tomcat/util/test DefaultMatcher.java
                        GTest.java
  Log:
  Added support for a responseMatchFile.  Each line of the "match file" is read
  and the response body searched for the presence of that text.  If not found,
  the test fails.  If a line containing only "!=" is found, all lines after it are
  required not to be found, else the test fails.
  
  Also fixed, I think, needAND handling in DefaultMatcher.
  
  Revision  Changes    Path
  1.8       +59 -3     
jakarta-tomcat/src/share/org/apache/tomcat/util/test/DefaultMatcher.java
  
  Index: DefaultMatcher.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/test/DefaultMatcher.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DefaultMatcher.java       2001/01/29 07:09:08     1.7
  +++ DefaultMatcher.java       2001/01/31 02:02:39     1.8
  @@ -79,6 +79,8 @@
       String goldenFile;
       // Match the body against a string
       String responseMatch;
  +    // Match the body against a list of strings in a file
  +    String responseMatchFile;
       // the response should include the following headers
       Vector headerVector=new Vector(); // workaround for introspection problems
       Hashtable expectHeaders=new Hashtable();
  @@ -179,6 +181,12 @@
        this.responseMatch=s;
       }
   
  +    /** Verify that response matches a list of strings in a file
  +     */
  +    public void setResponseMatchFile( String s ) {
  +     this.responseMatchFile=s;
  +    }
  +
       /** Verify the response code
        */
       public void setReturnCode( String s ) {
  @@ -198,8 +206,8 @@
        if( getExpectHeaders().size() > 0 ) {
            Enumeration e=expectHeaders.keys();
            while( e.hasMoreElements()) {
  -             if( ! needAND ) needAND=true;
                if( needAND ) desc.append( " && " );
  +             needAND=true;
                String key=(String)e.nextElement();
                Header h=(Header)expectHeaders.get(key);
                desc.append("( responseHeader '" + h.getName() +
  @@ -208,15 +216,23 @@
        }
   
        if( responseMatch != null ) {
  -         if( ! needAND ) needAND=true;
            if( needAND ) desc.append( " && " );
  +         needAND=true;
   
            desc.append("( responseBody matches '"+ responseMatch + "') ");
        }
   
  +     // if match file is specified
  +     if( responseMatchFile != null ) {
  +         if( needAND ) desc.append( " && " );
  +         needAND=true;
  +
  +         desc.append("( responseBody matches lines in '"+ responseMatchFile + "') 
");
  +        }
  +
        if( goldenFile != null ) {
  -         if( ! needAND ) needAND=true;
            if( needAND ) desc.append( " && " );
  +         needAND=true;
   
            desc.append("( responseBody " );
            if( exactMatch )
  @@ -303,6 +319,46 @@
                log("ERROR: expecting match on " + responseMatch);
                log("GOT: " );
                log(responseBody );
  +         }
  +     }
  +
  +     // if match file is specified
  +     if( responseMatchFile != null ) {
  +         try {
  +             boolean desiredResult = true;
  +             BufferedReader br = new BufferedReader( new 
FileReader(responseMatchFile));
  +
  +             String expected = br.readLine();
  +             while (expected != null) {
  +                 if ( "!=".equals(expected) )
  +                     desiredResult = false;
  +                 else {
  +                     boolean result = responseBody.indexOf( expected ) >= 0;
  +                     if( result != desiredResult ) {
  +                         responseStatus = false;
  +                         if ( desiredResult )
  +                             log("ERROR: expecting match on " + expected);
  +                         else
  +                             log("ERROR: expecting no match on " + expected);
  +                         log("In match file: " + responseMatchFile);
  +                         log("====================Got:");
  +                         log(responseBody );
  +                         log("====================");
  +                     }
  +                 }
  +                 expected = br.readLine();
  +             }
  +             br.close();
  +         } catch (FileNotFoundException ex) {
  +             log("\tMatch file not found: " + responseMatchFile);
  +             log("====================Got:");
  +             log(responseBody );
  +             log("====================");
  +             responseStatus = false;
  +         } catch ( IOException ex ) {
  +             log("\tError reading match file: " + responseMatchFile);
  +             log(ex.toString());
  +             responseStatus = false;
            }
        }
   
  
  
  
  1.8       +6 -0      jakarta-tomcat/src/share/org/apache/tomcat/util/test/GTest.java
  
  Index: GTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/test/GTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- GTest.java        2001/01/29 07:09:10     1.7
  +++ GTest.java        2001/01/31 02:02:39     1.8
  @@ -289,6 +289,12 @@
        matcher.setResponseMatch( s );
       }
   
  +    /** Verify that response matches a list of strings in a file
  +     */
  +    public void setResponseMatchFile( String s ) {
  +     matcher.setResponseMatchFile( s );
  +    }
  +
       /** Verify the response code
        */
       public void setReturnCode( String s ) {
  
  
  

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

Reply via email to