use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction in project jmeter by apache.
the class ParseCurlCommandActionTest method testReadCurlCommandsFromTextPanel.
@Test
public void testReadCurlCommandsFromTextPanel() {
ParseCurlCommandAction p = new ParseCurlCommandAction();
String cmdLine = "curl 'http://jmeter.apache.org/' --max-redirs 'b' " + "curl 'http://jmeter.apache.org/' --include --keepalive-time '20'";
List<String> commands = p.readFromTextPanel(cmdLine);
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 testCreateProxyServer.
@Test
public void testCreateProxyServer() throws Exception {
ParseCurlCommandAction p = new ParseCurlCommandAction();
HTTPSamplerProxy httpSampler = (HTTPSamplerProxy) HTTPSamplerFactory.newInstance(HTTPSamplerFactory.DEFAULT_CLASSNAME);
httpSampler.setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());
httpSampler.setProperty(TestElement.NAME, "HTTP Request");
BasicCurlParser basicCurlParser = new BasicCurlParser();
Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -x 'https://aa:bb@example.com:8042'");
Method method = getMethodFor("createProxyServer", Request.class, HTTPSamplerProxy.class);
method.invoke(p, request, httpSampler);
assertEquals("example.com", httpSampler.getProxyHost(), "proxy host should be set in httpsampler");
assertEquals("aa", httpSampler.getProxyUser(), "proxy user should be set in httpsampler");
assertEquals("bb", httpSampler.getProxyPass(), "proxy pass should be set in httpsampler");
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");
}
use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction in project jmeter by apache.
the class ParseCurlCommandActionTest method testParseCommandsException2.
@Test
public void testParseCommandsException2() {
ParseCurlCommandAction p = new ParseCurlCommandAction();
String cmdLine = "curl 'http://jmeter.apache.org/' --max-redir 'b'" + System.lineSeparator() + "curl 'http://jmeter.apache.org/' --include --keepalive-time '20'";
List<String> commands = p.readFromTextPanel(cmdLine);
assertThrowsIllegalArgument(() -> p.parseCommands(true, commands));
}
use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction in project jmeter by apache.
the class ParseCurlCommandActionTest method testCreateCookieManager.
@Test
public void testCreateCookieManager(@TempDir Path tempDir) throws Exception {
ParseCurlCommandAction p = new ParseCurlCommandAction();
CookieManager cookieManager = new CookieManager();
BasicCurlParser basicCurlParser = new BasicCurlParser();
Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -b 'name=Tom'");
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("name", cookieManager.get(0).getName(), "the name of cookie should be set in cookieManager");
assertEquals("Tom", cookieManager.get(0).getValue(), "the password of cookie should be set in cookieManager");
cookieManager = new CookieManager();
String filepath = tempDir.resolve("test.txt").toAbsolutePath().toString();
assertTrue(tempDir.resolve("test.txt").toFile().createNewFile());
request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -b '" + filepath + "'");
method.invoke(p, cookieManager, request);
request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -b 'test1.txt'");
try {
method.invoke(p, cookieManager, request);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof IllegalArgumentException) {
assertTrue(cause.getMessage().contains("File test1.txt doesn't exist"));
}
}
}
use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction in project jmeter by apache.
the class ParseCurlCommandActionTest method testParseCommandsException.
@Test
public void testParseCommandsException() {
ParseCurlCommandAction p = new ParseCurlCommandAction();
String cmdLine = "curl 'http://jmeter.apache.org/' --max-redir 'b' " + "curl 'http://jmeter.apache.org/' --include --keepalive-time '20'";
List<String> commands = p.readFromTextPanel(cmdLine);
assertThrowsIllegalArgument(() -> p.parseCommands(false, commands));
}
Aggregations