Search in sources :

Example 16 with BasicCurlParser

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

the class BasicCurlParserTest method testBackslashAtLineEnding.

@Test
public void testBackslashAtLineEnding() {
    String cmdLine = "curl \\\n-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());
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 17 with BasicCurlParser

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

the class BasicCurlParserTest method testCapath.

@Test
public void testCapath() {
    String cmdLine = "curl 'http://jmeter.apache.org/' --capath 'test.pem' ";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    assertEquals("capath", request.getCaCert(), "With method 'parser',the cacert need to show a warning'");
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 18 with BasicCurlParser

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

the class BasicCurlParserTest method testCookie.

@Test
public void testCookie() {
    String cmdLine = "curl -X POST  \"https://api.imgur.com/3/upload\" -b 'name=Tom;password=123456'";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    Cookie c1 = new Cookie();
    c1.setDomain("api.imgur.com");
    c1.setName("name");
    c1.setValue("Tom");
    c1.setPath("/3/upload");
    Cookie c2 = new Cookie();
    c2.setDomain("api.imgur.com");
    c2.setName("password");
    c2.setValue("123456");
    c2.setPath("/3/upload");
    assertTrue(request.getCookies("https://api.imgur.com/3/upload").contains(c1), "With method 'parser', the cookie should be set in CookieManager");
    assertTrue(request.getCookies("https://api.imgur.com/3/upload").contains(c2), "With method 'parser', the cookie should be set in CookieManager");
    assertEquals(2, request.getCookies("https://api.imgur.com/3/upload").size(), "With method 'parser', the cookie should be set in CookieManager");
}
Also used : Cookie(org.apache.jmeter.protocol.http.control.Cookie) BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 19 with BasicCurlParser

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

the class BasicCurlParserTest method testProxyDefaultPort.

@Test
public void testProxyDefaultPort() {
    String cmdLine = "curl 'http://jmeter.apache.org/' -x 'https://example.com'";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    assertEquals("1080", request.getProxyServer().get("port"), "With method 'parser',the default port of proxy should be 1080");
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 20 with BasicCurlParser

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

the class ParseCurlCommandActionTest method testCreateProxyServer.

@Test
public void testCreateProxyServer() 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/' -x 'https://aa:bb@example.com:8042'");
    Method method = getMethodFor("createProxyServer", Request.class, HTTPSamplerProxy.class);
    method.invoke(p, request, httpSampler);
    assertEquals("example.com", httpSampler.getProxyHost(), "proxy host should be set in httpsampler");
    assertEquals("aa", httpSampler.getProxyUser(), "proxy user should be set in httpsampler");
    assertEquals("bb", httpSampler.getProxyPass(), "proxy pass should be set in httpsampler");
    assertEquals("https", httpSampler.getProxyScheme(), "proxy scheme should be set in httpsampler");
    assertEquals("example.com", httpSampler.getProxyHost(), "proxy host should be set in httpsampler");
    assertEquals(8042, httpSampler.getProxyPortInt(), "The command line should be parsed in turn");
}
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) 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