Search in sources :

Example 56 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.getDoMultipartPost());
    // 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.getDoMultipartPost());
    // 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 57 with Arguments

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

the class TestHttpRequestHdr method testRepeatedArguments.

@Test
public void testRepeatedArguments() throws Exception {
    String url = "http://localhost/matrix.html";
    // A HTTP GET request
    String contentEncoding = "UTF-8";
    String testGetRequest = "GET " + url + "?update=yes&d=1&d=2&d=&d=&d=&d=&d=&d=1&d=2&d=1&d=&d= " + "HTTP/1.0\r\n\r\n";
    HTTPSamplerBase s = getSamplerForRequest(url, testGetRequest, contentEncoding);
    assertEquals(HTTPConstants.GET, s.getMethod());
    assertEquals(contentEncoding, s.getContentEncoding());
    // Check arguments
    Arguments arguments = s.getArguments();
    assertEquals(13, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "update", "yes", "yes", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(1), "d", "1", "1", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(2), "d", "2", "2", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(3), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(4), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(5), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(6), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(7), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(8), "d", "1", "1", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(9), "d", "2", "2", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(10), "d", "1", "1", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(11), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(12), "d", "", "", contentEncoding, false);
    // A HTTP POST request
    contentEncoding = "UTF-8";
    String postBody = "update=yes&d=1&d=2&d=&d=&d=&d=&d=&d=1&d=2&d=1&d=&d=";
    String testPostRequest = "POST " + url + " HTTP/1.0\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());
    assertFalse(s.getDoMultipartPost());
    assertEquals(contentEncoding, s.getContentEncoding());
    // Check arguments
    arguments = s.getArguments();
    assertEquals(13, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "update", "yes", "yes", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(1), "d", "1", "1", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(2), "d", "2", "2", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(3), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(4), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(5), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(6), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(7), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(8), "d", "1", "1", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(9), "d", "2", "2", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(10), "d", "1", "1", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(11), "d", "", "", contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(12), "d", "", "", contentEncoding, false);
    // A HTTP POST request, with content-type text/plain
    contentEncoding = "UTF-8";
    postBody = "update=yes&d=1&d=2&d=&d=&d=&d=&d=&d=1&d=2&d=1&d=쎅&d=";
    testPostRequest = "POST " + url + " HTTP/1.1\r\n" + "Content-type: text/plain\r\n" + "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n" + "\r\n" + postBody;
    s = getSamplerForRequest(url, testPostRequest, contentEncoding);
    assertEquals(HTTPConstants.POST, s.getMethod());
    assertFalse(s.getDoMultipartPost());
    assertEquals(contentEncoding, s.getContentEncoding());
    // Check arguments
    // We should have one argument, with the value equal to the post body
    arguments = s.getArguments();
    assertEquals(1, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "", postBody, postBody, contentEncoding, false);
    // A HTTP POST request, with content-type text/plain; charset=UTF-8
    // The encoding should be picked up from the header we send with the request
    contentEncoding = "UTF-8";
    postBody = "update=yes&d=1&d=2&d=&d=&d=&d=&d=&d=1&d=2&d=1&d=쎅&d=";
    testPostRequest = "POST " + url + " HTTP/1.1\r\n" + "Content-type: text/plain; charset=" + contentEncoding + "\r\n" + "Content-length: " + getBodyLength(postBody, contentEncoding) + "\r\n" + "\r\n" + postBody;
    // Use null for url to simulate that HttpRequestHdr do not
    // know the encoding for the page. Specify contentEncoding, so the
    // request is "sent" using that encoding
    s = getSamplerForRequest(null, testPostRequest, contentEncoding);
    assertEquals(HTTPConstants.POST, s.getMethod());
    assertFalse(s.getDoMultipartPost());
    assertEquals(contentEncoding, s.getContentEncoding());
    // Check arguments
    // We should have one argument, with the value equal to the post body
    arguments = s.getArguments();
    assertEquals(1, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "", postBody, postBody, contentEncoding, false);
    // A HTTP POST request, with content-type text/plain; charset=UTF-8
    // The encoding should be picked up from the header we send with the request
    contentEncoding = "UTF-8";
    url = "http://vmdal-hqqa9/retalixhq/GG_Implementation/ScreenEntity/ScreenEntityHTTP.aspx?Action=Save&ET=Vendor&TT=Single&Sid=1347280336092";
    postBody = "<Action UIStatus=\"2\"><Vendor Id=\"9292\" HOST_ID=\"0\" VENDOR=\"9292\" TERMS_TYPE=\"No Terms\" TERMS=\"0 %\" AUTO_PRICE=\"Use System Default\" VM_VENDOR_TYPE=\"DSD Vendor\" ITEM_FORMAT=\"PLU\" COST_ENTRY_SORT=\"UPC/EAN\" VM_REPORT_SORT=\"UPC/EAN\" VM_ORDER_SORT=\"UPC/EAN\" VM_RECEIVING_SORT=\"UPC/EAN\" VM_MAX_BACK_ORDERS=\"99\" MAX_OPEN_DAYS=\"99\" PAY_BASED_ON=\"System Cost\" ORDER_COST_DATE=\"Use System Rule\" VM_CONSIDER_FREE=\"False\" VM_SHOW_DETAIL=\"False\" VM_UPDATE_COST=\"No\" RD_USE_VENDOR_CC=\"False\" BLIND_RECEIVING=\"Default\" EXCLUDE_RECEIVED_COST=\"False\" PRINT_ITEM_ADJ=\"False\" PRINT_OVERALL_ADJ=\"False\" PRINT_TAX_DETAIL=\"False\" BLOCK_PRICE_VIEW=\"False\" DELIVERY_STATUS=\"No Delivery\" AUTO_RECEIVE=\"False\" TARGET_GM_FLAG=\"%\" MINIMUM_GM_FLAG=\"%\" MARGIN_TYPE=\"Gross Margin\" HOLD_REGULAR=\"Default\" HOLD_SPECIALS=\"Default\" TRUSTING_VENDOR=\"False\" AUTO_ACCEPT=\"All\" EARLY_RCPT_AFFECTS=\"All Costs\" SBT_ELIGIBLE=\"Not eligible\" SBT_REPORTING_DAY=\"Monday\" AUTO_BALANCE_FLAG=\"$\" DAX_MANAGED=\"False\" CHANGE_ID=\"QA\" CHANGE_SOURCE=\"Manual Change\" ORIGINAL_SOURCE=\"Manual Change\" RECORD_STATUS=\"Add\" RECORD_STATUS_DATE=\"9/7/2012 8:34:58 AM\" VENDOR_NAME=\"test\" UIStatus=\"2\"/></Action>";
    testPostRequest = "POST " + url + " HTTP/1.1\r\n" + "x-requested-with: XMLHttpRequest" + "\r\n" + "Accept-Language: en-us" + "\r\n" + "Referer: http://vmdal-hqqa9/retalixhq/GG_Implementation/ScreenEntity/ScreenEntityPage.aspx?ET=Vendor&TT=Single&WM=2&UID=9292&Sid=1347280331908&UITH=Blue&MUID=window_0" + "\r\n" + "Accept: */*" + "\r\n" + "Content-Type: application/x-www-form-urlencoded" + "\r\n" + "Accept-Encoding: gzip, deflate" + "\r\n" + "User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; Tablet PC 2.0)" + "\r\n" + "Host: vmdal-hqqa9" + "\r\n" + "Content-Length: " + getBodyLength(postBody, contentEncoding) + "\r\n" + "Proxy-Connection: Keep-Alive" + "\r\n" + "Pragma: no-cache" + "\r\n" + "Cookie: RHQ=sid=5aaeb66c-e174-4f4c-9928-83cffcc62150" + "\r\n" + "\r\n" + postBody;
    // Use null for url to simulate that HttpRequestHdr do not
    // know the encoding for the page. Specify contentEncoding, so the
    // request is "sent" using that encoding
    s = getSamplerForRequest(null, testPostRequest, contentEncoding);
    assertEquals(HTTPConstants.POST, s.getMethod());
    assertFalse(s.getDoMultipartPost());
    // TODO Should this be OK ?
    //assertEquals(contentEncoding, s.getContentEncoding());
    // Check arguments
    // We should have one argument, with the value equal to the post body
    arguments = s.getArguments();
    assertEquals(1, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "", postBody, postBody, contentEncoding, false);
}
Also used : Arguments(org.apache.jmeter.config.Arguments) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) Test(org.junit.Test)

