Author: sebb
Date: Wed Oct 17 05:55:27 2007
New Revision: 585470
URL: http://svn.apache.org/viewvc?rev=585470&view=rev
Log:
Added helper method checkHeaderTypeLength() to display more information when
failures occur.
Modified:
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java
Modified:
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java?rev=585470&r1=585469&r2=585470&view=diff
==============================================================================
---
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java
(original)
+++
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java
Wed Oct 17 05:55:27 2007
@@ -740,14 +740,7 @@
assertNotNull(boundaryString);
byte[] expectedPostBody = createExpectedFormdataOutput(boundaryString,
contentEncoding, titleField, titleValue, descriptionField, descriptionValue,
true, true);
// Check request headers
- assertTrue(isInRequestHeaders(res.getRequestHeaders(),
HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" +
boundaryString));
- assertTrue(
- isInRequestHeaders(
- res.getRequestHeaders(),
- HTTPSamplerBase.HEADER_CONTENT_LENGTH,
- Integer.toString(expectedPostBody.length)
- )
- );
+ checkHeaderTypeLength(res.getRequestHeaders(), "multipart/form-data" +
"; boundary=" + boundaryString, expectedPostBody.length);
// Check post body from the result query string
checkArraysHaveSameContent(expectedPostBody,
res.getQueryString().getBytes(contentEncoding));
@@ -765,14 +758,7 @@
fail("No header and body section found");
}
// Check response headers
- assertTrue(isInRequestHeaders(headersSent,
HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" +
boundaryString));
- assertTrue(
- isInRequestHeaders(
- headersSent,
- HTTPSamplerBase.HEADER_CONTENT_LENGTH,
- Integer.toString(expectedPostBody.length)
- )
- );
+ checkHeaderTypeLength(headersSent, "multipart/form-data" + ";
boundary=" + boundaryString, expectedPostBody.length);
// Check post body which was sent to the mirror server, and
// sent back by the mirror server
checkArraysHaveSameContent(expectedPostBody,
bodySent.getBytes(contentEncoding));
@@ -802,14 +788,7 @@
assertNotNull(boundaryString);
byte[] expectedPostBody =
createExpectedFormAndUploadOutput(boundaryString, contentEncoding, titleField,
titleValue, descriptionField, descriptionValue, fileField, fileValue,
fileMimeType, fileContent);
// Check request headers
- assertTrue(isInRequestHeaders(res.getRequestHeaders(),
HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" +
boundaryString));
- assertTrue(
- isInRequestHeaders(
- res.getRequestHeaders(),
- HTTPSamplerBase.HEADER_CONTENT_LENGTH,
- Integer.toString(expectedPostBody.length)
- )
- );
+ checkHeaderTypeLength(res.getRequestHeaders(), "multipart/form-data" +
"; boundary=" + boundaryString, expectedPostBody.length);
// We cannot check post body from the result query string, since that
will not contain
// the actual file content, but placeholder text for file content
//checkArraysHaveSameContent(expectedPostBody,
res.getQueryString().getBytes(contentEncoding));
@@ -820,14 +799,7 @@
fail("No header and body section found");
}
// Check response headers
- assertTrue(isInRequestHeaders(headersSent,
HTTPSamplerBase.HEADER_CONTENT_TYPE, "multipart/form-data" + "; boundary=" +
boundaryString));
- assertTrue(
- isInRequestHeaders(
- headersSent,
- HTTPSamplerBase.HEADER_CONTENT_LENGTH,
- Integer.toString(expectedPostBody.length)
- )
- );
+ checkHeaderTypeLength(headersSent, "multipart/form-data" + ";
boundary=" + boundaryString, expectedPostBody.length);
byte[] bodySent = getBodySent(res.getResponseData());
assertNotNull("Sent body should not be null", bodySent);
// Check post body which was sent to the mirror server, and
@@ -849,15 +821,8 @@
// Check URL
assertEquals(sampler.getUrl(), res.getURL());
// Check request headers
- assertTrue(isInRequestHeaders(res.getRequestHeaders(),
HTTPSamplerBase.HEADER_CONTENT_TYPE,
HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED));
- assertTrue(
- isInRequestHeaders(
- res.getRequestHeaders(),
- HTTPSamplerBase.HEADER_CONTENT_LENGTH,
-
Integer.toString(expectedPostBody.getBytes(contentEncoding).length)
- )
- );
- // Check post body from the result query string
+ checkHeaderTypeLength(res.getRequestHeaders(),
HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED,
expectedPostBody.getBytes(contentEncoding).length);
+ // Check post body from the result query string
checkArraysHaveSameContent(expectedPostBody.getBytes(contentEncoding),
res.getQueryString().getBytes(contentEncoding));
// Find the data sent to the mirror server, which the mirror server is
sending back to us
@@ -874,14 +839,7 @@
fail("No header and body section found");
}
// Check response headers
- assertTrue(isInRequestHeaders(headersSent,
HTTPSamplerBase.HEADER_CONTENT_TYPE,
HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED));
- assertTrue(
- isInRequestHeaders(
- headersSent,
- HTTPSamplerBase.HEADER_CONTENT_LENGTH,
-
Integer.toString(expectedPostBody.getBytes(contentEncoding).length)
- )
- );
+ checkHeaderTypeLength(headersSent,
HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED,
expectedPostBody.getBytes(contentEncoding).length);
// Check post body which was sent to the mirror server, and
// sent back by the mirror server
checkArraysHaveSameContent(expectedPostBody.getBytes(contentEncoding),
bodySent.getBytes(contentEncoding));
@@ -1055,6 +1013,14 @@
return checkRegularExpression(requestHeaders, headerName + ": " +
headerValue);
}
+ private void checkHeaderTypeLength(String requestHeaders, String
contentType, int contentLen) {
+ boolean typeOK = isInRequestHeaders(requestHeaders,
HTTPSamplerBase.HEADER_CONTENT_TYPE, contentType);
+ boolean lengOK = isInRequestHeaders(requestHeaders,
HTTPSamplerBase.HEADER_CONTENT_LENGTH, Integer.toString(contentLen));
+ if (!typeOK || !lengOK){
+ fail("Expected type:" + contentType + " & length: " +contentLen
+ " in:\n"+ requestHeaders);
+ }
+ }
+
private String getSentRequestHeaderValue(String requestHeaders, String
headerName) {
Perl5Matcher localMatcher = JMeterUtils.getMatcher();
String expression = ".*" + headerName + ": (\\d*).*";
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]