Search in sources :

Example 21 with BasicCurlParser

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser 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"));
        }
    }
}
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) CookieManager(org.apache.jmeter.protocol.http.control.CookieManager) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.jupiter.api.Test)

Example 22 with BasicCurlParser

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser 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");
}
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 23 with BasicCurlParser

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

the class BasicCurlParserTest method testSetRequestMethodOnData.

@Test
public void testSetRequestMethodOnData() {
    String cmdLine = "curl -X PUT -d 'hey' http://jmeter.apache.org/";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    assertEquals("http://jmeter.apache.org/", request.getUrl());
    assertEquals("hey", request.getPostData());
    assertEquals("PUT", request.getMethod());
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 24 with BasicCurlParser

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

the class BasicCurlParserTest method testNoproxy.

@Test
public void testNoproxy() {
    String cmdLine = "curl 'http://jmeter.apache.org/' --noproxy 'localhost'";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    assertEquals("localhost", request.getNoproxy());
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 25 with BasicCurlParser

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

the class BasicCurlParserTest method testDoubleQuote.

@Test
public void testDoubleQuote() {
    String cmdLine = "curl \"http://jmeter.apache.org/\"";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    assertEquals("http://jmeter.apache.org/", request.getUrl());
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Aggregations

BasicCurlParser (org.apache.jmeter.protocol.http.curl.BasicCurlParser)84 Test (org.junit.jupiter.api.Test)81 Request (org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request)20 ParseCurlCommandAction (org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction)19 Method (java.lang.reflect.Method)16 Pair (org.apache.commons.lang3.tuple.Pair)8 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 Cookie (org.apache.jmeter.protocol.http.control.Cookie)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 ArrayList (java.util.ArrayList)1