Search in sources :

Example 26 with Arguments

use of org.apache.jmeter.config.Arguments in project jmeter by apache.

the class ParseCurlCommandActionTest method testCreateSampler.

@Test
public void testCreateSampler(@TempDir Path tempDir) throws Exception {
    // test proxy in httpsampler
    ParseCurlCommandAction p = new ParseCurlCommandAction();
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org:8443/' -x 'https://aa:bb@example.com:8042'");
    Method method = getMethodFor("createSampler", Request.class, String.class);
    HTTPSamplerProxy httpSampler = (HTTPSamplerProxy) method.invoke(p, request, "");
    assertEquals("https", httpSampler.getProxyScheme(), "proxy scheme should be set in httpsampler");
    assertEquals("example.com", httpSampler.getProxyHost(), "proxy host should be set in httpsampler");
    assertEquals(8042, httpSampler.getProxyPortInt(), "The command line should be parsed in turn");
    assertEquals("/", httpSampler.getPath(), "path should be set in httpsampler");
    assertEquals("jmeter.apache.org", httpSampler.getDomain(), "domain should be set in httpsampler");
    assertEquals(8443, httpSampler.getPort(), "port should be set in httpsampler");
    assertEquals("GET", httpSampler.getMethod(), "method should be set in httpsampler");
    // test post data in httpsampler
    request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' --data 'name=test'");
    request.setInterfaceName("interface_name");
    httpSampler = (HTTPSamplerProxy) method.invoke(p, request, "");
    assertEquals("POST", httpSampler.getMethod());
    assertEquals("name=test", httpSampler.getArguments().getArgument(0).toString());
    // test form data in httpsampler(upload data)
    request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -F 'test=name;type=text/foo' -F 'test1=name1'");
    httpSampler = (HTTPSamplerProxy) method.invoke(p, request, "");
    Arguments samplerArguments = httpSampler.getArguments();
    assertEquals("POST", httpSampler.getMethod(), "method should be set in httpsampler");
    assertEquals("test", samplerArguments.getArgument(0).getName(), "form name should be set in httpsampler");
    assertEquals("name", samplerArguments.getArgument(0).getValue(), "form value should be set in httpsampler");
    assertEquals("test1", samplerArguments.getArgument(1).getName(), "form name should be set in httpsampler");
    assertEquals("name1", samplerArguments.getArgument(1).getValue(), "form value should be set in httpsampler");
    // test form data in httpsampler(upload file)
    String filePath = tempDir.resolve("test.txt").toAbsolutePath().toString();
    request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -F 'c=@" + filePath + ";type=text/foo' -F 'c1=@" + filePath + "'");
    httpSampler = (HTTPSamplerProxy) method.invoke(p, request, "");
    assertEquals("c", httpSampler.getHTTPFiles()[0].getParamName(), "form name should be set in httpsampler");
    assertEquals(filePath, httpSampler.getHTTPFiles()[0].getPath(), "form name should be set in httpsampler");
    assertEquals("c1", httpSampler.getHTTPFiles()[1].getParamName(), "form name should be set in httpsampler");
    // test form data in httpsampler
    request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' --form-string 'c=@test.txt;type=text/foo'");
    httpSampler = (HTTPSamplerProxy) method.invoke(p, request, "");
    assertEquals("c", httpSampler.getArguments().getArgument(0).getName());
    assertEquals("@test.txt;type=text/foo", httpSampler.getArguments().getArgument(0).getValue());
    // test form data in httpsampler
    request = basicCurlParser.parse("curl -X PUT \"https://www.example.com:123/12345?param1=value1&param2=value2\" -H  \"accept: */*\" -H  \"X-XSRF-TOKEN: 1234\"");
    httpSampler = (HTTPSamplerProxy) method.invoke(p, request, "");
    assertEquals(new URL("https://www.example.com:123/12345?param1=value1&param2=value2"), httpSampler.getUrl());
    assertEquals(123, httpSampler.getPort());
    assertEquals("www.example.com", httpSampler.getDomain());
    assertEquals("/12345?param1=value1&param2=value2", httpSampler.getPath());
    assertEquals("PUT", httpSampler.getMethod());
    assertEquals(new Header("accept", "*/*"), httpSampler.getHeaderManager().getHeader(0));
    assertEquals(new Header("X-XSRF-TOKEN", "1234"), httpSampler.getHeaderManager().getHeader(1));
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) HTTPSamplerProxy(org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy) Header(org.apache.jmeter.protocol.http.control.Header) Request(org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request) Arguments(org.apache.jmeter.config.Arguments) ParseCurlCommandAction(org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction) Method(java.lang.reflect.Method) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 27 with Arguments

