rlubke 02/01/23 14:52:36
Modified: src/tools/org/apache/tomcat/task GTest.java
Log:
- Added support for nesting of gtest tasks. This will allow the creation
of tests where multiple successful requests are required.
* If all nested tasks succeed as well as the top level task, then the
top level task will report success.
* If the top level task or any of the nested tasks fail, then information
will be displayed about that particular failure, and the top test
will display the FAILED message.
* All nested tasks must set the nested attribute to "true".
Example:
<gtest request="GET / HTTP/1.0" testName="nestedTest" host="${host}"
port="${port}" returnCode="200">
<gtest request="GET /test HTTP/1.0" host="${host}" port="${port}"
returnCode="200" nested="true"/>
</gtest>
This functionality will be used be new JSP tests that will be integrated
in the near future.
Revision Changes Path
1.16 +39 -9 jakarta-watchdog-4.0/src/tools/org/apache/tomcat/task/GTest.java
Index: GTest.java
===================================================================
RCS file:
/home/cvs/jakarta-watchdog-4.0/src/tools/org/apache/tomcat/task/GTest.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- GTest.java 22 Jan 2002 13:39:15 -0000 1.15
+++ GTest.java 23 Jan 2002 22:52:36 -0000 1.16
@@ -11,11 +11,12 @@
import java.net.*;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
+import org.apache.tools.ant.TaskContainer;
// derived from Jsp
-public class GTest extends Task {
+public class GTest extends Task implements TaskContainer {
private static final String ZEROS = "00000000";
private static final String CRLF = "\r\n";
@@ -26,17 +27,23 @@
private static int failureCount = 0;
private static int passCount = 0;
+ private static boolean result = false;
String prefix = "http";
String host = "localhost";
int port = 8080;
int debug = 0;
+ private ArrayList children = new ArrayList();
+
String description = "No description";
String request;
HashMap requestHeaders = new HashMap();
String content;
+
+ // true if task is nested
+ private boolean nested = false;
// Expected response
boolean magnitude = true;
@@ -90,7 +97,8 @@
* Creates a new <code>GTest</code> instance.
*
*/
- public GTest() {}
+ public GTest() {
+ }
/**
* <code>setTestSession</code> adds a
@@ -339,6 +347,10 @@
getHeaderDetails( s, unexpectedHeaders, false );
}
+ public void setNested( String s ) {
+ nested = Boolean.valueOf( s ).booleanValue();
+ }
+
/**
* <code>setResponseMatch</code> Match the
* passed value in the server's response.
@@ -409,6 +421,15 @@
}
/**
+ * Add a Task to this container
+ *
+ * @param Task to add
+ */
+ public void addTask(Task task) {
+ children.add(task);
+ }
+
+ /**
* <code>execute</code> Executes the test.
*
* @exception BuildException if an error occurs
@@ -417,7 +438,7 @@
try {
- if ( resultOut != null ) {
+ if ( resultOut != null && !nested ) {
resultOut.write( "<test>".getBytes() );
resultOut.write( ( "\n<testName>" + testName + "</testName>"
).getBytes() );
resultOut.write( ( "\n<assertion>" + assertion + "</assertion>"
).getBytes() );
@@ -426,31 +447,39 @@
dispatch( request, requestHeaders );
- boolean result = checkResponse( magnitude );
+ result = checkResponse( magnitude );
- if ( result ) {
+ if ( !children.isEmpty() ) {
+ Iterator iter = children.iterator();
+ while (iter.hasNext()) {
+ Task task = (Task) iter.next();
+ task.execute();
+ }
+ }
+
+ if ( result && !nested ) {
passCount++;
if ( resultOut != null ) {
resultOut.write( "<result>PASS</result>\n".getBytes() );
}
if ( testName != null ) {
- System.out.println( " PASSED " + testName + " (" + request +
")" );
+ System.out.println( " PASSED " + testName + "\n (" +
request + ")" );
} else {
System.out.println( " PASSED " + request );
}
- } else {
+ } else if ( !result && !nested ){
failureCount++;
if ( resultOut != null ) {
resultOut.write( "<result>FAIL</result>\n".getBytes() );
}
if ( testName != null ) {
- System.out.println( " FAILED " + testName + " (" + request +
")" );
+ System.out.println( " FAILED " + testName + "\n (" +
request + ")" );
} else {
System.out.println( " FAILED " + request );
}
}
- if ( resultOut != null ) {
+ if ( resultOut != null && !nested ) {
resultOut.write( "</test>\n".getBytes() );
if ( lastTask ) {
@@ -473,6 +502,7 @@
ex.printStackTrace();
}
+
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>