Example 58 with Arguments

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

the class TestURLRewritingModifier method testGrabSessionId7.

@Test
public void testGrabSessionId7() throws Exception {
    String html = "location: http://server.com/index.html" + "?session_id=bonjour+monsieur";
    response = new SampleResult();
    response.setResponseData(html, null);
    mod.setArgumentName("session_id");
    mod.setEncode(true);
    HTTPSamplerBase sampler = createSampler();
    sampler.addArgument("session_id", "adfasdfdsafasdfasd");
    context.setCurrentSampler(sampler);
    context.setPreviousResult(response);
    mod.process();
    Arguments args = sampler.getArguments();
    // System.out.println(((Argument) args.getArguments().get(0).getObjectValue()).getValue());
    // System.out.println(sampler.toString());
    assertEquals("bonjour+monsieur", ((Argument) args.getArguments().get(0).getObjectValue()).getValue());
    assertEquals("http://server.com/index.html?" + "session_id=bonjour%2Bmonsieur", sampler.toString());
}
Also used : Arguments(org.apache.jmeter.config.Arguments) SampleResult(org.apache.jmeter.samplers.SampleResult) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) Test(org.junit.Test)

Example 59 with Arguments

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

the class TestURLRewritingModifier method testGrabSessionIdEndedInTab.