use of org.apache.jmeter.config.Arguments in project jmeter by apache.

the class MultipartUrlConfigTest method testParseArgumentsLF.

// TODO - should LF-only EOL be allowed?
@Test
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.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with Arguments

use of org.apache.jmeter.config.Arguments in project jmeter by apache.

the class MultipartUrlConfigTest method testParseArgumentsQuotingStyle.

@ParameterizedTest()
@MethodSource("quotedMultiPartArgs")
void testParseArgumentsQuotingStyle(String boundary, String queryString, HTTPFileArgs expectedFiles, List<Argument> expectedArgs) {
    MultipartUrlConfig muc = new MultipartUrlConfig(boundary);
    muc.parseArguments(queryString);
    HTTPFileArgs files = muc.getHTTPFileArgs();
    assertEquals(expectedFiles.getHTTPFileArgCount(), files.getHTTPFileArgCount());
    for (int i = 0; i < files.getHTTPFileArgCount(); i++) {
        HTTPFileArg got = files.getHTTPFileArg(i);
        HTTPFileArg expected = expectedFiles.getHTTPFileArg(i);
        assertEquals(expected.getParamName(), got.getParamName());
        assertEquals(expected.getPath(), got.getPath());
        assertEquals(expected.getMimeType(), got.getMimeType());
    }
    Arguments args = muc.getArguments();
    assertEquals(expectedArgs.size(), args.getArgumentCount());
    for (int i = 0; i < args.getArgumentCount(); i++) {
        Argument got = args.getArgument(i);
        Argument expected = expectedArgs.get(i);
        assertEquals(expected.getName(), got.getName());
        assertEquals(expected.getValue(), got.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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 29 with Arguments

use of org.apache.jmeter.config.Arguments in project jmeter by apache.

the class MultipartUrlConfigTest method testParseArgumentsCRLF.

@Test
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.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with Arguments

use of org.apache.jmeter.config.Arguments in project jmeter by apache.

the class UrlConfigTest method setUp.

@BeforeEach
public void setUp() {
    Arguments args = new Arguments();
    args.addArgument("username", "mstover");
    args.addArgument("password", "pass");
    args.addArgument("action", "login");
    config = new HTTPNullSampler();
    config.setName("Full Config");
    config.setProperty(HTTPSamplerBase.DOMAIN, "www.lazer.com");
    config.setProperty(HTTPSamplerBase.PATH, "login.jsp");
    config.setProperty(HTTPSamplerBase.METHOD, HTTPConstants.POST);
    config.setProperty(new TestElementProperty(HTTPSamplerBase.ARGUMENTS, args));
    defaultConfig = new HTTPNullSampler();
    defaultConfig.setName("default");
    defaultConfig.setProperty(HTTPSamplerBase.DOMAIN, "www.xerox.com");
    defaultConfig.setProperty(HTTPSamplerBase.PATH, "default.html");
    partialConfig = new HTTPNullSampler();
    partialConfig.setProperty(HTTPSamplerBase.PATH, "main.jsp");
    partialConfig.setProperty(HTTPSamplerBase.METHOD, HTTPConstants.GET);
}
Also used : HTTPNullSampler(org.apache.jmeter.protocol.http.sampler.HTTPNullSampler) TestElementProperty(org.apache.jmeter.testelement.property.TestElementProperty) Arguments(org.apache.jmeter.config.Arguments) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Arguments (org.apache.jmeter.config.Arguments)96 Test (org.junit.jupiter.api.Test)32 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)18 SampleResult (org.apache.jmeter.samplers.SampleResult)17 Argument (org.apache.jmeter.config.Argument)15 HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)10 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)8 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)6 TestElement (org.apache.jmeter.testelement.TestElement)6 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)5 Test (org.junit.Test)5 HTTPFileArgs (org.apache.jmeter.protocol.http.util.HTTPFileArgs)4 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)4 IOException (java.io.IOException)3 URL (java.net.URL)3 Iterator (java.util.Iterator)3 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)3 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)3