Search in sources :

Example 36 with Arguments

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

the class JavaConfigGui method configureClassName.

/**
 */
private void configureClassName() {
    String className = classNameLabeledChoice.getText().trim();
    try {
        JavaSamplerClient client = Class.forName(className, true, Thread.currentThread().getContextClassLoader()).asSubclass(JavaSamplerClient.class).getDeclaredConstructor().newInstance();
        Arguments currArgs = new Arguments();
        argsPanel.modifyTestElement(currArgs);
        Map<String, String> currArgsMap = currArgs.getArgumentsAsMap();
        Arguments newArgs = new Arguments();
        Arguments testParams = null;
        try {
            testParams = client.getDefaultParameters();
        } catch (AbstractMethodError e) {
            log.warn("JavaSamplerClient doesn't implement " + "getDefaultParameters.  Default parameters won't " + "be shown.  Please update your client class: {}", className);
        }
        if (testParams != null) {
            for (JMeterProperty jMeterProperty : testParams.getArguments()) {
                Argument arg = (Argument) jMeterProperty.getObjectValue();
                String name = arg.getName();
                String value = arg.getValue();
                // values that they did in the original test.
                if (currArgsMap.containsKey(name)) {
                    String newVal = currArgsMap.get(name);
                    if (newVal != null && newVal.length() > 0) {
                        value = newVal;
                    }
                }
                newArgs.addArgument(name, value);
            }
        }
        argsPanel.configure(newArgs);
        warningLabel.setVisible(false);
    } catch (Exception e) {
        log.error("Error getting argument list for {}", className, e);
        warningLabel.setVisible(true);
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Argument(org.apache.jmeter.config.Argument) Arguments(org.apache.jmeter.config.Arguments) JavaSamplerClient(org.apache.jmeter.protocol.java.sampler.JavaSamplerClient)

Example 37 with Arguments

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

the class TestURLRewritingModifier method testGrabSessionIdFromForm.

@Test
public void testGrabSessionIdFromForm() throws Exception {
    String[] html = new String[] { "<input name=\"sid\" value=\"myId\">", "<input name='sid' value='myId'>", "<input value=\"myId\" NAME='sid'>", "<input VALUE='myId' name=\"sid\">", "<input blah blah value=\"myId\" yoda yoda NAME='sid'>", "<input type=\"HIDDEN\" name=\"sid\"      value=\"myId\">", "<input type=\"HIDDEN\" name=\"sid\"\tvalue=\"myId\">" };
    for (int i = 0; i < html.length; i++) {
        response = new SampleResult();
        response.setResponseData(html[i], null);
        URLRewritingModifier newMod = new URLRewritingModifier();
        newMod.setThreadContext(context);
        newMod.setArgumentName("sid");
        newMod.setPathExtension(false);
        HTTPSamplerBase sampler = createSampler();
        context.setCurrentSampler(sampler);
        context.setPreviousResult(response);
        newMod.process();
        Arguments args = sampler.getArguments();
        assertEquals("For case i=" + i, "myId", ((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.jupiter.api.Test)

Example 38 with Arguments

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

the class TestHttpRequestHdr method testPostMultipartFileUpload.

@Test
public void testPostMultipartFileUpload() throws Exception {
    String url = "http://localhost/matrix.html";
    // A HTTP POST request, multipart/form-data, simple values,
    String contentEncoding = "UTF-8";
    String boundary = "xf8SqlDNvmn6mFYwrioJaeUR2_Z4cLRXOSmB";
    String endOfLine = "\r\n";
    String fileFieldValue = "test_file";
    String fileName = "somefilename.txt";
    String mimeType = "text/plain";
    String fileContent = "somedummycontent\n\ndfgdfg\r\nfgdgdg\nContent-type:dfsfsfds";
    String postBody = createMultipartFileUploadBody(fileFieldValue, fileName, mimeType, fileContent, boundary, endOfLine);
    String testPostRequest = createMultipartFormRequest(url, postBody, contentEncoding, boundary, endOfLine);
    HTTPSamplerBase s = getSamplerForRequest(url, testPostRequest, contentEncoding);
    assertEquals(HTTPConstants.POST, s.getMethod());
    assertEquals(contentEncoding, s.getContentEncoding());
    assertEquals("", s.getQueryString());
    assertTrue(s.getDoMultipart());
    // Check arguments
    Arguments arguments = s.getArguments();
    assertEquals(0, arguments.getArgumentCount());
    // Assume there's at least one file
    HTTPFileArg hfa = s.getHTTPFiles()[0];
    assertEquals(fileFieldValue, hfa.getParamName());
    assertEquals(fileName, hfa.getPath());
    assertEquals(mimeType, hfa.getMimeType());
}
Also used : Arguments(org.apache.jmeter.config.Arguments) HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) Test(org.junit.jupiter.api.Test)

Example 39 with Arguments

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

the class TestHttpRequestHdr method testPostMultipartFormData.

@Test
public void testPostMultipartFormData() throws Exception {
    String url = "http://localhost/matrix.html";
    // A HTTP POST request, multipart/form-data, simple values,
    String contentEncoding = "UTF-8";
    String boundary = "xf8SqlDNvmn6mFYwrioJaeUR2_Z4cLRXOSmB";
    String endOfLine = "\r\n";
    String titleValue = "mytitle";
    String descriptionValue = "mydescription";
    String postBody = createMultipartFormBody(titleValue, descriptionValue, contentEncoding, true, boundary, endOfLine);
    String testPostRequest = createMultipartFormRequest(url, postBody, contentEncoding, boundary, endOfLine);
    HTTPSamplerBase s = getSamplerForRequest(url, testPostRequest, contentEncoding);
    assertEquals(HTTPConstants.POST, s.getMethod());
    assertEquals(contentEncoding, s.getContentEncoding());
    assertTrue(s.getDoMultipart());
    // Check arguments
    Arguments arguments = s.getArguments();
    assertEquals(2, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "title", titleValue, titleValue, contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(1), "description", descriptionValue, descriptionValue, contentEncoding, false);
    // A HTTP POST request, multipart/form-data, simple values,
    // with \r\n as end of line, which is according to spec,
    // and with more headers in each multipart
    endOfLine = "\r\n";
    titleValue = "mytitle";
    descriptionValue = "mydescription";
    postBody = createMultipartFormBody(titleValue, descriptionValue, contentEncoding, true, boundary, endOfLine);
    testPostRequest = createMultipartFormRequest(url, postBody, contentEncoding, boundary, endOfLine);
    s = getSamplerForRequest(url, testPostRequest, contentEncoding);
    assertEquals(HTTPConstants.POST, s.getMethod());
    assertEquals(contentEncoding, s.getContentEncoding());
    assertTrue(s.getDoMultipart());
    // Check arguments
    arguments = s.getArguments();
    assertEquals(2, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "title", titleValue, titleValue, contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(1), "description", descriptionValue, descriptionValue, contentEncoding, false);
    // A HTTP POST request, multipart/form-data, simple values,
    // with \n as end of line, which should also be handled,
    // and with more headers in each multipart
    endOfLine = "\n";
    titleValue = "mytitle";
    descriptionValue = "mydescription";
    postBody = createMultipartFormBody(titleValue, descriptionValue, contentEncoding, true, boundary, endOfLine);
    testPostRequest = createMultipartFormRequest(url, postBody, contentEncoding, boundary, endOfLine);
    s = getSamplerForRequest(url, testPostRequest, contentEncoding);
    assertEquals(HTTPConstants.POST, s.getMethod());
    assertEquals(contentEncoding, s.getContentEncoding());
    assertTrue(s.getDoMultipart());
    // Check arguments
    arguments = s.getArguments();
    assertEquals(2, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "title", titleValue, titleValue, contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(1), "description", descriptionValue, descriptionValue, contentEncoding, false);
    // A HTTP POST request, multipart/form-data, with value that will change
    // if they are url encoded
    // Values are similar to __VIEWSTATE parameter that .net uses
    endOfLine = "\r\n";
    titleValue = "/wEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ/rA+8DZ2dnZ2dnZ2d/GNDar6OshPwdJc=";
    descriptionValue = "mydescription";
    postBody = createMultipartFormBody(titleValue, descriptionValue, contentEncoding, true, boundary, endOfLine);
    testPostRequest = createMultipartFormRequest(url, postBody, contentEncoding, boundary, endOfLine);
    s = getSamplerForRequest(url, testPostRequest, contentEncoding);
    assertEquals(HTTPConstants.POST, s.getMethod());
    assertEquals(contentEncoding, s.getContentEncoding());
    assertTrue(s.getDoMultipart());
    // Check arguments
    arguments = s.getArguments();
    assertEquals(2, arguments.getArgumentCount());
    checkArgument((HTTPArgument) arguments.getArgument(0), "title", titleValue, titleValue, contentEncoding, false);
    checkArgument((HTTPArgument) arguments.getArgument(1), "description", descriptionValue, descriptionValue, contentEncoding, false);
}
Also used : Arguments(org.apache.jmeter.config.Arguments) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) Test(org.junit.jupiter.api.Test)

Example 40 with Arguments

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

the class TestHttpRequestHdr method testPostRequestEncodings.

@Test
public void testPostRequestEncodings() throws Exception {
    String url = "http://localhost/matrix.html";
    // A HTTP POST request, with encoding not known
    String contentEncoding = "";
    String param1Value = "yes";
    String param2Value = "0+5 -\u00c5%C3%85";
    String param2ValueEncoded = URLEncoder.encode(param2Value, "UTF-8");
    String postBody = "param1=" + param1Value + "&param2=" + param2ValueEncoded + "\r\n";
    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
    HTTPSamplerBase s = getSamplerForRequest(null, testPostRequest, null);
    assertEquals(HTTPConstants.POST, 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 POST 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);
    postBody = "param1=" + param1Value + "&param2=" + param2ValueEncoded + "\r\n";
    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;
    s = getSamplerForRequest(url, testPostRequest, contentEncoding);
    assertEquals(HTTPConstants.POST, 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 POST request, with ISO-8859-1 encoding
    contentEncoding = "ISO-8859-1";
    param1Value = "yes";
    param2Value = "0+5 -\u00c5%C3%85";
    param2ValueEncoded = URLEncoder.encode(param2Value, contentEncoding);
    postBody = "param1=" + param1Value + "&param2=" + param2ValueEncoded + "\r\n";
    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;
    s = getSamplerForRequest(url, testPostRequest, contentEncoding);
    assertEquals(HTTPConstants.POST, 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) Test(org.junit.jupiter.api.Test)

Aggregations

Arguments (org.apache.jmeter.config.Arguments)96 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 HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)10 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)8 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)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 Test (org.junit.Test)5 HTTPFileArgs (org.apache.jmeter.protocol.http.util.HTTPFileArgs)4 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)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