Search in sources :

Example 1 with HTTPFileArgs

use of org.apache.jmeter.protocol.http.util.HTTPFileArgs in project jmeter by apache.

the class MultipartUrlConfigTest method testParseArgumentsCRLF.

@Test
public void testParseArgumentsCRLF() {
    String queryString = "Content-Disposition: form-data; name=\"aa\"\r\n" + "Content-Type: text/plain; charset=ISO-8859-1\r\n" + "Content-Transfer-Encoding: 8bit\r\n" + "\r\n" + "bb\r\n" + "--7d159c1302d0y0\r\n" + "Content-Disposition: form-data; name=\"xx\"\r\n" + "Content-Type: text/plain; charset=ISO-8859-1\r\n" + "Content-Transfer-Encoding: 8bit\r\n" + "\r\n" + "yy\r\n" + "--7d159c1302d0y0\r\n" + "Content-Disposition: form-data; name=\"abc\"\r\n" + "Content-Type: text/plain; charset=ISO-8859-1\r\n" + "Content-Transfer-Encoding: 8bit\r\n" + "\r\n" + "xyz  \r\n" + "xyz  \r\n" + "--7d159c1302d0y0\r\n" + "Content-Disposition: form-data; name=\"param1\"; filename=\"file1\"\r\n" + "Content-Type: text/plain\r\n" + "Content-Transfer-Encoding: binary\r\n" + "\r\n" + "file content\r\n" + "\r\n";
    MultipartUrlConfig muc = new MultipartUrlConfig("7d159c1302d0y0");
    muc.parseArguments(queryString);
    HTTPFileArgs files = muc.getHTTPFileArgs();
    assertEquals(1, files.getHTTPFileArgCount());
    HTTPFileArg file = (HTTPFileArg) files.iterator().next().getObjectValue();
    assertEquals("file1", file.getPath());
    assertEquals("param1", file.getParamName());
    assertEquals("text/plain", file.getMimeType());
    Arguments args = muc.getArguments();
    assertEquals(3, args.getArgumentCount());
    Argument arg = args.getArgument(0);
    assertEquals("aa", arg.getName());
    assertEquals("bb", arg.getValue());
    arg = args.getArgument(1);
    assertEquals("xx", arg.getName());
    assertEquals("yy", arg.getValue());
    arg = args.getArgument(2);
    assertEquals("abc", arg.getName());
    assertEquals("xyz  \r\nxyz  ", arg.getValue());
}
Also used : Argument(org.apache.jmeter.config.Argument) HTTPFileArgs(org.apache.jmeter.protocol.http.util.HTTPFileArgs) Arguments(org.apache.jmeter.config.Arguments) HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg) Test(org.junit.Test)

Example 2 with HTTPFileArgs

use of org.apache.jmeter.protocol.http.util.HTTPFileArgs in project jmeter by apache.

the class MultipartUrlConfigTest method testParseArgumentsLF.

// TODO - should LF-only EOL be allowed? 
@Test
public void testParseArgumentsLF() {
    String queryString = "Content-Disposition: form-data; name=\"aa\"\n" + "Content-Type: text/plain; charset=ISO-8859-1\n" + "Content-Transfer-Encoding: 8bit\n" + "\n" + "bb\n" + "--7d159c1302d0y0\n" + "Content-Disposition: form-data; name=\"xx\"\n" + "Content-Type: text/plain; charset=ISO-8859-1\n" + "Content-Transfer-Encoding: 8bit\n" + "\n" + "yy\n" + "--7d159c1302d0y0\n" + "Content-Disposition: form-data; name=\"abc\"\n" + "Content-Type: text/plain; charset=ISO-8859-1\n" + "Content-Transfer-Encoding: 8bit\n" + "\n" + "xyz  \n" + "xyz  \n" + "--7d159c1302d0y0\n" + "Content-Disposition: form-data; name=\"param1\"; filename=\"file1\"\n" + "Content-Type: text/plain\n" + "Content-Transfer-Encoding: binary\n" + "\n" + "file content\n" + "\n";
    MultipartUrlConfig muc = new MultipartUrlConfig("7d159c1302d0y0");
    muc.parseArguments(queryString);
    HTTPFileArgs files = muc.getHTTPFileArgs();
    assertEquals(1, files.getHTTPFileArgCount());
    HTTPFileArg file = (HTTPFileArg) files.iterator().next().getObjectValue();
    assertEquals("file1", file.getPath());
    assertEquals("param1", file.getParamName());
    assertEquals("text/plain", file.getMimeType());
    Arguments args = muc.getArguments();
    assertEquals(3, args.getArgumentCount());
    Argument arg = args.getArgument(0);
    assertEquals("aa", arg.getName());
    assertEquals("bb", arg.getValue());
    arg = args.getArgument(1);
    assertEquals("xx", arg.getName());
    assertEquals("yy", arg.getValue());
    arg = args.getArgument(2);
    assertEquals("abc", arg.getName());
    assertEquals("xyz  \nxyz  ", arg.getValue());
}
Also used : Argument(org.apache.jmeter.config.Argument) HTTPFileArgs(org.apache.jmeter.protocol.http.util.HTTPFileArgs) Arguments(org.apache.jmeter.config.Arguments) HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg) Test(org.junit.Test)

