use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.
the class TestHttpRequestHdr method testPostMultipartFileUpload.
@Test
public void testPostMultipartFileUpload() throws Exception {
String url = "http://localhost/matrix.html";
// A HTTP POST request, multipart/form-data, simple values,
String contentEncoding = "UTF-8";
String boundary = "xf8SqlDNvmn6mFYwrioJaeUR2_Z4cLRXOSmB";
String endOfLine = "\r\n";
String fileFieldValue = "test_file";
String fileName = "somefilename.txt";
String mimeType = "text/plain";
String fileContent = "somedummycontent\n\ndfgdfg\r\nfgdgdg\nContent-type:dfsfsfds";
String postBody = createMultipartFileUploadBody(fileFieldValue, fileName, mimeType, fileContent, boundary, endOfLine);
String testPostRequest = createMultipartFormRequest(url, postBody, contentEncoding, boundary, endOfLine);
HTTPSamplerBase s = getSamplerForRequest(url, testPostRequest, contentEncoding);
assertEquals(HTTPConstants.POST, s.getMethod());
assertEquals(contentEncoding, s.getContentEncoding());
assertEquals("", s.getQueryString());
assertTrue(s.getDoMultipart());
// Check arguments
Arguments arguments = s.getArguments();
assertEquals(0, arguments.getArgumentCount());
// Assume there's at least one file
HTTPFileArg hfa = s.getHTTPFiles()[0];
assertEquals(fileFieldValue, hfa.getParamName());
assertEquals(fileName, hfa.getPath());
assertEquals(mimeType, hfa.getMimeType());
}
use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.
the class TestHttpRequestHdr method testPostMultipartFormData.
@Test
public void testPostMultipartFormData() throws Exception {
String url = "http://localhost/matrix.html";
// A HTTP POST request, multipart/form-data, simple values,
String contentEncoding = "UTF-8";
String boundary = "xf8SqlDNvmn6mFYwrioJaeUR2_Z4cLRXOSmB";
String endOfLine = "\r\n";
String titleValue = "mytitle";
String descriptionValue = "mydescription";
String postBody = createMultipartFormBody(titleValue, descriptionValue, contentEncoding, true, boundary, endOfLine);
String testPostRequest = createMultipartFormRequest(url, postBody, contentEncoding, boundary, endOfLine);
HTTPSamplerBase s = getSamplerForRequest(url, testPostRequest, contentEncoding);
assertEquals(HTTPConstants.POST, s.getMethod());
assertEquals(contentEncoding, s.getContentEncoding());
assertTrue(s.getDoMultipart());
// Check arguments
Arguments arguments = s.getArguments();
assertEquals(2, arguments.getArgumentCount());
checkArgument((HTTPArgument) arguments.getArgument(0), "title", titleValue, titleValue, contentEncoding, false);
checkArgument((HTTPArgument) arguments.getArgument(1), "description", descriptionValue, descriptionValue, contentEncoding, false);
// A HTTP POST request, multipart/form-data, simple values,
// with \r\n as end of line, which is according to spec,
// and with more headers in each multipart
endOfLine = "\r\n";
titleValue = "mytitle";
descriptionValue = "mydescription";
postBody = createMultipartFormBody(titleValue, descriptionValue, contentEncoding, true, boundary, endOfLine);
testPostRequest = createMultipartFormRequest(url, postBody, contentEncoding, boundary, endOfLine);
s = getSamplerForRequest(url, testPostRequest, contentEncoding);
assertEquals(HTTPConstants.POST, s.getMethod());
assertEquals(contentEncoding, s.getContentEncoding());
assertTrue(s.getDoMultipart());
// Check arguments
arguments = s.getArguments();
assertEquals(2, arguments.getArgumentCount());
checkArgument((HTTPArgument) arguments.getArgument(0), "title", titleValue, titleValue, contentEncoding, false);
checkArgument((HTTPArgument) arguments.getArgument(1), "description", descriptionValue, descriptionValue, contentEncoding, false);
// A HTTP POST request, multipart/form-data, simple values,
// with \n as end of line, which should also be handled,
// and with more headers in each multipart
endOfLine = "\n";
titleValue = "mytitle";
descriptionValue = "mydescription";
postBody = createMultipartFormBody(titleValue, descriptionValue, contentEncoding, true, boundary, endOfLine);
testPostRequest = createMultipartFormRequest(url, postBody, contentEncoding, boundary, endOfLine);
s = getSamplerForRequest(url, testPostRequest, contentEncoding);
assertEquals(HTTPConstants.POST, s.getMethod());
assertEquals(contentEncoding, s.getContentEncoding());
assertTrue(s.getDoMultipart());
// Check arguments
arguments = s.getArguments();
assertEquals(2, arguments.getArgumentCount());
checkArgument((HTTPArgument) arguments.getArgument(0), "title", titleValue, titleValue, contentEncoding, false);
checkArgument((HTTPArgument) arguments.getArgument(1), "description", descriptionValue, descriptionValue, contentEncoding, false);
// A HTTP POST request, multipart/form-data, with value that will change
// if they are url encoded
// Values are similar to __VIEWSTATE parameter that .net uses
endOfLine = "\r\n";
titleValue = "/wEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ/rA+8DZ2dnZ2dnZ2d/GNDar6OshPwdJc=";
descriptionValue = "mydescription";
postBody = createMultipartFormBody(titleValue, descriptionValue, contentEncoding, true, boundary, endOfLine);
testPostRequest = createMultipartFormRequest(url, postBody, contentEncoding, boundary, endOfLine);
s = getSamplerForRequest(url, testPostRequest, contentEncoding);
assertEquals(HTTPConstants.POST, s.getMethod());
assertEquals(contentEncoding, s.getContentEncoding());
assertTrue(s.getDoMultipart());
// Check arguments
arguments = s.getArguments();
assertEquals(2, arguments.getArgumentCount());
checkArgument((HTTPArgument) arguments.getArgument(0), "title", titleValue, titleValue, contentEncoding, false);
checkArgument((HTTPArgument) arguments.getArgument(1), "description", descriptionValue, descriptionValue, contentEncoding, false);
}
use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.
the class TestHttpRequestHdr method testPostRequestEncodings.
@Test
public void testPostRequestEncodings() throws Exception {
String url = "http://localhost/matrix.html";
// A HTTP POST request, with encoding not known
String contentEncoding = "";
String param1Value = "yes";
String param2Value = "0+5 -\u00c5%C3%85";
String param2ValueEncoded = URLEncoder.encode(param2Value, "UTF-8");
String postBody = "param1=" + param1Value + "¶m2=" + param2ValueEncoded + "\r\n";
String testPostRequest = "POST " + url + " HTTP/1.1\r\n" + "Content-type: " + HTTPConstants.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
HTTPSamplerBase s = getSamplerForRequest(null, testPostRequest, null);
assertEquals(HTTPConstants.POST, s.getMethod());
assertEquals(contentEncoding, s.getContentEncoding());
// Check arguments
Arguments arguments = s.getArguments();
assertEquals(2, arguments.getArgumentCount());
checkArgument((HTTPArgument) arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false);
// When the encoding is not known, the argument will get the encoded value, and the "encode?" set to false
checkArgument((HTTPArgument) arguments.getArgument(1), "param2", param2ValueEncoded, param2ValueEncoded, contentEncoding, false);
// A HTTP POST request, with UTF-8 encoding
contentEncoding = "UTF-8";
param1Value = "yes";
param2Value = "0+5 -\u007c\u2aa1\u266a\u0153\u20a1\u0115\u0364\u00c5\u2052\uc385%C3%85";
param2ValueEncoded = URLEncoder.encode(param2Value, contentEncoding);
postBody = "param1=" + param1Value + "¶m2=" + param2ValueEncoded + "\r\n";
testPostRequest = "POST " + url + " HTTP/1.1\r\n" + "Content-type: " + HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED + "\r\n" + "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n" + "\r\n" + postBody;
s = getSamplerForRequest(url, testPostRequest, contentEncoding);
assertEquals(HTTPConstants.POST, s.getMethod());
assertEquals(contentEncoding, s.getContentEncoding());
// Check arguments
arguments = s.getArguments();
assertEquals(2, arguments.getArgumentCount());
checkArgument((HTTPArgument) arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false);
checkArgument((HTTPArgument) arguments.getArgument(1), "param2", param2Value, param2ValueEncoded, contentEncoding, true);
// A HTTP POST request, with ISO-8859-1 encoding
contentEncoding = "ISO-8859-1";
param1Value = "yes";
param2Value = "0+5 -\u00c5%C3%85";
param2ValueEncoded = URLEncoder.encode(param2Value, contentEncoding);
postBody = "param1=" + param1Value + "¶m2=" + param2ValueEncoded + "\r\n";
testPostRequest = "POST " + url + " HTTP/1.1\r\n" + "Content-type: " + HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED + "\r\n" + "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n" + "\r\n" + postBody;
s = getSamplerForRequest(url, testPostRequest, contentEncoding);
assertEquals(HTTPConstants.POST, s.getMethod());
assertEquals(contentEncoding, s.getContentEncoding());
// Check arguments
arguments = s.getArguments();
assertEquals(2, arguments.getArgumentCount());
checkArgument((HTTPArgument) arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false);
checkArgument((HTTPArgument) arguments.getArgument(1), "param2", param2Value, param2ValueEncoded, contentEncoding, true);
}
use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.
the class TestAnchorModifier method testSimpleParse4.
@Test
public void testSimpleParse4() throws Exception {
HTTPSamplerBase config = makeUrlConfig("/subdir/index\\..*");
HTTPSamplerBase context = makeContext("http://www.apache.org/subdir/previous.html");
String responseText = "<html><head><title>Test page</title></head><body>" + "<A HREF=\"index.html\">Goto index page</A></body></html>";
HTTPSampleResult result = new HTTPSampleResult();
result.setResponseData(responseText, null);
result.setSampleLabel(context.toString());
result.setURL(context.getUrl());
jmctx.setCurrentSampler(context);
jmctx.setCurrentSampler(config);
jmctx.setPreviousResult(result);
parser.process();
String newUrl = config.getUrl().toString();
assertEquals("http://www.apache.org/subdir/index.html", newUrl);
}
use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.
the class TestAnchorModifier method testSimpleParse2.
@Test
public void testSimpleParse2() throws Exception {
HTTPSamplerBase config = makeUrlConfig("/index\\.html");
HTTPSamplerBase context = makeContext("http://www.apache.org/subdir/previous.html");
String responseText = "<html><head><title>Test page</title></head><body>" + "<a href=\"/index.html\">Goto index page</a>" + "hfdfjiudfjdfjkjfkdjf" + "<b>bold text</b><a href=lowerdir/index.html>lower</a>" + "</body></html>";
HTTPSampleResult result = new HTTPSampleResult();
result.setResponseData(responseText, null);
result.setSampleLabel(context.toString());
result.setURL(context.getUrl());
jmctx.setCurrentSampler(context);
jmctx.setCurrentSampler(config);
jmctx.setPreviousResult(result);
parser.process();
String newUrl = config.getUrl().toString();
assertTrue("http://www.apache.org/index.html".equals(newUrl) || "http://www.apache.org/subdir/lowerdir/index.html".equals(newUrl));
}
Aggregations