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¶m2=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¶m2=value2"), httpSampler.getUrl());
assertEquals(123, httpSampler.getPort());
assertEquals("www.example.com", httpSampler.getDomain());
assertEquals("/12345?param1=value1¶m2=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));
}
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());
}
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());
}
}
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());
}
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);
}
Aggregations