String testGetRequest = "GET " + url
+ "?" + queryString
+ " HTTP/1.1\r\n\r\n";
// Use null for url and contentEncoding, to simulate that HttpRequestHdr do not
// know the encoding for the page
HTTPSamplerBase s = getSamplerForRequest(null, testGetRequest, null);
assertEquals(HTTPSamplerBase.GET, s.getMethod());
assertEquals(queryString, s.getQueryString());
assertEquals(contentEncoding, s.getContentEncoding());
// Check arguments
Arguments arguments = s.getArguments();
assertEquals(3, arguments.getArgumentCount());
// When the encoding is not known, the argument will get the encoded value, and the "encode?" set to false
checkArgument((HTTPArgument)arguments.getArgument(0), "abc%3FSPACE", "a+b", "a+b", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(1), "space", "a%20b", "a%20b", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(2), "query", "What%3F", "What%3F", contentEncoding, false);
// A HTTP GET request, with UTF-8 encoding
contentEncoding = "UTF-8";
queryString = "abc%3FSPACE=a+b&space=a%20b&query=What%3F";
testGetRequest = "GET " + url
+ "?" + queryString
+ " HTTP/1.1\r\n\r\n";
s = getSamplerForRequest(url, testGetRequest, contentEncoding);
assertEquals(HTTPSamplerBase.GET, s.getMethod());
String expectedQueryString = "abc%3FSPACE=a+b&space=a+b&query=What%3F";
assertEquals(expectedQueryString, s.getQueryString());
assertEquals(contentEncoding, s.getContentEncoding());
// Check arguments
arguments = s.getArguments();
assertEquals(3, arguments.getArgumentCount());
checkArgument((HTTPArgument)arguments.getArgument(0), "abc?SPACE", "a b", "a+b", contentEncoding, true);
checkArgument((HTTPArgument)arguments.getArgument(1), "space", "a b", "a+b", contentEncoding, true);
checkArgument((HTTPArgument)arguments.getArgument(2), "query", "What?", "What%3F", contentEncoding, true);
// A HTTP POST request, with unknown encoding
contentEncoding = "";
String postBody = "abc%3FSPACE=a+b&space=a%20b&query=What%3F";
String testPostRequest = "POST " + url + " HTTP/1.1\r\n"
+ "Content-type: "
+ HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED + "\r\n"
+ "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n"
+ "\r\n"
+ postBody;
// Use null for url and contentEncoding, to simulate that HttpRequestHdr do not
// know the encoding for the page
s = getSamplerForRequest(null, testPostRequest, null);
assertEquals(HTTPSamplerBase.POST, s.getMethod());
assertEquals(queryString, s.getQueryString());
assertEquals(contentEncoding, s.getContentEncoding());
assertFalse(s.getDoMultipartPost());
// Check arguments
arguments = s.getArguments();
assertEquals(3, arguments.getArgumentCount());
// When the encoding is not known, the argument will get the encoded value, and the "encode?" set to false
checkArgument((HTTPArgument)arguments.getArgument(0), "abc%3FSPACE", "a+b", "a+b", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(1), "space", "a%20b", "a%20b", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(2), "query", "What%3F", "What%3F", contentEncoding, false);
// A HTTP POST request, with UTF-8 encoding
contentEncoding = "UTF-8";
postBody = "abc?SPACE=a+b&space=a%20b&query=What?";
testPostRequest = "POST " + url + " HTTP/1.1\n"
+ "Content-type: "
+ HTTPSamplerBase.APPLICATION_X_WWW_FORM_URLENCODED + "\r\n"
+ "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n"
+ "\r\n"
+ postBody;
s = getSamplerForRequest(url, testPostRequest, contentEncoding);
assertEquals(HTTPSamplerBase.POST, s.getMethod());
expectedQueryString = "abc%3FSPACE=a+b&space=a+b&query=What%3F";
assertEquals(expectedQueryString, s.getQueryString());
assertEquals(contentEncoding, s.getContentEncoding());
assertFalse(s.getDoMultipartPost());
// Check arguments
arguments = s.getArguments();
assertEquals(3, arguments.getArgumentCount());
checkArgument((HTTPArgument)arguments.getArgument(0), "abc?SPACE", "a b", "a+b", contentEncoding, true);
checkArgument((HTTPArgument)arguments.getArgument(1), "space", "a b", "a+b", contentEncoding, true);
checkArgument((HTTPArgument)arguments.getArgument(2), "query", "What?", "What%3F", contentEncoding, true);
}