@Test
public void testGrabSessionIdEndedInTab() throws Exception {
    String html = "href='index.html?session_id=jfdkjdkfjddkfdfjkdjfdf\t";
    response = new SampleResult();
    response.setResponseData(html, null);
    mod.setArgumentName("session_id");
    HTTPSamplerBase sampler = createSampler();
    context.setCurrentSampler(sampler);
    context.setPreviousResult(response);
    mod.process();
    Arguments args = sampler.getArguments();
    assertEquals("jfdkjdkfjddkfdfjkdjfdf", ((Argument) args.getArguments().get(0).getObjectValue()).getValue());
}
Also used : Arguments(org.apache.jmeter.config.Arguments) SampleResult(org.apache.jmeter.samplers.SampleResult) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) Test(org.junit.Test)

Example 60 with Arguments

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

the class TestHTTPSamplers method testParseArguments2.

// Parse arguments all at once
@Test
public void testParseArguments2() {
    HTTPSamplerBase sampler = new HTTPNullSampler();
    Arguments args;
    Argument arg;
    args = sampler.getArguments();
    assertEquals(0, args.getArgumentCount());
    assertEquals(0, sampler.getHTTPFileCount());
    sampler.parseArguments("&name1&name2=&name3=value3");
    args = sampler.getArguments();
    assertEquals(3, args.getArgumentCount());
    assertEquals(0, sampler.getHTTPFileCount());
    arg = args.getArgument(0);
    assertEquals("name1", arg.getName());
    assertEquals("", arg.getMetaData());
    assertEquals("", arg.getValue());
    assertEquals(0, sampler.getHTTPFileCount());
    arg = args.getArgument(1);
    assertEquals("name2", arg.getName());
    assertEquals("=", arg.getMetaData());
    assertEquals("", arg.getValue());
    assertEquals(0, sampler.getHTTPFileCount());
    arg = args.getArgument(2);
    assertEquals("name3", arg.getName());
    assertEquals("=", arg.getMetaData());
    assertEquals("value3", arg.getValue());
    assertEquals(0, sampler.getHTTPFileCount());
}
Also used : Argument(org.apache.jmeter.config.Argument) Arguments(org.apache.jmeter.config.Arguments) Test(org.junit.Test)

Aggregations

Arguments (org.apache.jmeter.config.Arguments)75 Test (org.junit.Test)27 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)18 SampleResult (org.apache.jmeter.samplers.SampleResult)15 Argument (org.apache.jmeter.config.Argument)13 HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)9 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)7 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)5 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)5 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)3 TestElement (org.apache.jmeter.testelement.TestElement)3 TestPlan (org.apache.jmeter.testelement.TestPlan)3 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)3 File (java.io.File)2 Iterator (java.util.Iterator)2 InvalidVariableException (org.apache.jmeter.functions.InvalidVariableException)2 HTTPFileArgs (org.apache.jmeter.protocol.http.util.HTTPFileArgs)2 ResultCollector (org.apache.jmeter.reporters.ResultCollector)2 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)2 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)2