Search in sources :

Example 66 with BasicCurlParser

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

the class BasicCurlParserTest method testFormWithQuotedNotFilename.

@Test
public void testFormWithQuotedNotFilename() {
    // The quotes will be removed later by the consumer, which is ParseCurlCommandAction
    String cmdLine = "curl 'https://www.exaple.invalid/' " + "--form 'image=\"@/some/file.jpg\"'";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    List<Pair<String, ArgumentHolder>> res = request.getFormData();
    assertTrue(res.contains(Pair.of("image", StringArgumentHolder.of("@/some/file.jpg"))), "With method 'form', we should post form data");
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test)

Example 67 with BasicCurlParser

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

the class BasicCurlParserTest method testMaxTime.

@Test
public void testMaxTime() {
    String cmdLine = "curl 'http://jmeter.apache.org/' -m '2'";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    assertEquals("2000.0", String.valueOf(request.getMaxTime()));
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 68 with BasicCurlParser

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

the class BasicCurlParserTest method testConnectMax.

@Test
public void testConnectMax() {
    String cmdLine = "curl 'http://jmeter.apache.org/' -H 'Connection: keep-alive' " + "-H 'Upgrade-Insecure-Requests: 1' --connect-timeout '2'";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    assertEquals("2000.0", String.valueOf(request.getConnectTimeout()), "With method 'parser' request should contain 'connect-timeout=2'");
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 69 with BasicCurlParser

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

the class BasicCurlParserTest method testDataReadFromFile.

@Test
public void testDataReadFromFile() throws IOException {
    String encoding = StandardCharsets.UTF_8.name();
    FileUtils.writeStringToFile(tempFile, "name=test" + System.lineSeparator(), encoding, true);
    String pathname = tempFile.getAbsolutePath();
    String cmdLine = "curl 'https://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_submit/action_page.php' " + "-H 'cache-control: no-cache' --data '@" + pathname + "' ";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    assertEquals("name=test", request.getPostData(), "With method 'parser',the parameters need to reserve '\n' and '\r' ");
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 70 with BasicCurlParser

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

the class BasicCurlParserTest method testProxyUriIncorrectFormat.

@Test
public void testProxyUriIncorrectFormat() {
    String cmdLine = "curl 'http://jmeter.apache.org/' -x 'https://xxxx.xxx?xxx=xxx|xxxx|'";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    assertThrows(IllegalArgumentException.class, () -> basicCurlParser.parse(cmdLine), "The method 'translateCommandline shouldn't run when the uri of proxy is not in the correct format");
}
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