Search in sources :

Example 16 with ParseCurlCommandAction

use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction 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 17 with ParseCurlCommandAction

use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction 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 18 with ParseCurlCommandAction

use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction 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)

Example 19 with ParseCurlCommandAction

use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction in project jmeter by apache.

the class ParseCurlCommandActionTest method testCommentText.

private void testCommentText(String cmdLine, String expectedComment) {
    ParseCurlCommandAction p = new ParseCurlCommandAction();
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    Request request = basicCurlParser.parse(cmdLine);
    String comment = p.createCommentText(request);
    assertEquals(expectedComment, comment.trim());
}
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)

Example 20 with ParseCurlCommandAction

use of org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction in project jmeter by apache.

the class ParseCurlCommandActionTest method testCanUpdateAuthManagerInThreadGroupt.

@Test
public void testCanUpdateAuthManagerInThreadGroupt() throws Exception {
    ParseCurlCommandAction p = new ParseCurlCommandAction();
    AuthManager authManager = new AuthManager();
    Authorization authorization = new Authorization();
    authorization.setPass("passwd");
    authorization.setUser("user");
    authorization.setURL("http://jmeter.apache.org/");
    authorization.setMechanism(Mechanism.BASIC);
    authManager.addAuth(authorization);
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -u 'user:passwd'");
    Method method = getMethodFor("canUpdateAuthManagerInThreadGroup", Request.class, AuthManager.class);
    assertFalse((boolean) method.invoke(p, request, authManager), "When AuthManager contains this url, shouldn't add a AuthManager in ThreadGroup");
    request = basicCurlParser.parse("curl 'http://jmeter.apache.fr/' -u 'user:passwd'");
    assertTrue((boolean) method.invoke(p, request, authManager), "The AuthManager doesn't contain this url , should add a AuthManager in ThreadGroup");
}
Also used : Authorization(org.apache.jmeter.protocol.http.control.Authorization) BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) AuthManager(org.apache.jmeter.protocol.http.control.AuthManager) Request(org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request) ParseCurlCommandAction(org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Aggregations

ParseCurlCommandAction (org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction)24 Test (org.junit.jupiter.api.Test)21 BasicCurlParser (org.apache.jmeter.protocol.http.curl.BasicCurlParser)19 Request (org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request)19 Method (java.lang.reflect.Method)17 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 Field (java.lang.reflect.Field)1 URL (java.net.URL)1 JCheckBox (javax.swing.JCheckBox)1 Arguments (org.apache.jmeter.config.Arguments)1 Header (org.apache.jmeter.protocol.http.control.Header)1