Search in sources :

Example 76 with Arguments

use of org.apache.jmeter.config.Arguments in project jmeter by apache.

the class TestHttpRequestHdr method testGetRequestEncodings.

private void testGetRequestEncodings(String url) throws Exception {
    // A HTTP GET request, with encoding not known
    String contentEncoding = "";
    String param1Value = "yes";
    String param2Value = "0+5 -\u00c5\uc385%C3%85";
    String param2ValueEncoded = URLEncoder.encode(param2Value, "UTF-8");
    String testGetRequest = "GET " + url + "?param1=" + param1Value + "&param2=" + param2ValueEncoded + " " + "HTTP/1.1\r\n\r\n";
    // Use null for url and contentEncoding, to simulate that HttpRequestHdr do not
    // know the encoding for the page
    HTTPSamplerBase s = getSamplerForRequest(null, testGetRequest, null);
    assertEquals(HTTPConstants.GET, s.getMethod());
    assertEquals(contentEncoding, s.getContentEncoding());
    // Check arguments
    Arguments arguments = s.getArguments();
    assertEquals(2, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false);
    // When the encoding is not known, the argument will get the encoded value, and the "encode?" set to false
    checkArgument((HTTPArgument) arguments.getArgument(1), "param2", param2ValueEncoded, param2ValueEncoded, contentEncoding, false);
    // A HTTP GET request, with UTF-8 encoding
    contentEncoding = "UTF-8";
    param1Value = "yes";
    param2Value = "0+5 -\u007c\u2aa1\u266a\u0153\u20a1\u0115\u0364\u00c5\u2052\uc385%C3%85";
    param2ValueEncoded = URLEncoder.encode(param2Value, contentEncoding);
    testGetRequest = "GET " + url + "?param1=" + param1Value + "&param2=" + param2ValueEncoded + " " + "HTTP/1.1\r\n\r\n";
    s = getSamplerForRequest(url, testGetRequest, contentEncoding);
    assertEquals(HTTPConstants.GET, s.getMethod());
    assertEquals(contentEncoding, s.getContentEncoding());
    // Check arguments
    arguments = s.getArguments();
    assertEquals(2, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(1), "param2", param2Value, param2ValueEncoded, contentEncoding, true);
    // A HTTP GET request, with ISO-8859-1 encoding
    contentEncoding = "ISO-8859-1";
    param1Value = "yes";
    param2Value = "0+5 -\u00c5%C3%85";
    param2ValueEncoded = URLEncoder.encode(param2Value, contentEncoding);
    testGetRequest = "GET " + url + "?param1=" + param1Value + "&param2=" + param2ValueEncoded + " " + "HTTP/1.1\r\n\r\n";
    s = getSamplerForRequest(url, testGetRequest, contentEncoding);
    assertEquals(HTTPConstants.GET, s.getMethod());
    assertEquals(contentEncoding, s.getContentEncoding());
    // Check arguments
    arguments = s.getArguments();
    assertEquals(2, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "param1", param1Value, param1Value, contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(1), "param2", param2Value, param2ValueEncoded, contentEncoding, true);
}
Also used : Arguments(org.apache.jmeter.config.Arguments) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)

Example 77 with Arguments

use of org.apache.jmeter.config.Arguments in project jmeter by apache.

the class TestHttpRequestHdr method testEncodedArguments.