Example 3 with HTTPFileArgs

use of org.apache.jmeter.protocol.http.util.HTTPFileArgs in project jmeter by apache.

the class HTTPSamplerBase method mergeFileProperties.

/**
     * JMeter 2.3.1 and earlier only had fields for one file on the GUI:
     * <ul>
     *   <li>FILE_NAME</li>
     *   <li>FILE_FIELD</li>
     *   <li>MIMETYPE</li>
     * </ul>
     * These were stored in their own individual properties.
     * <p>
     * Version 2.3.3 introduced a list of files, each with their own path, name and mimetype.
     * <p>
     * In order to maintain backwards compatibility of test plans, the 3 original properties
     * were retained; additional file entries are stored in an HTTPFileArgs class.
     * The HTTPFileArgs class was only present if there is more than 1 file; this means that
     * such test plans are backward compatible.
     * <p>
     * Versions after 2.3.4 dispense with the original set of 3 properties.
     * Test plans that use them are converted to use a single HTTPFileArgs list.
     *
     * @see HTTPSamplerBaseConverter
     */
void mergeFileProperties() {
    JMeterProperty fileName = getProperty(FILE_NAME);
    JMeterProperty paramName = getProperty(FILE_FIELD);
    JMeterProperty mimeType = getProperty(MIMETYPE);
    HTTPFileArg oldStyleFile = new HTTPFileArg(fileName, paramName, mimeType);
    HTTPFileArgs fileArgs = getHTTPFileArgs();
    HTTPFileArgs allFileArgs = new HTTPFileArgs();
    if (oldStyleFile.isNotEmpty()) {
        // OK, we have an old-style file definition
        // save it
        allFileArgs.addHTTPFileArg(oldStyleFile);
        // Now deal with any additional file arguments
        if (fileArgs != null) {
            HTTPFileArg[] infiles = fileArgs.asArray();
            for (HTTPFileArg infile : infiles) {
                allFileArgs.addHTTPFileArg(infile);
            }
        }
    } else {
        if (fileArgs != null) {
            // for new test plans that don't have FILE/PARAM/MIME properties
            allFileArgs = fileArgs;
        }
    }
    // Updated the property lists
    setHTTPFileArgs(allFileArgs);
    removeProperty(FILE_FIELD);
    removeProperty(FILE_NAME);
    removeProperty(MIMETYPE);
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) HTTPFileArgs(org.apache.jmeter.protocol.http.util.HTTPFileArgs) HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg)

Example 4 with HTTPFileArgs

use of org.apache.jmeter.protocol.http.util.HTTPFileArgs in project jmeter by apache.

the class HTTPSamplerBase method setHTTPFiles.

/**
     * Saves the list of files.
     * The first file is saved in the Filename/field/mimetype properties.
     * Any additional files are saved in the FILE_ARGS array.
     *
     * @param files list of files to save
     */
public void setHTTPFiles(HTTPFileArg[] files) {
    HTTPFileArgs fileArgs = new HTTPFileArgs();
    // Weed out the empty files
    if (files.length > 0) {
        for (HTTPFileArg file : files) {
            if (file.isNotEmpty()) {
                fileArgs.addHTTPFileArg(file);
            }
        }
    }
    setHTTPFileArgs(fileArgs);
}
Also used : HTTPFileArgs(org.apache.jmeter.protocol.http.util.HTTPFileArgs) HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg)

Aggregations

HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)4 HTTPFileArgs (org.apache.jmeter.protocol.http.util.HTTPFileArgs)4 Argument (org.apache.jmeter.config.Argument)2 Arguments (org.apache.jmeter.config.Arguments)2 Test (org.junit.Test)2 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)1