use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction in project jmeter by apache.
the class ParseCurlCommandActionTest method testDnsServer.
@Test
public void testDnsServer() throws Exception {
ParseCurlCommandAction p = new ParseCurlCommandAction();
DNSCacheManager dnsCacheManager = new DNSCacheManager();
BasicCurlParser basicCurlParser = new BasicCurlParser();
Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' --dns-servers '0.0.0.0'");
Method method = getMethodFor("createDnsServer", Request.class, DNSCacheManager.class);
method.invoke(p, request, dnsCacheManager);
assertEquals("0.0.0.0", dnsCacheManager.getServers().get(0).getStringValue(), "the dns server should be set in DNSCacheManager");
}
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 testDataFormException.
@Test
public void testDataFormException() 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/' -F 'test=name' --data 'fname=a&lname=b'");
Method method = getMethodFor("setFormData", Request.class, HTTPSamplerProxy.class);
try {
method.invoke(p, request, httpSampler);
throw new IllegalStateException("Should have thrown InvocationTargetException");
} catch (InvocationTargetException | IllegalAccessException e) {
assertEquals("--form and --data can't appear in the same command", e.getCause().getMessage());
}
}
use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction in project jmeter by apache.
the class ParseCurlCommandActionTest method getMethodFor.
private Method getMethodFor(String name, Class<?>... paramsClasses) throws NoSuchMethodException, SecurityException {
Class<ParseCurlCommandAction> parseCurlCommandAction = ParseCurlCommandAction.class;
Method method = parseCurlCommandAction.getDeclaredMethod(name, paramsClasses);
method.setAccessible(true);
return method;
}
use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction in project jmeter by apache.
the class ParseCurlCommandActionTest method testCreateHttpRequest.
@Test
public void testCreateHttpRequest() throws Exception {
ParseCurlCommandAction p = new ParseCurlCommandAction();
BasicCurlParser basicCurlParser = new BasicCurlParser();
ThreadGroup threadGroup = new ThreadGroup();
TestPlan testPlan = new TestPlan();
HashTree tree = new HashTree();
HashTree testPlanHT = tree.add(testPlan);
HashTree threadGroupHT = testPlanHT.add(threadGroup);
Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -E '<CA certificate>'");
Method method = getMethodFor("createHttpRequest", Request.class, HashTree.class, String.class);
HTTPSamplerProxy httpSampler = (HTTPSamplerProxy) method.invoke(p, request, threadGroupHT, "comment");
assertEquals("/", httpSampler.getPath(), "path should be set in httpsampler");
assertEquals("jmeter.apache.org", httpSampler.getDomain(), "domain should be set in httpsampler");
assertEquals(80, httpSampler.getPort(), "port should be 80 in httpsampler");
assertEquals("GET", httpSampler.getMethod(), "method should be set in httpsampler");
}
Aggregations