Search in sources :

Example 6 with Request

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

the class ParseCurlCommandActionTest method testCommentTextStartsWith.

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

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

the class ParseCurlCommandActionTest method testCanAddAuthManagerInHttpRequest.

@Test
public void testCanAddAuthManagerInHttpRequest() 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("canAddAuthManagerInHttpRequest", Request.class, AuthManager.class);
    assertFalse((boolean) method.invoke(p, request, authManager), "When AuthManager contains this authorization, shouldn't add a AuthManager in Http Request");
    request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -u 'user1:passwd1'");
    assertTrue((boolean) method.invoke(p, request, authManager), "When AuthManager contains this url, but the username or password isn't the same," + "should add a AuthManager in Http Request");
}
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)

Example 8 with Request

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request 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)

Example 9 with Request

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request 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 10 with Request

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request 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)

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