Search in sources :

Example 11 with Request

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request 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());
    }
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) HTTPSamplerProxy(org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy) HttpTestSampleGui(org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui) Request(org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request) ParseCurlCommandAction(org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.jupiter.api.Test)

Example 12 with Request

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request 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");
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) HashTree(org.apache.jorphan.collections.HashTree) HTTPSamplerProxy(org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy) TestPlan(org.apache.jmeter.testelement.TestPlan) Request(org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request) ParseCurlCommandAction(org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction) ThreadGroup(org.apache.jmeter.threads.ThreadGroup) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 13 with Request

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request in project jmeter by apache.

the class ParseCurlCommandActionTest method testParseCommands.

@Test
public void testParseCommands() {
    // commands from textpanel
    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);
    List<Request> requests = p.parseCommands(false, commands);
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    Request request1 = basicCurlParser.parse("curl 'http://jmeter.apache.org/' --max-redirs 'b'");
    assertEquals(request1.toString(), requests.get(0).toString());
    assertEquals(2, requests.size());
    // commands from file
    cmdLine = "curl 'http://jmeter.apache.org/' --max-redirs 'b'" + System.lineSeparator() + "curl 'http://jmeter.apache.org/' --include --keepalive-time '20'";
    commands = p.readFromTextPanel(cmdLine);
    requests = p.parseCommands(true, commands);
    request1 = basicCurlParser.parse("curl 'http://jmeter.apache.org/' --max-redirs 'b'");
    assertEquals(request1.toString(), requests.get(0).toString(), "The command line should be parsed in turn");
    assertEquals(2, requests.size());
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Request(org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request) ParseCurlCommandAction(org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction) Test(org.junit.jupiter.api.Test)

Example 14 with Request

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request in project jmeter by apache.

the class ParseCurlCommandActionTest method testCreateHeaderManager.

@Test
public void testCreateHeaderManager() throws Exception {
    ParseCurlCommandAction p = new ParseCurlCommandAction();
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -H 'Content-Type: application/x-www-form-urlencoded' --compressed");
    Method method = getMethodFor("createHeaderManager", Request.class);
    HeaderManager headerManager = (HeaderManager) method.invoke(p, request);
    // The following headers should be set in the HeaderManager
    assertEquals("Content-Type", headerManager.get(0).getName());
    assertEquals("application/x-www-form-urlencoded", headerManager.get(0).getValue());
    assertEquals("Accept-Encoding", headerManager.get(1).getName());
    assertEquals("gzip, deflate", headerManager.get(1).getValue());
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Request(org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request) ParseCurlCommandAction(org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction) Method(java.lang.reflect.Method) HeaderManager(org.apache.jmeter.protocol.http.control.HeaderManager) Test(org.junit.jupiter.api.Test)

Example 15 with Request

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request in project jmeter by apache.

the class ParseCurlCommandActionTest method testCreateDnsResolver.

@Test
public void testCreateDnsResolver() throws Exception {
    ParseCurlCommandAction p = new ParseCurlCommandAction();
    DNSCacheManager dnsCacheManager = new DNSCacheManager();
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/'  --resolve 'moonagic.com:443:127.0.0.2'");
    Method method = getMethodFor("createDnsResolver", Request.class, DNSCacheManager.class);
    method.invoke(p, request, dnsCacheManager);
    assertEquals("StaticHost(moonagic.com, 127.0.0.2)", dnsCacheManager.getHosts().get(0).getStringValue());
    request = basicCurlParser.parse("curl 'http://jmeter.apache.org/'  --resolve 'moonagic.com:9090:127.0.0.2'");
    method.invoke(p, request, dnsCacheManager);
    assertEquals("StaticHost(moonagic.com, 127.0.0.2)", dnsCacheManager.getHosts().get(0).getStringValue(), "the dns resolver should be set in DNSCacheManager");
    assertTrue(dnsCacheManager.getComment().contains("Custom DNS resolver doesn't support port"), "the dns resolver should be set in DNSCacheManager");
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Request(org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request) ParseCurlCommandAction(org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction) Method(java.lang.reflect.Method) DNSCacheManager(org.apache.jmeter.protocol.http.control.DNSCacheManager) Test(org.junit.jupiter.api.Test)

Aggregations

BasicCurlParser (org.apache.jmeter.protocol.http.curl.BasicCurlParser)21 Request (org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request)21 ParseCurlCommandAction (org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction)19 Test (org.junit.jupiter.api.Test)17 Method (java.lang.reflect.Method)16 HTTPSamplerProxy (org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy)6 DNSCacheManager (org.apache.jmeter.protocol.http.control.DNSCacheManager)4 AuthManager (org.apache.jmeter.protocol.http.control.AuthManager)3 HttpTestSampleGui (org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Authorization (org.apache.jmeter.protocol.http.control.Authorization)2 CookieManager (org.apache.jmeter.protocol.http.control.CookieManager)2 TestPlan (org.apache.jmeter.testelement.TestPlan)2 ThreadGroup (org.apache.jmeter.threads.ThreadGroup)2 HashTree (org.apache.jorphan.collections.HashTree)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1