private void testEncodedArguments(String url) throws Exception {
    // A HTTP GET request, with encoding not known
    String contentEncoding = "";
    String queryString = "abc%3FSPACE=a+b&space=a%20b&query=What%3F";
    String testGetRequest = "GET " + url + "?" + queryString + " HTTP/1.1\r\n\r\n";
    // Use null for url and contentEncoding, to simulate that HttpRequestHdr do not
    // know the encoding for the page
    HTTPSamplerBase s = getSamplerForRequest(null, testGetRequest, null);
    assertEquals(HTTPConstants.GET, s.getMethod());
    assertEquals(queryString, s.getQueryString());
    assertEquals(contentEncoding, s.getContentEncoding());
    // Check arguments
    Arguments arguments = s.getArguments();
    assertEquals(3, arguments.getArgumentCount());
    // When the encoding is not known, the argument will get the encoded value, and the "encode?" set to false
    checkArgument((HTTPArgument) arguments.getArgument(0), "abc%3FSPACE", "a+b", "a+b", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(1), "space", "a%20b", "a%20b", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(2), "query", "What%3F", "What%3F", contentEncoding, false);
    // A HTTP GET request, with UTF-8 encoding
    contentEncoding = "UTF-8";
    queryString = "abc%3FSPACE=a+b&space=a%20b&query=What%3F";
    testGetRequest = "GET " + url + "?" + queryString + " HTTP/1.1\r\n\r\n";
    s = getSamplerForRequest(url, testGetRequest, contentEncoding);
    assertEquals(HTTPConstants.GET, s.getMethod());
    String expectedQueryString = "abc%3FSPACE=a+b&space=a+b&query=What%3F";
    assertEquals(expectedQueryString, s.getQueryString());
    assertEquals(contentEncoding, s.getContentEncoding());
    // Check arguments
    arguments = s.getArguments();
    assertEquals(3, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "abc?SPACE", "a b", "a+b", contentEncoding, true);
    checkArgument((HTTPArgument) arguments.getArgument(1), "space", "a b", "a+b", contentEncoding, true);
    checkArgument((HTTPArgument) arguments.getArgument(2), "query", "What?", "What%3F", contentEncoding, true);
    // A HTTP POST request, with unknown encoding
    contentEncoding = "";
    String postBody = "abc%3FSPACE=a+b&space=a%20b&query=What%3F";
    String testPostRequest = "POST " + url + " HTTP/1.1\r\n" + "Content-type: " + HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED + "\r\n" + "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n" + "\r\n" + postBody;
    // Use null for url and contentEncoding, to simulate that HttpRequestHdr do not
    // know the encoding for the page
    s = getSamplerForRequest(null, testPostRequest, null);
    assertEquals(HTTPConstants.POST, s.getMethod());
    assertEquals(queryString, s.getQueryString());
    assertEquals(contentEncoding, s.getContentEncoding());
    assertFalse(s.getDoMultipart());
    // Check arguments
    arguments = s.getArguments();
    assertEquals(3, arguments.getArgumentCount());
    // When the encoding is not known, the argument will get the encoded value, and the "encode?" set to false
    checkArgument((HTTPArgument) arguments.getArgument(0), "abc%3FSPACE", "a+b", "a+b", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(1), "space", "a%20b", "a%20b", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(2), "query", "What%3F", "What%3F", contentEncoding, false);
    // A HTTP POST request, with UTF-8 encoding
    contentEncoding = "UTF-8";
    postBody = "abc?SPACE=a+b&space=a%20b&query=What?";
    testPostRequest = "POST " + url + " HTTP/1.1\n" + "Content-type: " + HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED + "\r\n" + "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n" + "\r\n" + postBody;
    s = getSamplerForRequest(url, testPostRequest, contentEncoding);
    assertEquals(HTTPConstants.POST, s.getMethod());
    expectedQueryString = "abc%3FSPACE=a+b&space=a+b&query=What%3F";
    assertEquals(expectedQueryString, s.getQueryString());
    assertEquals(contentEncoding, s.getContentEncoding());
    assertFalse(s.getDoMultipart());
    // Check arguments
    arguments = s.getArguments();
    assertEquals(3, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "abc?SPACE", "a b", "a+b", contentEncoding, true);
    checkArgument((HTTPArgument) arguments.getArgument(1), "space", "a b", "a+b", contentEncoding, true);
    checkArgument((HTTPArgument) arguments.getArgument(2), "query", "What?", "What%3F", contentEncoding, true);
}
Also used : Arguments(org.apache.jmeter.config.Arguments) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)

Example 78 with Arguments

use of org.apache.jmeter.config.Arguments in project jmeter by apache.

the class TestGraphQLRequestParamUtils method testInvalidQueryParam.

@Test
void testInvalidQueryParam() {
    Arguments args = new Arguments();
    args.addArgument(new HTTPArgument("query", "select * from emp", "=", false));
    assertThrows(IllegalArgumentException.class, () -> GraphQLRequestParamUtils.toGraphQLRequestParams(args, null));
}
Also used : Arguments(org.apache.jmeter.config.Arguments) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 79 with Arguments

use of org.apache.jmeter.config.Arguments in project jmeter by apache.

the class TestGraphQLRequestParamUtils method testInvalidQueryParamVariables.

@Test
void testInvalidQueryParamVariables() {
    Arguments args = new Arguments();
    args.addArgument(new HTTPArgument("query", "query { droid { id }}", "=", false));
    args.addArgument(new HTTPArgument("variables", "r2d2", "=", false));
    assertThrows(IllegalArgumentException.class, () -> GraphQLRequestParamUtils.toGraphQLRequestParams(args, null));
}
Also used : Arguments(org.apache.jmeter.config.Arguments) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 80 with Arguments

use of org.apache.jmeter.config.Arguments in project jmeter by apache.

the class TestGraphQLRequestParamUtils method testMissingParams.

@Test
void testMissingParams() {
    Arguments args = new Arguments();
    assertThrows(IllegalArgumentException.class, () -> GraphQLRequestParamUtils.toGraphQLRequestParams(args, null));
}
Also used : Arguments(org.apache.jmeter.config.Arguments) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Arguments (org.apache.jmeter.config.Arguments)102 Test (org.junit.jupiter.api.Test)32 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)18 SampleResult (org.apache.jmeter.samplers.SampleResult)17 Argument (org.apache.jmeter.config.Argument)15 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)11 HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)10 Test (org.junit.Test)10 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)7 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)6 TestElement (org.apache.jmeter.testelement.TestElement)6 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)5 HTTPFileArgs (org.apache.jmeter.protocol.http.util.HTTPFileArgs)4 IOException (java.io.IOException)3 URL (java.net.URL)3 Iterator (java.util.Iterator)3 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)3 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)3