use of org.apache.jmeter.protocol.http.util.HTTPFileArg in project jmeter by apache.
the class TestHTTPSamplersAgainstHttpMirrorServer method setupFileUploadData.
/**
* Setup the form data with specified values, and file to upload
*
* @param httpSampler
*/
private void setupFileUploadData(HTTPSamplerBase httpSampler, boolean isEncoded, String titleField, String titleValue, String descriptionField, String descriptionValue, String fileField, File fileValue, String fileMimeType) {
// Set the form data
setupFormData(httpSampler, isEncoded, titleField, titleValue, descriptionField, descriptionValue);
// Set the file upload data
HTTPFileArg[] hfa = { new HTTPFileArg(fileValue == null ? "" : fileValue.getAbsolutePath(), fileField, fileMimeType) };
httpSampler.setHTTPFiles(hfa);
}
use of org.apache.jmeter.protocol.http.util.HTTPFileArg 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.getDoMultipartPost());
// 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.util.HTTPFileArg in project jmeter by apache.
the class PostWriterTest method setupFilepart.
/**
* Setup the filepart with specified values
*
* @param httpSampler
*/
private void setupFilepart(HTTPSampler httpSampler, String fileField, File file, String mimeType) {
HTTPFileArg[] hfa = { new HTTPFileArg(file == null ? "" : file.getAbsolutePath(), fileField, mimeType) };
httpSampler.setHTTPFiles(hfa);
}
use of org.apache.jmeter.protocol.http.util.HTTPFileArg in project jmeter by apache.
the class PutWriterTest method testSetHeadersWithNoParams.
@Test
public void testSetHeadersWithNoParams() throws Exception {
URLConnection uc = new NullURLConnection();
HTTPSampler sampler = new HTTPSampler();
sampler.setHTTPFiles(new HTTPFileArg[] { new HTTPFileArg("file1", "", "mime1") });
PutWriter pw = new PutWriter();
pw.setHeaders(uc, sampler);
assertEquals("mime1", uc.getRequestProperty(HTTPConstants.HEADER_CONTENT_TYPE));
}
use of org.apache.jmeter.protocol.http.util.HTTPFileArg in project jmeter by apache.
the class TestHTTPSamplers method testSetAndGetFilename.
@Test
public void testSetAndGetFilename() {
HTTPSamplerBase sampler = new HTTPNullSampler();
sampler.setHTTPFiles(new HTTPFileArg[] { new HTTPFileArg("name", "", "") });
HTTPFileArg file = sampler.getHTTPFiles()[0];
assertEquals("name", file.getPath());
sampler.setHTTPFiles(new HTTPFileArg[] { new HTTPFileArg("name2", "", "") });
file = sampler.getHTTPFiles()[0];
assertEquals("name2", file.getPath());
}
Aggregations