Hi All,
I have a couple of modifications to the Test Recorder.
Fixes:
* The Test Recorder (TR) had a bug where, in some cases, during record and/or playback the html captured by the TR did not match the html returned to the browser by the container. The bug was encountered in some usages of the jsp:forward tag in a jsp page, where the container desired to reset the jsp writer buffer. The fix consists of implementing the reset() and resetBuffer() methods in the ResponseWrapper to reset the TR output buffer when requested.
* Fixed a bug where in some cases the test recorder test links were not properly produced.
* Modified the string representation of exceptions during logging: included exception messages and stack traces of nested exceptions.
* Added some debugging around request data - request params, headers, post params, etc.
* Some simple cleanup to netui\test\ant\testRecorder.xml
Thanks, Patrick.
Index: netui/test/ant/testRecorder.xml
===================================================================
--- netui/test/ant/testRecorder.xml (revision 47607)
+++ netui/test/ant/testRecorder.xml (working copy)
@@ -201,12 +201,10 @@
</or>
</condition>
- <echo>config.jar: ${_config.jar}</echo>
<echo>log4j.config: ${log4j.config}</echo>
<echo>playback list: ${_list}</echo>
<echo>playback categories: ${_categories}</echo>
<echo>playback webapps: ${playback.webapps}</echo>
- <echo>playback config jar: ${_config.jar}</echo>
<echo>test.recorder.classpath: ${test.recorder.classpath}</echo>
<junit dir="${netui.ant.dir}" fork="true"
errorproperty="playback.drt.error" failureproperty="playback.drt.failure"
@@ -221,7 +219,7 @@
<sysproperty key="test.recorder.run.tests" value="${_list}"/>
<sysproperty key="test.recorder.run.categories"
value="${_categories}"/>
<sysproperty key="test.recorder.run.webapps"
value="${playback.webapps}"/>
- <sysproperty key="test.recorder.run.results.delete"
value="${results.delete}"/>
+ <sysproperty key="test.recorder.run.results.delete"
value="${_results.delete}"/>
<sysproperty key="netuidrt.logdir"
path="${build.dir}/testRecorder"/>
<sysproperty key="log4j.configuration"
value="file:${log4j.config}"/>
@@ -259,13 +257,6 @@
<target name="playback"
description="Plays back a list of pre-recorded tests, set the
'playback.list' property to specify a list of tests.">
- <fail unless="testRecorder.config.name" message="No test recorder
config name (property: 'testRecorder.config.name') specified"/>
- <echo>testRecorder.config.name: ${testRecorder.config.name}</echo>
- <property name="_config.jar"
location="${_testRecorder.config.dir}/${testRecorder.config.name}.jar"/>
- <available property="config.jar.available" file="${_config.jar}"/>
- <fail unless="config.jar.available" message="Can't find a test
recorder config JAR at ${_config.jar} to copy"/>
- <echo>_config.jar: ${_config.jar}</echo>
-
<antcall target="playback.tests">
<param name="formatter.type" value="plain"/>
<param name="formatter.usefile" value="false"/>
Index:
netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/Constants.java
===================================================================
---
netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/Constants.java
(revision 47607)
+++
netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/Constants.java
(working copy)
@@ -61,6 +61,7 @@
public static final String REQUEST_NEW_EXCEPTION_MARKER_ATTRIBUTE =
"testRecorder.request.marked.exception.new";
public static final String STATE_STORAGE_KEY = "testRecorder.state.";
public static final String BODY_END = "</body>";
+ public static final String BODY_END_CAPS = "</BODY>";
public static final String NL = "\n";
public static final String EMPTY_STRING = "";
// 'cmd' values
Index:
netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/Logger.java
===================================================================
---
netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/Logger.java
(revision 47607)
+++
netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/Logger.java
(working copy)
@@ -145,12 +145,28 @@
}
}
- public static String format( Object m, Throwable t ) {
+ public static String format( final Object obj, final Throwable t ) {
if ( t == null ) {
- return m.toString();
+ return obj.toString();
}
+ Throwable ex = t;
+ StringBuffer sb = new StringBuffer( 512 );
+ sb.append( "object( " + obj + " )\n" );
+ while ( ex != null ) {
+ sb.append( format( ex ) + "\n");
+ ex = ex.getCause();
+ }
+ return sb.toString();
+ }
+
+ public static String format( Throwable t ) {
+ if ( t == null ) {
+ return "NULL";
+ }
StringWriter sw = new StringWriter();
t.printStackTrace( new PrintWriter( sw ) );
- return m + "\n\n" + "Throwable: " + t.toString() + "\nStack Trace:\n"
+ sw.toString();
+ return "throwable: msg( " + t.getMessage() + " )\ntoString( " +
t.toString() +
+ " )\nstack trace:\n" + sw.toString();
}
+
}
Index:
netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/ResponseWrapper.java
===================================================================
---
netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/ResponseWrapper.java
(revision 47607)
+++
netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/ResponseWrapper.java
(working copy)
@@ -39,7 +39,7 @@
private ByteArrayOutputStream output;
private PrintWriter writer;
private ServletOutputStream servletStream;
- private int statusCode = 200;
+ private int statusCode = SC_OK;
private String reason = "";
private String outputString = null;
@@ -100,6 +100,29 @@
}
}
+ public void reset() {
+ if ( log.isDebugEnabled() ) {
+ log.debug( "reset()" );
+ }
+ if ( isCommitted() ) {
+ throw new IllegalStateException( "response is already commited,
reset not allowed" );
+ }
+ output.reset();
+ statusCode = SC_OK;
+ super.reset();
+ }
+
+ public void resetBuffer() {
+ if ( log.isDebugEnabled() ) {
+ log.debug( "resetBuffer()" );
+ }
+ if ( isCommitted() ) {
+ throw new IllegalStateException( "response is already commited,
reset buffer not allowed" );
+ }
+ output.reset();
+ super.resetBuffer();
+ }
+
// package scoped
int getStatusCode() {
return statusCode;
@@ -124,6 +147,7 @@
return outputString;
}
+
/**
* Internal class that implements a ServletOutputStream. This is used to
* return our output stream to the JSP world.
Index:
netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/DefaultFilterData.java
===================================================================
---
netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/DefaultFilterData.java
(revision 47607)
+++
netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/DefaultFilterData.java
(working copy)
@@ -94,6 +94,9 @@
// capture request data, this may not be necessary if we aren't
recording or playing back.
reqData = RequestData.populate( (HttpServletRequest) request, new
RequestData() );
+ if ( log.isDebugEnabled() ) {
+ log.debug( "request data( " + reqData + " )" );
+ }
}
protected void testForTestId( ServletRequest request ) {
Index:
netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/TestRecorderFilter.java
===================================================================
---
netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/TestRecorderFilter.java
(revision 47607)
+++
netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/TestRecorderFilter.java
(working copy)
@@ -452,6 +452,9 @@
if ( addLink ) {
int index = body.lastIndexOf( Constants.BODY_END );
if ( index == -1 ) {
+ index = body.lastIndexOf( Constants.BODY_END_CAPS );
+ }
+ if ( index == -1 ) {
if ( log.isDebugEnabled() ) {
log.debug( "</body> was not found:\nbody(" + body +
")" );
}
