use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction in project jmeter by apache.
the class ParseCurlCommandActionTest method testReadCurlCommandsFromFile.
@Test
public void testReadCurlCommandsFromFile(@TempDir Path tempDir) throws Exception {
String cmdLine = "curl 'http://jmeter.apache.org/' --max-redirs 'b'" + System.lineSeparator() + "curl 'http://jmeter.apache.org/' --include --keepalive-time '20'";
String tempPath = writeToTempFile(tempDir, cmdLine);
ParseCurlCommandAction p = new ParseCurlCommandAction();
List<String> commands = p.readFromFile(tempPath);
assertTrue(commands.contains("curl 'http://jmeter.apache.org/' --max-redirs 'b'"), "Curl commands should be saved in list");
assertTrue(commands.contains("curl 'http://jmeter.apache.org/' --include --keepalive-time '20'"), "Curl commands should be saved in list");
assertEquals(2, commands.size());
}
use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction 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.protocol.http.gui.action.ParseCurlCommandAction in project jmeter by apache.
the class ParseCurlCommandActionTest method testConfigureTimeout.
@Test
public void testConfigureTimeout() throws Exception {
ParseCurlCommandAction p = new ParseCurlCommandAction();
BasicCurlParser basicCurlParser = new BasicCurlParser();
Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -m '20' --connect-timeout '1'");
HTTPSamplerProxy httpSampler = (HTTPSamplerProxy) HTTPSamplerFactory.newInstance(HTTPSamplerFactory.DEFAULT_CLASSNAME);
httpSampler.setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());
httpSampler.setProperty(TestElement.NAME, "HTTP Request");
Method method = getMethodFor("configureTimeout", Request.class, HTTPSamplerProxy.class);
method.invoke(p, request, httpSampler);
assertEquals(1000, httpSampler.getConnectTimeout());
assertEquals(19000, httpSampler.getResponseTimeout());
}
use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction in project jmeter by apache.
the class ParseCurlCommandActionTest method testCreateCookieManagerHeader.
@Test
public void testCreateCookieManagerHeader() throws Exception {
ParseCurlCommandAction p = new ParseCurlCommandAction();
CookieManager cookieManager = new CookieManager();
BasicCurlParser basicCurlParser = new BasicCurlParser();
Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -H 'cookie: PHPSESSID=testphpsessid;a=b' --compressed");
Field f = ParseCurlCommandAction.class.getDeclaredField("uploadCookiesCheckBox");
f.setAccessible(true);
JCheckBox uploadCookiesCheckBox = new JCheckBox(JMeterUtils.getResString("curl_add_cookie_header_to_cookiemanager"), true);
f.set(p, uploadCookiesCheckBox);
Method method = getMethodFor("createCookieManager", CookieManager.class, Request.class);
method.invoke(p, cookieManager, request);
assertEquals("jmeter.apache.org", cookieManager.get(0).getDomain(), "the domain of cookie should be set in cookieManager");
assertEquals("/", cookieManager.get(0).getPath(), "the path of cookie should be set in cookieManager");
assertEquals("a", cookieManager.get(0).getName(), "the name of cookie should be set in cookieManager");
assertEquals("b", cookieManager.get(0).getValue(), "the password of cookie should be set in cookieManager");
uploadCookiesCheckBox = new JCheckBox(JMeterUtils.getResString("curl_add_cookie_header_to_cookiemanager"), false);
f.set(p, uploadCookiesCheckBox);
cookieManager = new CookieManager();
method.invoke(p, cookieManager, request);
assertEquals(0, cookieManager.getCookies().size(), "When doesn't choose to upload cookies from header," + "the cookie shouldn't be set in cookieManager");
}
use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction in project jmeter by apache.
the class ParseCurlCommandActionTest method testCommentTextStartsWith.
private void testCommentTextStartsWith(String cmdLine, String expectedComment) {
ParseCurlCommandAction p = new ParseCurlCommandAction();
BasicCurlParser basicCurlParser = new BasicCurlParser();
Request request = basicCurlParser.parse(cmdLine);
String comment = p.createCommentText(request);
assertTrue(comment.trim().startsWith(expectedComment));
}
Aggregations