You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/01/18 01:02:30 UTC
cvs commit: jakarta-tomcat/src/tests/share/tests/jsp/Golden ForwardWithQuery.txt IncludeFile.txt Mismatch1.txt Mismatch2.txt PrintWriterTest.txt SimpleForward.txt SimpleInclude.txt welcome.txt HelloWorld.txt
costin 00/01/17 16:02:30
Modified: src/tests server.xml
src/tests/bin testJsp.xml
src/tests/share/tests GTest.java
src/tests/share/tests/jsp/Golden HelloWorld.txt
Added: src/tests/share/tests/jsp/Golden ForwardWithQuery.txt
IncludeFile.txt Mismatch1.txt Mismatch2.txt
PrintWriterTest.txt SimpleForward.txt
SimpleInclude.txt welcome.txt
Log:
Converted all tomcat tests to use <gtest> ( golden-file-based-test ).
Probably it should be moved in a new directory ( with the golden
results from share/test/jsp/Golden ) - and the build should
use the new directory.
If nobody -1 this change, we can remove all moo deps from
tomcat build and moo will remain part of jakarta-watchdog.
Note that GTest.java is just a 1 1/2-day hack, it can be cleaned
up and improved ( too many attributes, better support for
checking headers in result, etc), but it should be easier than
changing 25 java files.
Revision Changes Path
1.4 +5 -0 jakarta-tomcat/src/tests/server.xml
Index: server.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/tests/server.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- server.xml 1999/11/02 00:46:40 1.3
+++ server.xml 2000/01/18 00:02:28 1.4
@@ -28,6 +28,11 @@
defaultSessionTimeOut="30" isWARExpanded="true"
isWARValidated="false" isInvokerEnabled="true"
isWorkDirPersistent="false"/>
+
+ <Context path="/test" docBase="webpages"
+ defaultSessionTimeOut="30" isWARExpanded="true"
+ isWARValidated="false" isInvokerEnabled="true"
+ isWorkDirPersistent="false"/>
<!-- Old TcpEndpoint-based HttpServer. Will be deprecated soon!
<Connector className="org.apache.tomcat.server.HttpServerConnector">
</Connector>
1.2 +312 -4 jakarta-tomcat/src/tests/bin/testJsp.xml
Index: testJsp.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/tests/bin/testJsp.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- testJsp.xml 2000/01/17 02:17:31 1.1
+++ testJsp.xml 2000/01/18 00:02:28 1.2
@@ -1,18 +1,123 @@
<project name="TestRun" default="main" basedir="." init="init">
<target name="init">
- <property name="test.hostname" value="localhost" />
- <property name="test.port" value="8080" />
+ <property name="host" value="localhost" />
+ <property name="port" value="8080" />
<property name="gdir" value="jsp/Golden" />
<taskdef name="test" class="tests.Test" />
<taskdef name="gtest" class="tests.GTest" />
</target>
- <target name="startup">
- <java class="org.apache.tomcat.shell.Startup" args="" />
+ <!-- ==================== File tests ==================== -->
+ <target name="file">
+ <gtest description="Content Type Test"
+ request="GET /test/binaries/image1.gif HTTP/1.0"
+ expectHeaders="Content-Type:image/gif" />
+
+ <gtest description="File Integrity and Length Test"
+ request="GET /test/binaries/image1.gif HTTP/1.0"
+ goldenFile="${gdir}/image1.gif"
+ exactMatch="true" />
+
+ <gtest description="Welcome File Test1"
+ request="GET /test/welcome HTTP/1.0"
+ expectHeaders="Location:/welcome/"
+ returnCode="HTTP/1.0 302" />
+
+ <gtest description="Welcome File Test2"
+ request="GET /test/binaries HTTP/1.0"
+ returnCode="HTTP/1.0 200" />
+
+ <gtest description="Welcome File Test3"
+ request="GET /test/welcome/ HTTP/1.0"
+ returnCode="HTTP/1.0 200"
+ goldenFile="${gdir}/welcome.txt" />
+
</target>
+ <!-- ==================== Dispatch tests ==================== -->
+ <target name="dispatch">
+ <gtest description="SimpleRedirect"
+ request="GET /test/servlet/dispatch.SimpleRedirectServlet?/index.html HTTP/1.0"
+ expectHeaders="Location:http://${host}:${port}/index.html"
+ returnCode="HTTP/1.0 302"
+ />
+ <gtest description="SimpleRedirect2"
+ request="GET /test/servlet/dispatch.SimpleRedirectServlet?index.html HTTP/1.0"
+ expectHeaders="Location:http://${host}:${port}/test/servlet/index.html"
+ returnCode="HTTP/1.0 302"
+ />
+ <gtest description="SimpleInclude"
+ request="GET /test/servlet/dispatch.SimpleIncludeServlet HTTP/1.0"
+ expectHeaders="Content-Type:text/foobar"
+ returnCode="HTTP/1.0 200"
+ goldenFile="${gdir}/SimpleInclude.txt"
+ />
+ <gtest description="SimpleForward"
+ request="GET /test/servlet/dispatch.SimpleForwardServlet HTTP/1.0"
+ expectHeaders="Content-Type:text/funky"
+ returnCode="HTTP/1.0 200"
+ goldenFile="${gdir}/SimpleForward.txt"
+ />
+ <gtest description="PrintWriterTest"
+ request="GET /test/servlet/dispatch.PrintWriterTest1Servlet HTTP/1.0"
+ returnCode="HTTP/1.0 200"
+ responseMatch="PreInclude"
+ />
+ <gtest description="PrintWriterTest"
+ request="GET /test/servlet/dispatch.PrintWriterTest1Servlet HTTP/1.0"
+ returnCode="HTTP/1.0 200"
+ responseMatch="PostInclude"
+ />
+ <gtest description="PrintWriterTest"
+ request="GET /test/servlet/dispatch.PrintWriterTest1Servlet HTTP/1.0"
+ returnCode="HTTP/1.0 200"
+ responseMatch="Included servlet error: 500:"
+ />
+ <gtest description="Mismatch2"
+ request="GET /test/servlet/dispatch.Mismatch2 HTTP/1.0"
+ returnCode="HTTP/1.0 200"
+ goldenFile="${gdir}/Mismatch2.txt"
+ />
+
+ <gtest description="IncludeMismatch1-1"
+ request="GET /test/servlet/dispatch.IncludeMismatch1 HTTP/1.0"
+ returnCode="HTTP/1.0 200"
+ responseMatch="LINE1"
+ />
+
+ <gtest description="IncludeMismatch1-2"
+ request="GET /test/servlet/dispatch.IncludeMismatch1 HTTP/1.0"
+ returnCode="HTTP/1.0 200"
+ responseMatch="error: 500"
+ />
+
+ <gtest description="IncludeMismatch1-3"
+ request="GET /test/servlet/dispatch.IncludeMismatch1 HTTP/1.0"
+ returnCode="HTTP/1.0 200"
+ responseMatch="LINE1"
+ />
+
+ <gtest description="IncludeFile"
+ request="GET /test/servlet/dispatch.IncludeFileServlet HTTP/1.0"
+ returnCode="HTTP/1.0 200"
+ expectHeaders="Content-Type:text/foobar"
+ goldenFile="${gdir}/IncludeFile.txt"
+ />
+
+ <gtest description="ForwardWithQuery"
+ request="GET /test/servlet/dispatch.ForwardWithQueryServlet?name=Sun%20Microsystems&age=100000&city=Cupertino HTTP/1.0"
+ returnCode="HTTP/1.0 200"
+ expectHeaders="Content-Type:text/funky"
+ goldenFile="${gdir}/ForwardWithQuery.txt"
+ />
+
+
+
+ </target>
+
+ <!-- ==================== Jsp tests ==================== -->
<target name="jsp">
<gtest request="GET /test/jsp/HelloWorld.jsp HTTP/1.0"
goldenFile="${gdir}/HelloWorld.txt"
@@ -280,13 +385,216 @@
+ <target name="get">
+ <gtest request="GET /test/request/uri/does/not/exist"
+ responseMatch="Error: 404"
+ />
+
+ <gtest request="GET /test/request/uri/does/not/exist HTTP/1.0"
+ returnCode="HTTP/1.0 404 Not Found"
+ />
+
+ <gtest request="GET /test/"
+ returnCode="Error: "
+ magnitude="false" />
+
+ <gtest request=" GET / "
+ returnCode="Error: "
+ magnitude="false" />
+
+ <gtest request="GET /test/ HTTP/1.0"
+ returnCode="HTTP/1.0 200 OK"
+ />
+
+ <gtest request=" GET / HTTP/1.0"
+ returnCode="HTTP/1.0 200 OK"
+ />
+
+ <gtest request="GET /test/index.ht ml HTTP/1.0"
+ returnCode="HTTP/1.0 400 Bad Request"
+ />
+
+ <gtest request=" GET /index.ht ml HTTP/1.0 "
+ returnCode="HTTP/1.0 400 Bad Request"
+ />
+
+
+ <gtest request="GET /test/servlet HTTP/1.0"
+ returnCode="HTTP/1.0 404 Not Found"
+ />
+
+ <gtest request="GET /test/servlet/ HTTP/1.0"
+ returnCode="HTTP/1.0 404"
+ />
+
+ <gtest request="GET /test/servlet/foo HTTP/1.0"
+ returnCode="HTTP/1.0 404 Not Found"
+ />
+
+ <gtest request="GET /test/welcome HTTP/1.0"
+ returnCode="HTTP/1.0 302"
+ />
+
+
+ </target>
+
+
+ <target name="requestMap">
+ <gtest description="/foo/bar/index.html : 1.0 : 200"
+ request="GET /test/foo/bar/index.html HTTP/1.0"
+ responseMatch="Servlet: Servlet1"
+ />
+
+ <gtest description="/foo/bar/index.bop : 1.0 : 200"
+ request="GET /test/foo/bar/index.bop HTTP/1.0"
+ responseMatch="Servlet: Servlet1"
+ />
+
+ <gtest description="/baz : 1.0 : 200"
+ request="GET /test/baz HTTP/1.0"
+ responseMatch="Servlet: Servlet2"
+ />
+
+ <gtest description="/baz/index.html : 1.0 : 200"
+ request="GET /test/baz/index.html HTTP/1.0"
+ responseMatch="Servlet: Servlet2"
+ />
+
+ <gtest description="/catalog : 1.0 : 200"
+ request="GET /test/catalog HTTP/1.0"
+ responseMatch="Servlet: Servlet3"
+ />
+
+ <gtest description="/catalog/index.html : 1.0 : 200"
+ request="GET /test/catalog/index.html HTTP/1.0"
+ returnCode="HTTP/1.0 404 Not Found"
+ />
+
+ <gtest description="/catalog/racecar.bop : 1.0 : 200"
+ request="GET /test/catalog/racecar.bop HTTP/1.0"
+ responseMatch="Servlet: Servlet4"
+ />
+
+ <gtest description="/index.bop : 1.0 : 200"
+ request="GET /test/index.bop HTTP/1.0"
+ responseMatch="Servlet: Servlet4"
+ />
+ </target>
+
+ <target name="post">
+ <gtest request="POST /test/servlet/request.NotThere HTTP/1.0"
+ content="name=lightness of being"
+ returnCode="HTTP/1.0 404 Not Found"
+ />
+
+ <gtest request="POST /test/servlet/request.EchoServlet HTTP/1.0"
+ content="name=lightness of being"
+ returnCode="HTTP/1.0 200 OK"
+ />
+
+ <gtest request="GHOST /test/servlet/request.EchoServlet HTTP/1.0"
+ content="name=lightness of being"
+ returnCode="HTTP/1.0 501 Not Implemented"
+ />
+
+ <gtest request="POST /test/servlet/request.EchoServlet HT TP/1.0"
+ content="name=lightness of being"
+ returnCode="Error: 400"
+ />
+
+ <gtest request="POST "
+ content="name=lightness of being"
+ returnCode="Error: 400"
+ />
+
+ <gtest request="POST /test/servlet/request.EchoServlet HTTP/1.0"
+ content=""
+ returnCode="HTTP/1.0 200 OK"
+ />
+
+ <gtest request="POST /test/servlet HTTP/1.0"
+ content=""
+ returnCode="HTTP/1.0 404 Not Found"
+ />
+
+ <gtest request="POST /test/servlet/ HTTP/1.0"
+ content=""
+ returnCode="HTTP/1.0 404"
+ />
+
+ <gtest request="POST /test/ HTTP/0.9"
+ content=""
+ returnCode="HTTP/1.0 400 Bad Request"
+ />
+
+ <gtest request="POST /test/servlet/request.EchoServlet HTTP/0.9"
+ content="name=lightness of being"
+ returnCode="HTTP/1.0 200 OK"
+ />
+
+ <gtest request="POST /test/servlet/request.EchoServlet HTTP/0.9"
+ content="name=lightness of being,,,,,,,....###///&&@@@@@***"
+ returnCode="HTTP/1.0 200 OK"
+ />
+
+ <gtest request="POST /test/servlet/request.EchoServlet HTTP/0.9"
+ content="name=lightness of being,,,,,,,....###///&&&&@@@@@***"
+ returnCode="HTTP/1.0 200 OK"
+ />
+
+ <gtest request="POST \/test/servlet/request.EchoServlet?name=sun&age=2000 HTTP/0.9"
+ content="name=lightness of being,,,,,,,....###///&@@@@@***"
+ returnCode="HTTP/1.0 200 OK"
+ />
+
+ <gtest request="POST \ HTTP/0.9"
+ content="name=lightness of being"
+ returnCode="Error: 400"
+ />
+
+ <gtest request="POST /test/servlet/request.EchoServlet HTTP/1.0"
+ content="name=lightness of being"
+ returnCode="HTTP/1.0 200 OK"
+ />
+
+ <gtest request="post /test/servlet/request.EchoServlet HTTP/1.0"
+ content="name=lightness of being"
+ returnCode="HTTP/1.0 501 Not Implemented"
+ />
+
+ <gtest request="GET http://www.javasoft.com/index.html HTTP/1.0 "
+ returnCode="HTTP/1.0 400 Bad Request"
+ />
+
+ <gtest request="POST /test/servlet/request.EchoServlet HTTP/1.0"
+ headers="Content-Encoding: x-gzip"
+ content="name=lightness of being"
+ returnCode="HTTP/1.0 200 OK"
+ />
+
+ <gtest request="POST /test/servlet/request.EchoServlet HTTP/4.4"
+ content="name=lightness of being"
+ returnCode="HTTP/1.0 200 OK"
+ />
+ </target>
+
+
+ <target name="startup">
+ <java class="org.apache.tomcat.shell.Startup" args="" />
+ </target>
+
+
<target name="client" depends="jsp,wrong_request">
</target>
+
<target name="shutdown">
<java class="org.apache.tomcat.shell.Startup" args="" />
</target>
+
<target name="main" depends="startup,client,shutdown" />
+
+
</project>
1.2 +125 -40 jakarta-tomcat/src/tests/share/tests/GTest.java
Index: GTest.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/tests/share/tests/GTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GTest.java 2000/01/17 02:17:31 1.1
+++ GTest.java 2000/01/18 00:02:29 1.2
@@ -17,20 +17,30 @@
String host="localhost";
int port=8080;
int debug=0;
+
String description="No description";
+ String request;
+ Hashtable requestHeaders;
+ String content;
+
+ // Expected response
boolean magnitude=true;
boolean exactMatch=false;
- String request;
-
+ // Match the body against a golden file
String goldenFile;
+ // Match the body against a string
+ String responseMatch;
+ // the response should include the following headers
+ Hashtable expectHeaders;
+ // Match request line
String returnCode="";
+ // Actual response
String responseLine;
String responseBody;
Hashtable headers;
-
public GTest() {
}
@@ -67,9 +77,44 @@
this.description=description;
}
+ public void setContent(String s) {
+ this.content=s;
+ }
+
public void setDebug( String debugS ) {
debug=Integer.valueOf( debugS).intValue();
}
+
+ public void setMagnitude( String magnitudeS ) {
+ magnitude = Boolean.valueOf(magnitudeS).booleanValue();
+ }
+
+ public void setGoldenFile( String s ) {
+ this.goldenFile=s;
+ }
+
+ public void setExpectHeaders( String s ) {
+ this.expectHeaders=new Hashtable();
+ parseHeader( s, expectHeaders );
+ }
+
+ public void setResponseMatch( String s ) {
+ this.responseMatch=s;
+ }
+
+ public void setRequest( String s ) {
+ this.request=s;
+ }
+
+ public void setReturnCode( String s ) {
+ this.returnCode=s;
+ }
+
+ public void setHeaders( String s ) {
+ requestHeaders=new Hashtable();
+ parseHeader( s, requestHeaders );
+ }
+
public void execute() throws BuildException {
@@ -92,22 +137,6 @@
}
}
- public void setMagnitude( String magnitudeS ) {
- magnitude = Boolean.valueOf(magnitudeS).booleanValue();
- }
-
- public void setGoldenFile( String s ) {
- this.goldenFile=s;
- }
-
- public void setRequest( String s ) {
- this.request=s;
- }
-
- public void setReturnCode( String s ) {
- this.returnCode=s;
- }
-
// XXX move to exec, get rid of TestResult
public boolean runTest()
throws Exception
@@ -123,14 +152,50 @@
boolean responseStatus = true;
// If returnCode doesn't match
- 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( 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( expectHeaders != null ) {
+ // Check if we got the expected headers
+ if(headers==null) {
+ 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 + ")");
+
+ return false;
+ }
+ }
+
}
+
+ if( responseMatch != null ) {
+ // check if we got the string we wanted
+ if( responseBody == null ) {
+ System.out.println("ERROR: got no response, expecting " + responseMatch);
+ return false;
+ }
+ if( responseBody.indexOf( responseMatch ) < 0) {
+ System.out.println("ERROR: expecting match on " + responseMatch);
+ System.out.println("GOT: " );
+ System.out.println(responseBody );
+ }
+ }
+ // compare the body
if( goldenFile==null) return responseStatus;
// Get the expected result from the "golden" file.
StringBuffer expResult = getExpectedResult();
@@ -171,16 +236,32 @@
OutputStreamWriter out=new OutputStreamWriter(s.getOutputStream());
PrintWriter pw = new PrintWriter(out);
pw.println(request);
- pw.println("");
+
+ if( content != null) {
+ pw.println("Content-Length: " + content.length());
+ }
+
+ if( request.indexOf( "HTTP/1." ) > -1)
+ pw.println("");
+
+ if( content != null) {
+ pw.println(content);
+ // XXX no /n at the end -see HTTP specs!
+ }
+
pw.flush();
- responseLine = read( is );
try {
- headers=parseHeaders( is );
+ // http 0.9
+ if( request.indexOf( "HTTP/1." ) > -1) {
+ responseLine = read( is );
+ headers=parseHeaders( is );
+ }
// else do content matching as well
StringBuffer result = readBody( is );
- responseBody=result.toString();
+ if(result!=null)
+ responseBody=result.toString();
} catch( SocketException ex ) {
s.close();
@@ -286,20 +367,24 @@
break;
}
- // Parse the header name and value
- int colon = line.indexOf(":");
- if (colon < 0) {
- System.out.println("ERROR: Wrong Header Line: " + line );
- return headers;
- }
-
- String name = line.substring(0, colon).trim();
- String value = line.substring(colon + 1).trim();
-
- headers.put(name, value);
+ parseHeader( line, headers);
}
return headers;
+ }
+
+ private void parseHeader(String line, Hashtable headers) {
+ // Parse the header name and value
+ int colon = line.indexOf(":");
+ if (colon < 0) {
+ System.out.println("ERROR: Wrong Header Line: " + line );
+ return;
+ }
+ String name = line.substring(0, colon).trim();
+ String value = line.substring(colon + 1).trim();
+
+ // System.out.println("HEADER: " +name + " " + value);
+ headers.put(name, value);
}
/**
1.3 +1 -1 jakarta-tomcat/src/tests/share/tests/jsp/Golden/HelloWorld.txt
Index: HelloWorld.txt
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/tests/share/tests/jsp/Golden/HelloWorld.txt,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HelloWorld.txt 1999/11/04 01:39:46 1.2
+++ HelloWorld.txt 2000/01/18 00:02:29 1.3
@@ -1,3 +1,3 @@
<html>
- HelloWorld
+HelloWorld
</html>
1.1 jakarta-tomcat/src/tests/share/tests/jsp/Golden/ForwardWithQuery.txt
Index: ForwardWithQuery.txt
===================================================================
FORWARDWITHQUERYTARGET
city=Cupertino&age=100000&name=Sun Microsystems
1.1 jakarta-tomcat/src/tests/share/tests/jsp/Golden/IncludeFile.txt
Index: IncludeFile.txt
===================================================================
LINE1
FOO
LINE2
1.1 jakarta-tomcat/src/tests/share/tests/jsp/Golden/Mismatch1.txt
Index: Mismatch1.txt
===================================================================
PWO OUT
YES
FINISH
1.1 jakarta-tomcat/src/tests/share/tests/jsp/Golden/Mismatch2.txt
Index: Mismatch2.txt
===================================================================
SOS OUT
YES
FINISH
1.1 jakarta-tomcat/src/tests/share/tests/jsp/Golden/PrintWriterTest.txt
Index: PrintWriterTest.txt
===================================================================
1.1 jakarta-tomcat/src/tests/share/tests/jsp/Golden/SimpleForward.txt
Index: SimpleForward.txt
===================================================================
TARGET1
1.1 jakarta-tomcat/src/tests/share/tests/jsp/Golden/SimpleInclude.txt
Index: SimpleInclude.txt
===================================================================
LINE1
TARGET1
LINE2
TARGET1
LINE3
1.1 jakarta-tomcat/src/tests/share/tests/jsp/Golden/welcome.txt
Index: welcome.txt
===================================================================
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
This is just a html file for the welcome file tests. (1999)
</body>
</html>