String contentEncoding = "UTF-8";
String testGetRequest =
"GET " + url
+ "?update=yes&d=1&d=2&d=&d=&d=&d=&d=&d=1&d=2&d=1&d=&d= "
+ "HTTP/1.0\r\n\r\n";
HTTPSamplerBase s = getSamplerForRequest(url, testGetRequest, contentEncoding);
assertEquals(HTTPSamplerBase.GET, s.getMethod());
assertEquals(contentEncoding, s.getContentEncoding());
// Check arguments
Arguments arguments = s.getArguments();
assertEquals(13, arguments.getArgumentCount());
checkArgument((HTTPArgument)arguments.getArgument(0), "update", "yes", "yes", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(1), "d", "1", "1", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(2), "d", "2", "2", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(3), "d", "", "", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(4), "d", "", "", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(5), "d", "", "", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(6), "d", "", "", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(7), "d", "", "", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(8), "d", "1", "1", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(9), "d", "2", "2", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(10), "d", "1", "1", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(11), "d", "", "", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(12), "d", "", "", contentEncoding, false);
// A HTTP POST request
contentEncoding = "UTF-8";
String postBody = "update=yes&d=1&d=2&d=&d=&d=&d=&d=&d=1&d=2&d=1&d=&d=";
String testPostRequest = "POST " + url + " HTTP/1.0\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());
assertFalse(s.getDoMultipartPost());
assertEquals(contentEncoding, s.getContentEncoding());
// Check arguments
arguments = s.getArguments();
assertEquals(13, arguments.getArgumentCount());
checkArgument((HTTPArgument)arguments.getArgument(0), "update", "yes", "yes", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(1), "d", "1", "1", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(2), "d", "2", "2", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(3), "d", "", "", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(4), "d", "", "", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(5), "d", "", "", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(6), "d", "", "", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(7), "d", "", "", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(8), "d", "1", "1", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(9), "d", "2", "2", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(10), "d", "1", "1", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(11), "d", "", "", contentEncoding, false);
checkArgument((HTTPArgument)arguments.getArgument(12), "d", "", "", contentEncoding, false);
// A HTTP POST request, with content-type text/plain
contentEncoding = "UTF-8";
postBody = "update=yes&d=1&d=2&d=&d=&d=&d=&d=&d=1&d=2&d=1&d=\uc385&d=";
testPostRequest = "POST " + url + " HTTP/1.1\r\n"
+ "Content-type: text/plain\r\n"
+ "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n"
+ "\r\n"
+ postBody;
s = getSamplerForRequest(url, testPostRequest, contentEncoding);
assertEquals(HTTPSamplerBase.POST, s.getMethod());
assertFalse(s.getDoMultipartPost());
assertEquals(contentEncoding, s.getContentEncoding());
// Check arguments
// We should have one argument, with the value equal to the post body
arguments = s.getArguments();
assertEquals(1, arguments.getArgumentCount());
checkArgument((HTTPArgument)arguments.getArgument(0), "", postBody, postBody, contentEncoding, false);
// A HTTP POST request, with content-type text/plain; charset=UTF-8
// The encoding should be picked up from the header we send with the request
contentEncoding = "UTF-8";
postBody = "update=yes&d=1&d=2&d=&d=&d=&d=&d=&d=1&d=2&d=1&d=\uc385&d=";
testPostRequest = "POST " + url + " HTTP/1.1\r\n"
+ "Content-type: text/plain; charset=" + contentEncoding + "\r\n"
+ "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n"
+ "\r\n"
+ postBody;
// Use null for url to simulate that HttpRequestHdr do not
// know the encoding for the page. Specify contentEncoding, so the
// request is "sent" using that encoding
s = getSamplerForRequest(null, testPostRequest, contentEncoding);
assertEquals(HTTPSamplerBase.POST, s.getMethod());
assertFalse(s.getDoMultipartPost());
assertEquals(contentEncoding, s.getContentEncoding());
// Check arguments
// We should have one argument, with the value equal to the post body
arguments = s.getArguments();
assertEquals(1, arguments.getArgumentCount());
checkArgument((HTTPArgument)arguments.getArgument(0), "", postBody, postBody, contentEncoding, false);
}