Search in sources :

Example 61 with BasicCurlParser

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

the class BasicCurlParserTest method testCertType.

@Test
public void testCertType() {
    String cmdLine = "curl 'http://jmeter.apache.org/'  --cert-type 'test'";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    assertEquals("cert-type", 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 62 with BasicCurlParser

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

the class BasicCurlParserTest method testFormWithEmptyHeader.

@Test
public void testFormWithEmptyHeader() {
    String cmdLine = "curl 'https://example.invalid' -H 'X-Something;' ";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    List<Pair<String, String>> res = request.getHeaders();
    assertTrue(res.contains(Pair.of("X-Something", "")), "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 63 with BasicCurlParser

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

the class BasicCurlParserTest method testDataUrlEncodeWith2AtSymbol.

@Test
public void testDataUrlEncodeWith2AtSymbol() throws IOException {
    String encoding = StandardCharsets.UTF_8.name();
    FileUtils.writeStringToFile(tempFile, "test@", 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-urlencode 'name@" + pathname + "' ";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    assertEquals("name=test%40", request.getPostData(), "With method 'parser',the parameters in the file need to be encoded'");
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 64 with BasicCurlParser

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

the class BasicCurlParserTest method testDataReadFromNonexistentFile.

@Test
public void testDataReadFromNonexistentFile() {
    String cmdLine = "curl 'https://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_submit/action_page.php' " + "-H 'cache-control: no-cache' --data '@test.txt' ";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    assertThrows(IllegalArgumentException.class, () -> basicCurlParser.parse(cmdLine), "The method 'translateCommandline shouldn't run when the path of file is incorrect");
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 65 with BasicCurlParser

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

the class BasicCurlParserTest method testFormString.

@Test
public void testFormString() {
    String cmdLine = "curl 'https://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_submit/action_page.php' " + "-H 'cache-control: no-cache' --form-string 'image=@C:\\Test\\test.jpg' ";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    List<Pair<String, String>> res = request.getFormStringData();
    assertTrue(res.contains(Pair.of("image", "@C:\\Test\\test.jpg")), "With method 'parser', we should post form data: " + request.getFormStringData());
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Pair(org.apache.commons.lang3.tuple.Pair) 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