Search in sources :

Example 11 with BasicCurlParser

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

the class BasicCurlParserTest method testFFParsing.

@Test
public void testFFParsing() {
    String cmdLine = "curl 'http://jmeter.apache.org/' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:63.0) Gecko/20100101 Firefox/63.0' " + "-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' " + "-H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'DNT: 1' " + "-H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1'";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    assertEquals("http://jmeter.apache.org/", request.getUrl());
    assertEquals(5, request.getHeaders().size());
    assertTrue(request.isCompressed());
    assertEquals("GET", request.getMethod());
    String resParser = "Request [compressed=true, url=http://jmeter.apache.org/, method=GET, headers=[(User-Agent,Mozilla/5.0 " + "(Macintosh; Intel Mac OS X 10.11; rv:63.0) Gecko/20100101 Firefox/63.0), (Accept,text/html,application/xhtml+xml," + "application/xml;q=0.9,*/*;q=0.8), (Accept-Language,en-US,en;q=0.5), (DNT,1), " + "(Upgrade-Insecure-Requests,1)]]";
    assertEquals(resParser, request.toString(), "The method 'toString' should get all parameters correctly");
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 12 with BasicCurlParser

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

the class BasicCurlParserTest method testFormWithEmptyValue.

@Test
public void testFormWithEmptyValue() {
    String cmdLine = "curl 'https://example.invalid' -F 'test=\"\"' ";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    List<Pair<String, ArgumentHolder>> res = request.getFormData();
    assertTrue(res.contains(Pair.of("test", StringArgumentHolder.of(""))), "With method 'parser', we should post form data: " + request.getFormData());
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test)

Example 13 with BasicCurlParser

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

the class BasicCurlParserTest method testDuplicatedKeyInData.

@Test
public void testDuplicatedKeyInData() {
    String cmdLine = "curl 'https://example.invalid' " + "-H 'cache-control: no-cache' --data 'name=one' --data 'name=two' ";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    assertEquals("name=one&name=two", request.getPostData());
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 14 with BasicCurlParser

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

the class BasicCurlParserTest method testNullCommand.

@Test
public void testNullCommand() {
    String cmdLine = "";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    assertEquals("Request [compressed=false, url=null, method=GET, headers=[]]", request.toString(), "The method 'translateCommandline' should return 'null' when command is empty, ");
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 15 with BasicCurlParser

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

the class BasicCurlParserTest method testProxyUser.

@Test
public void testProxyUser() {
    String cmdLine = "curl 'http://jmeter.apache.org/' --proxy '201.36.208.19:3128' -U 'aa:bb'";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    assertEquals("aa", request.getProxyServer().get("username"));
    assertEquals("bb", request.getProxyServer().get("password"));
}
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