Apologies, I attached the wrong patch in the previous email. The correct patch for Bugzilla 3904 is now attached.
-rl On Tue, 2001-11-20 at 09:07, Ryan Lubke wrote: > GTest currently verifies response headers in a case sensative > manner. This patch resolves the issue. > > Fix is based of suggested fix in Bug report. > > Comments welcome. > > -rl > > > > > > ---- > > Index: GTest.java > =================================================================== > RCS file: >/home/cvspublic/jakarta-watchdog-4.0/src/tools/org/apache/tomcat/task/GTest.java,v > retrieving revision 1.3 > diff -u -r1.3 GTest.java > --- GTest.java 2001/09/28 04:09:56 1.3 > +++ GTest.java 2001/11/19 21:36:00 > @@ -15,6 +15,11 @@ > > // derived from Jsp > public class GTest extends Task { > + > + private static final String ZEROS = "00000000"; > + private static final int SHORTPADSIZE = 4; > + private static final int BYTEPADSIZE = 2; > + > String prefix="http://localhost:8080/test"; > String host="localhost"; > int port=8080; > @@ -376,9 +381,9 @@ > boolean cmp=true; > > if(exactMatch) > - cmp=compare(responseBody, expResult.toString() ); > + cmp=compare(responseBody.getBytes(), expResult.toString().getBytes() ); > else > - cmp=compareWeek( responseBody, expResult.toString()); > + cmp=compareWeak( responseBody, expResult.toString()); > > if( cmp != testCondition ) { > responseStatus = false; > @@ -521,30 +526,200 @@ > } > } > > + /* > + * <code>compare</code> compares the two byte arrays passed > + * in to verify that the lengths of the arrays are equal, and > + * that the content of the two arrays, byte for byte are equal. > + * > + * @param fromServer a <code>byte[]</code> value > + * @param fromGoldenFile a <code>byte[]</code> value > + * @return <code>boolean</code> true if equal, otherwise false > + */ > + private boolean compare( byte[] fromServer, byte[] fromGoldenFile ) { > + if ( fromServer == null || fromGoldenFile == null ) { > + return false; > + } > + > + /* > + * Check to see that the respose and golden file lengths > + * are equal. If they are not, dump the hex and don't > + * bother comparing the bytes. If they are equal, > + * iterate through the byte arrays and compare each byte. > + * If the bytes don't match, dump the hex representation > + * of the server response and the goldenfile and return > + * false. > + */ > + > + if ( fromServer.length != fromGoldenFile.length ) { > + StringBuffer sb = new StringBuffer( 50 ); > + sb.append( "Response and golden file lengths do not match!\n" ); > + sb.append( "Server response length: " ); > + sb.append( fromServer.length ); > + sb.append( "\nGoldenfile length: " ); > + sb.append( fromGoldenFile.length ); > + System.out.println( sb.toString() ); > + sb = null; > + // dump the hex representation of the byte arrays > + dumpHex( fromServer, fromGoldenFile ); > + > + return false; > + > + } else { > + > + int i = 0; > + int j = 0; > + > + while ( ( i < fromServer.length ) && ( j < fromGoldenFile.length ) ) { > + if ( fromServer[ i ] != fromGoldenFile[ j ] ) { > + System.out.println( "Error at position " + ( i + 1 ) ); > > - // Compare the actual result and the expected result. > - private boolean compare(String str1, String str2) { > - //System.out.println("In compare"); > - if ( str1==null || str2==null) return false; > - if ( str1.length() != str2.length() ) { > - System.out.println("Wrong size " + str1.length() +" " + str2.length() ); > - return false; > - } > - > - for(int i=0; i<str1.length() ; i++ ) { > - if (str1.charAt( i ) != str2.charAt( i ) ) { > - System.out.println("Error at " + i + " " + str1.charAt(1) + > - str2.charAt(i)); > - return false; > + // dump the hex representation of the byte arrays > + dumpHex( fromServer, fromGoldenFile ); > + > + return false; > + } > + > + i++; > + j++; > + } > + } > + > + return true; > + } > + > + /* > + * <code>dumpHex</code> helper method to dump formatted > + * hex output of the server response and the goldenfile. > + * > + * @param serverResponse a <code>byte[]</code> value > + * @param goldenFile a <code>byte[]</code> value > + */ > + private void dumpHex( byte[] serverResponse, byte[] goldenFile ) { > + StringBuffer outBuf = new StringBuffer( ( serverResponse.length + >goldenFile.length ) * 2 ); > + > + String fromServerString = getHexValue( serverResponse, 0, >serverResponse.length ); > + String fromGoldenFileString = getHexValue( goldenFile, 0, goldenFile.length >); > + > + outBuf.append( "Hex dump of server response and goldenfile below.\n\n### >RESPONSE FROM SERVER ###\n" ); > + outBuf.append( "----------------------------\n" ); > + outBuf.append( fromServerString ); > + outBuf.append( "\n\n### GOLDEN FILE ###\n" ); > + outBuf.append( "-------------------\n" ); > + outBuf.append( fromGoldenFileString ); > + outBuf.append( "\n\n### END OF DUMP ###\n" ); > + > + System.out.println( outBuf.toString() ); > + > + } > + > + /* > + * <code>getHexValue</code> displays a formatted hex > + * representation of the passed byte array. It also > + * allows for only a specified offset and length of > + * a particular array to be returned. > + * > + * @param bytes <code>byte[]</code> array to process. > + * @param pos <code>int</code> specifies offset to begin processing. > + * @param len <code>int</code> specifies the number of bytes to process. > + * @return <code>String</code> formatted hex representation of processed > + * array. > + */ > + private String getHexValue( byte[] bytes, int pos, int len ) { > + StringBuffer outBuf = new StringBuffer( bytes.length * 2 ); > + int bytesPerLine = 36; > + int cnt = 1; > + int groups = 4; > + int curPos = pos; > + int linePos = 1; > + boolean displayOffset = true; > + > + while ( len-- > 0 ) { > + if ( displayOffset ) { > + > + outBuf.append( "\n" + paddedHexString( pos, SHORTPADSIZE, > + true ) + ": " ); > + displayOffset = false; > + } > + > + outBuf.append( > + paddedHexString( ( int ) bytes[ pos ], BYTEPADSIZE, false ) ); > + linePos += 2; // Byte is padded to 2 characters > + > + if ( ( cnt % 4 ) == 0 ) { > + outBuf.append( " " ); > + linePos++; > + } > + > + // Now display the characters that are printable > + if ( ( cnt % ( groups * 4 ) ) == 0 ) { > + outBuf.append( " " ); > + > + while ( curPos <= pos ) { > + if ( !Character.isWhitespace( ( char ) bytes[ curPos ] ) ) { > + outBuf.append( ( char ) bytes[ curPos ] ); > + } else { > + outBuf.append( "." ); > + } > + > + curPos++; > + } > + > + curPos = pos + 1; > + linePos = 1; > + displayOffset = true; > } > + > + cnt++; > + pos++; > + } > + > + // pad out the line with spaces > + while ( linePos++ <= bytesPerLine ) { > + outBuf.append( " " ); > } > - return true; > + > + outBuf.append( " " ); > + // Now display the printable characters for the trailing bytes > + while ( curPos < pos ) { > + if ( !Character.isWhitespace( ( char ) bytes[ curPos ] ) ) { > + outBuf.append( ( char ) bytes[ curPos ] ); > + } else { > + outBuf.append( "." ); > + } > + > + curPos++; > + } > + > + return outBuf.toString(); > + } > + > + /* > + * <code>paddedHexString</code> pads the passed value > + * based on the specified wordsize and the value of the > + * prefixFlag. > + * > + * @param val an <code>int</code> value > + * @param wordsize an <code>int</code> value > + * @param prefixFlag a <code>boolean</code> value > + * @return a <code>String</code> value > + */ > + private String paddedHexString( int val, int wordsize, > + boolean prefixFlag ) { > + > + String prefix = prefixFlag ? "0x" : "" ; > + String hexVal = Integer.toHexString( val ); > + > + if ( hexVal.length() > wordsize ) > + hexVal = hexVal.substring( hexVal.length() - wordsize ); > + > + return ( prefix + ( wordsize > hexVal.length() ? > + ZEROS.substring( 0, wordsize - hexVal.length() ) : "" ) >+ hexVal ); > } > > // Compare the actual result and the expected result. > // Original compare - ignores spaces ( because most > // golden files are wrong !) > - private boolean compareWeek(String str1, String str2) { > + private boolean compareWeak(String str1, String str2) { > //System.out.println("In compareWeek"); > if ( str1==null || str2==null) return false; > > > ---- > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
Index: GTest.java =================================================================== RCS file: /home/cvspublic/jakarta-watchdog-4.0/src/tools/org/apache/tomcat/task/GTest.java,v retrieving revision 1.3 diff -u -r1.3 GTest.java --- GTest.java 2001/09/28 04:09:56 1.3 +++ GTest.java 2001/11/20 13:44:36 @@ -311,47 +311,59 @@ if( request.indexOf( "HTTP/1." ) > -1) { boolean match= ( responseLine!=null && responseLine.indexOf(returnCode) > -1); if( match != testCondition ) { - responseStatus = false; - System.out.println("ERROR in: " + request); - System.out.println(" Expecting: " + returnCode ); - System.out.println(" Got : " + responseLine); - if ( resultOut != null ) - { - expectedString = "<expectedReturnCode>" + returnCode + "</expectedReturnCode>\n"; - actualString = "<actualReturnCode>"+ responseLine + "</actualReturnCode>\n"; - resultOut.write(expectedString.getBytes() ); - resultOut.write(actualString.getBytes() ); - - } + responseStatus = false; + System.out.println("ERROR in: " + request); + System.out.println(" Expecting: " + returnCode ); + System.out.println(" Got : " + responseLine); + if ( resultOut != null ) + { + expectedString = "<expectedReturnCode>" + returnCode + +"</expectedReturnCode>\n"; + actualString = "<actualReturnCode>"+ responseLine + +"</actualReturnCode>\n"; + resultOut.write(expectedString.getBytes() ); + resultOut.write(actualString.getBytes() ); + + } } } if( expectHeaders != null ) { // Check if we got the expected headers if(headers==null) { - System.out.println("ERROR no response header, expecting header"); + System.out.println("ERROR no response header, expecting header"); } Enumeration e=expectHeaders.keys(); while( e.hasMoreElements()) { - String key=(String)e.nextElement(); - String value=(String)expectHeaders.get(key); - String respValue=(String)headers.get(key); - if( respValue==null || respValue.indexOf( value ) <0 ) { - System.out.println("ERROR expecting header " + key + ":" + - value + " GOT: " + respValue+ " HEADERS(" + headers + ")"); - if ( resultOut != null ) - { - expectedString = "<expectedHeader>" + key + ":"+ value + "</expectedHeader>\n"; - actualString = "<actualHeader>"+ key + ":" + respValue + "</actualHeader>\n"; - resultOut.write(expectedString.getBytes() ); - resultOut.write(actualString.getBytes() ); - - } - - return false; - } - } + String key=(String)e.nextElement(); + String value=(String)expectHeaders.get(key); + + Enumeration headerKeys = headers.keys(); + + String respValue = null; + while ( headerKeys.hasMoreElements() ) { + String headerKey = (String) headerKeys.nextElement(); + + if ( headerKey.equalsIgnoreCase( key ) ) { + respValue = (String) headers.get( headerKey ); + break; + } + } + + if( respValue==null || respValue.indexOf( value ) <0 ) { + System.out.println("ERROR expecting header " + key + ":" + + value + " GOT: " + respValue+ " HEADERS(" + +headers + ")"); + if ( resultOut != null ) + { + expectedString = "<expectedHeader>" + key + ":"+ value + +"</expectedHeader>\n"; + actualString = "<actualHeader>"+ key + ":" + respValue + +"</actualHeader>\n"; + resultOut.write(expectedString.getBytes() ); + resultOut.write(actualString.getBytes() ); + + } + + return false; + } + } } if( responseMatch != null ) {
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>