Search in sources :

Example 6 with ParseCurlCommandAction

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

the class ParseCurlCommandActionTest method testReadCurlCommandsFromTextPanel.

@Test
public void testReadCurlCommandsFromTextPanel() {
    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);
    assertTrue(commands.contains("curl 'http://jmeter.apache.org/' --max-redirs 'b'"), "Curl commands should be saved in list");
    assertTrue(commands.contains("curl 'http://jmeter.apache.org/' --include --keepalive-time '20'"), "Curl commands should be saved in list");
    assertEquals(2, commands.size());
}
Also used : ParseCurlCommandAction(org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction) Test(org.junit.jupiter.api.Test)

Example 7 with ParseCurlCommandAction

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

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

the class ParseCurlCommandActionTest method testParseCommandsException2.

@Test
public void testParseCommandsException2() {
    ParseCurlCommandAction p = new ParseCurlCommandAction();
    String cmdLine = "curl 'http://jmeter.apache.org/' --max-redir 'b'" + System.lineSeparator() + "curl 'http://jmeter.apache.org/' --include --keepalive-time '20'";
    List<String> commands = p.readFromTextPanel(cmdLine);
    assertThrowsIllegalArgument(() -> p.parseCommands(true, commands));
}
Also used : ParseCurlCommandAction(org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction) Test(org.junit.jupiter.api.Test)

Example 9 with ParseCurlCommandAction

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

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

the class ParseCurlCommandActionTest method testParseCommandsException.

@Test
public void testParseCommandsException() {
    ParseCurlCommandAction p = new ParseCurlCommandAction();
    String cmdLine = "curl 'http://jmeter.apache.org/' --max-redir 'b' " + "curl 'http://jmeter.apache.org/' --include --keepalive-time '20'";
    List<String> commands = p.readFromTextPanel(cmdLine);
    assertThrowsIllegalArgument(() -> p.parseCommands(false, commands));
}
Also used : ParseCurlCommandAction(org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction) 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