Search in sources :

Example 11 with HTTPFileArg

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);
}
Also used : HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg)

Example 12 with HTTPFileArg

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());
}
Also used : Arguments(org.apache.jmeter.config.Arguments) HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) Test(org.junit.Test)

Example 13 with HTTPFileArg

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);
}
Also used : HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg)

Example 14 with HTTPFileArg

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));
}
Also used : HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg) URLConnection(java.net.URLConnection) Test(org.junit.Test)

Example 15 with HTTPFileArg

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());
}
Also used : HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg) Test(org.junit.Test)

Aggregations

HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)24 Test (org.junit.Test)9 File (java.io.File)6 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)6 Arguments (org.apache.jmeter.config.Arguments)5 HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 HTTPFileArgs (org.apache.jmeter.protocol.http.util.HTTPFileArgs)4 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)3 URLConnection (java.net.URLConnection)2 HttpEntity (org.apache.http.HttpEntity)2 FileEntity (org.apache.http.entity.FileEntity)2 StringEntity (org.apache.http.entity.StringEntity)2 Argument (org.apache.jmeter.config.Argument)2 AuthManager (org.apache.jmeter.protocol.http.control.AuthManager)2 HeaderManager (org.apache.jmeter.protocol.http.control.HeaderManager)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1