tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/test GTest.java HttpClient.java
Date Wed, 07 Feb 2001 06:41:33 GMT
costin      01/02/06 22:41:33

  Modified:    src/share/org/apache/tomcat/util/test GTest.java
                        HttpClient.java
  Log:
  Allow multiple tests (matchers ) per request.
  
  Revision  Changes    Path
  1.9       +58 -23    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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- GTest.java	2001/01/31 02:02:39	1.8
  +++ GTest.java	2001/02/07 06:41:33	1.9
  @@ -86,8 +86,10 @@
       // Instance variables
       
       HttpClient httpClient=new HttpClient();
  -    DefaultMatcher matcher=new DefaultMatcher();
  +    Vector matchers=new Vector();
  +    //DefaultMatcher matcher=new DefaultMatcher();
       Body comment=null;
  +    String failMessage="";
       
       String description="No description";
   
  @@ -98,7 +100,7 @@
       boolean result=false;
       
       public GTest() {
  -	matcher.setDebug( debug );
  +	//matcher.setDebug( debug );
   	httpClient.setDebug( debug );
       }
   
  @@ -183,7 +185,8 @@
       }
   
       public void addDefaultMatcher( DefaultMatcher m ) {
  -	matcher=m;
  +	matchers.addElement( m );
  +	//	matcher=m;
       }
   
       public Body createComment() {
  @@ -196,9 +199,9 @@
   	return httpClient;
       }
       
  -    public DefaultMatcher getMatcher() {
  -	return matcher;
  -    }
  +//     public DefaultMatcher getMatcher() {
  +// 	return matcher;
  +//     }
   
       public String getComment() {
   	if(comment==null) return "";
  @@ -209,18 +212,33 @@
       /** Description should be in <test description=""/>
        */
       public String getDescription() {
  +	if( comment!=null) return comment.getText();
   	return description;
       }
   
       public void setDescription(String description) {
   	this.description=description;
       }
  +
  +    public String getMatchDescription() {
  +	StringBuffer sb=new StringBuffer();
  +	for( int i=0; i<matchers.size(); i++ ) {
  +	    DefaultMatcher m=(DefaultMatcher)matchers.elementAt( i );
  +	    if( i!=0 ) sb.append( " && " );
  +	    sb.append( m.getTestDescription());
  +	}
  +	return sb.toString();
  +    }
  +
  +    public String getFailureMessage() {
  +	return failMessage;
  +    }
       
       /** Display debug info
        */
       public void setDebug( String debugS ) {
   	debug=Integer.valueOf( debugS).intValue();
  -	matcher.setDebug( debug );
  +	//matcher.setDebug( debug );
   	httpClient.setDebug( debug );
       }
   
  @@ -259,46 +277,56 @@
       }
   
       // -------------------- Matcher properties --------------------
  +
  +    // @deprecated Use defaultMatcher childs, this allow only one test !!!
  +
       
       public void setExactMatch(String exact) {
  -	matcher.setExactMatch(exact);
  +	if( matchers.size() > 0 )
  +	    ((DefaultMatcher)matchers.elementAt(0)).setExactMatch(exact);
       }
   
       /** True if this is a positive test, false for negative
        */
       public void setMagnitude( String magnitudeS ) {
  -        matcher.setMagnitude( magnitudeS );
  +	if( matchers.size() > 0 )
  +	    ((DefaultMatcher)matchers.elementAt(0)).setMagnitude( magnitudeS );
       }
   
       /** Compare with the golden file
        */
       public void setGoldenFile( String s ) {
  -	matcher.setGoldenFile(s);
  +	if( matchers.size() > 0 )
  +	    ((DefaultMatcher)matchers.elementAt(0)).setGoldenFile(s);
       }
   
       /** Verify that response includes the expected headers
        *  The value is a "|" separated list of headers to expect.
        */
       public void setExpectHeaders( String s ) {
  -	matcher.setExpectHeaders( s );
  +	if( matchers.size() > 0 )
  +	    ((DefaultMatcher)matchers.elementAt(0)).setExpectHeaders( s );
       }
   
       /** Verify that response match the string
        */
       public void setResponseMatch( String s ) {
  -	matcher.setResponseMatch( s );
  +	if( matchers.size() > 0 )
  +	    ((DefaultMatcher)matchers.elementAt(0)).setResponseMatch( s );
       }
   
       /** Verify that response matches a list of strings in a file
        */
       public void setResponseMatchFile( String s ) {
  -	matcher.setResponseMatchFile( s );
  +	if( matchers.size() > 0 )
  +	    ((DefaultMatcher)matchers.elementAt(0)).setResponseMatchFile( s );
       }
   
       /** Verify the response code
        */
       public void setReturnCode( String s ) {
  -	matcher.setReturnCode( s );
  +	if( matchers.size() > 0 )
  +	    ((DefaultMatcher)matchers.elementAt(0)).setReturnCode( s );
       }
   
       // -------------------- Execute the request --------------------
  @@ -313,10 +341,19 @@
   	    httpClient.execute();
   	    Response resp=httpClient.getResponse();
   
  -	    matcher.setResponse( resp );
  -	    matcher.execute();
  -	    result=matcher.getResult();
  -
  +	    result=true;
  +	    for( int i=0; i< matchers.size(); i++ ) {
  +		DefaultMatcher matcher=(DefaultMatcher)matchers.elementAt(i);
  +		matcher.setResponse( resp );
  +		matcher.execute();
  +		boolean testResult=matcher.getResult();
  +		if( ! testResult ) {
  +		    result=false;
  +		    failMessage=matcher.getMessage();
  +		    break;
  +		}
  +	    }
  +	    
   	    // don't print OKs
   	    if( result && failureOnly ) return;
   
  @@ -349,17 +386,16 @@
   	else
   	    msg=description + " (" + httpClient.getRequestLine() + ")";
   
  -	if(matcher.getResult()) 
  +	if( result ) 
   	    out.println("OK " +  msg );
   	else {
   	    out.println("FAIL " + msg );
  -	    out.println("Message: " + matcher.getMessage());
  +	    out.println("Message: " + failMessage);
   	}
   	out.flush();
       }
   
       private void htmlReport() {
  -	boolean result=matcher.getResult();
   	String uri=httpClient.getURI();
   	if( uri!=null )
   	    out.println("<a href='" + uri + "'>");
  @@ -385,7 +421,7 @@
   
   	if( ! result ) {
   	    out.println("<b>Message:</b><pre>");
  -	    out.println( matcher.getMessage());
  +	    out.println( failMessage);
   	    out.println("</pre>");
   	}
   
  @@ -416,7 +452,6 @@
       }
   
       private void xmlReport() {
  -	boolean result=matcher.getResult();
   	String msg=null;
   	if(  "No description".equals( description )) 
   	    msg=" (" + httpClient.getRequestLine() + ")";
  
  
  
  1.6       +6 -0      jakarta-tomcat/src/share/org/apache/tomcat/util/test/HttpClient.java
  
  Index: HttpClient.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/test/HttpClient.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- HttpClient.java	2001/02/06 06:48:53	1.5
  +++ HttpClient.java	2001/02/07 06:41:33	1.6
  @@ -128,6 +128,12 @@
   	this.host=h;
       }
   
  +    /** 
  +     */
  +    public void setMethod(String h) {
  +	this.method=h;
  +    }
  +
       /** The port used to send the request
        */
       public void setPort(String portS) {
  
  
  

Mime
View raw message