Search in sources :

Example 16 with TestPlan

use of org.apache.jmeter.testelement.TestPlan in project jmeter by apache.

the class TestHTTPSamplersAgainstHttpMirrorServer method testPostRequest_BodyFromParameterValues.

private void testPostRequest_BodyFromParameterValues(int samplerType, String samplerDefaultEncoding) throws Exception {
    // ensure only values are used
    final String titleField = "";
    String titleValue = "mytitle";
    // ensure only values are used
    final String descriptionField = "";
    String descriptionValue = "mydescription";
    // Test sending data with default encoding
    HTTPSamplerBase sampler = createHttpSampler(samplerType);
    String contentEncoding = "";
    setupUrl(sampler, contentEncoding);
    setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
    ((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
    ((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
    HTTPSampleResult res = executeSampler(sampler);
    String expectedPostBody = titleValue + descriptionValue;
    checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
    // Test sending data as ISO-8859-1
    sampler = createHttpSampler(samplerType);
    contentEncoding = ISO_8859_1;
    setupUrl(sampler, contentEncoding);
    setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
    ((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
    ((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
    res = executeSampler(sampler);
    expectedPostBody = titleValue + descriptionValue;
    checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
    // Test sending data as UTF-8
    sampler = createHttpSampler(samplerType);
    contentEncoding = "UTF-8";
    titleValue = "mytitleœ₡ĕÅ";
    descriptionValue = "mydescriptionœ₡ĕÅ";
    setupUrl(sampler, contentEncoding);
    setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
    ((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
    ((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
    res = executeSampler(sampler);
    expectedPostBody = titleValue + descriptionValue;
    checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
    // Test sending data as UTF-8, with values that will change when urlencoded
    sampler = createHttpSampler(samplerType);
    contentEncoding = "UTF-8";
    titleValue = "mytitle/=";
    descriptionValue = "mydescription   /\\";
    setupUrl(sampler, contentEncoding);
    setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
    ((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
    ((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
    res = executeSampler(sampler);
    expectedPostBody = titleValue + descriptionValue;
    checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
    // Test sending data as UTF-8, with values that will change when urlencoded, and where
    // we tell the sampler to urlencode the parameter value
    sampler = createHttpSampler(samplerType);
    contentEncoding = "UTF-8";
    titleValue = "mytitle/=";
    descriptionValue = "mydescription   /\\";
    setupUrl(sampler, contentEncoding);
    setupFormData(sampler, true, titleField, titleValue, descriptionField, descriptionValue);
    res = executeSampler(sampler);
    expectedPostBody = URLEncoder.encode(titleValue + descriptionValue, contentEncoding);
    checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
    // Test sending data as UTF-8, with values that have been urlencoded
    sampler = createHttpSampler(samplerType);
    contentEncoding = "UTF-8";
    titleValue = "mytitle%2F%3D";
    descriptionValue = "mydescription+++%2F%5C";
    setupUrl(sampler, contentEncoding);
    setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
    ((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
    ((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
    res = executeSampler(sampler);
    expectedPostBody = titleValue + descriptionValue;
    checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
    // Test sending data as UTF-8, with values that have been urlencoded, and
    // where we tell the sampler to urlencode the parameter values
    sampler = createHttpSampler(samplerType);
    contentEncoding = "UTF-8";
    titleValue = "mytitle%2F%3D";
    descriptionValue = "mydescription+++%2F%5C";
    setupUrl(sampler, contentEncoding);
    setupFormData(sampler, true, titleField, titleValue, descriptionField, descriptionValue);
    res = executeSampler(sampler);
    expectedPostBody = titleValue + descriptionValue;
    checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
    // Test sending data as UTF-8, with values similar to __VIEWSTATE parameter that .net uses
    sampler = createHttpSampler(samplerType);
    contentEncoding = "UTF-8";
    titleValue = "/wEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ/rA+8DZ2dnZ2dnZ2d/GNDar6OshPwdJc=";
    descriptionValue = "mydescription";
    setupUrl(sampler, contentEncoding);
    setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
    ((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
    ((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
    res = executeSampler(sampler);
    expectedPostBody = titleValue + descriptionValue;
    checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
    // Test sending data as UTF-8, with + as part of the value,
    // where the value is set in sampler as not urluencoded, but the 
    // isalwaysencoded flag of the argument is set to false.
    // This mimics the HTTPConstants.addNonEncodedArgument, which the
    // Proxy server calls in some cases
    sampler = createHttpSampler(samplerType);
    contentEncoding = "UTF-8";
    titleValue = "mytitle++";
    descriptionValue = "mydescription+";
    setupUrl(sampler, contentEncoding);
    setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
    ((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
    ((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
    res = executeSampler(sampler);
    expectedPostBody = titleValue + descriptionValue;
    checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
    // Test sending data as UTF-8, where user defined variables are used
    // to set the value for form data
    JMeterUtils.setLocale(Locale.ENGLISH);
    TestPlan testPlan = new TestPlan();
    JMeterVariables vars = new JMeterVariables();
    vars.put("title_prefix", "a testÅ");
    vars.put("description_suffix", "the_end");
    JMeterContextService.getContext().setVariables(vars);
    JMeterContextService.getContext().setSamplingStarted(true);
    ValueReplacer replacer = new ValueReplacer();
    replacer.setUserDefinedVariables(testPlan.getUserDefinedVariables());
    sampler = createHttpSampler(samplerType);
    contentEncoding = "UTF-8";
    titleValue = "${title_prefix}mytitleœ₡ĕÅ";
    descriptionValue = "mydescriptionœ₡ĕÅ${description_suffix}";
    setupUrl(sampler, contentEncoding);
    setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
    ((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
    ((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
    // Replace the variables in the sampler
    replacer.replaceValues(sampler);
    res = executeSampler(sampler);
    String expectedTitleValue = "a testÅmytitleœ₡ĕÅ";
    String expectedDescriptionValue = "mydescriptionœ₡ĕÅthe_end";
    expectedPostBody = expectedTitleValue + expectedDescriptionValue;
    checkPostRequestBody(sampler, res, samplerDefaultEncoding, contentEncoding, expectedPostBody);
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) HTTPArgument(org.apache.jmeter.protocol.http.util.HTTPArgument) TestPlan(org.apache.jmeter.testelement.TestPlan) ValueReplacer(org.apache.jmeter.engine.util.ValueReplacer)

Example 17 with TestPlan

use of org.apache.jmeter.testelement.TestPlan in project jmeter by apache.

the class Move method getParentNode.

private JMeterTreeNode getParentNode(JMeterTreeNode currentNode) {
    JMeterTreeNode parentNode = (JMeterTreeNode) currentNode.getParent();
    TestElement te = currentNode.getTestElement();
    if (te instanceof TestPlan || te instanceof WorkBench) {
        // So elements can only be added as children
        parentNode = null;
    }
    return parentNode;
}
Also used : TestPlan(org.apache.jmeter.testelement.TestPlan) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TestElement(org.apache.jmeter.testelement.TestElement) WorkBench(org.apache.jmeter.testelement.WorkBench)

Example 18 with TestPlan

use of org.apache.jmeter.testelement.TestPlan in project jmeter by apache.

the class ProxyControlGui method buildNodesModel.

private void buildNodesModel(JMeterTreeNode node, String parentName, int level) {
    String separator = " > ";
    if (node != null) {
        for (int i = 0; i < node.getChildCount(); i++) {
            StringBuilder name = new StringBuilder();
            JMeterTreeNode cur = (JMeterTreeNode) node.getChildAt(i);
            TestElement te = cur.getTestElement();
            /*
                 * Will never be true. Probably intended to use
                 * org.apache.jmeter.threads.ThreadGroup rather than
                 * java.lang.ThreadGroup However, that does not work correctly;
                 * whereas treating it as a Controller does. if (te instanceof
                 * ThreadGroup) { name.append(parent_name);
                 * name.append(cur.getName()); name.append(separator);
                 * buildNodesModel(cur, name.toString(), level); } else
                 */
            if (te instanceof Controller) {
                name.append(parentName);
                name.append(cur.getName());
                TreeNodeWrapper tnw = new TreeNodeWrapper(cur, name.toString());
                targetNodesModel.addElement(tnw);
                name.append(separator);
                buildNodesModel(cur, name.toString(), level + 1);
            } else if (te instanceof TestPlan || te instanceof WorkBench) {
                name.append(cur.getName());
                name.append(separator);
                buildNodesModel(cur, name.toString(), 0);
            }
        // Ignore everything else
        }
    }
}
Also used : TestPlan(org.apache.jmeter.testelement.TestPlan) TreeNodeWrapper(org.apache.jmeter.control.gui.TreeNodeWrapper) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TestElement(org.apache.jmeter.testelement.TestElement) Controller(org.apache.jmeter.control.Controller) RecordingController(org.apache.jmeter.protocol.http.control.RecordingController) WorkBench(org.apache.jmeter.testelement.WorkBench)

Example 19 with TestPlan

use of org.apache.jmeter.testelement.TestPlan in project jmeter by apache.

the class TestValueReplacer method testReverseReplacementXml.

@Test
public void testReverseReplacementXml() throws Exception {
    ValueReplacer replacer = new ValueReplacer(variables);
    assertTrue(variables.getUserDefinedVariables().containsKey("bounded_regex"));
    assertTrue(variables.getUserDefinedVariables().containsKey("normal_regex"));
    assertTrue(replacer.containsKey("bounded_regex"));
    assertTrue(replacer.containsKey("normal_regex"));
    TestElement element = new TestPlan();
    element.setProperty(new StringProperty("domain", "<this><is>xml</this></is>"));
    List<Object> argsin = new ArrayList<>();
    argsin.add("<this><is>xml</this></is>");
    argsin.add("And I say: Hello World.");
    element.setProperty(new CollectionProperty("args", argsin));
    replacer.reverseReplace(element, true);
    @SuppressWarnings("unchecked") List<JMeterProperty> args = (List<JMeterProperty>) element.getProperty("args").getObjectValue();
    assertEquals("${bounded_regex}", element.getPropertyAsString("domain"));
    assertEquals("${bounded_regex}", args.get(0).getStringValue());
}
Also used : CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) TestPlan(org.apache.jmeter.testelement.TestPlan) ArrayList(java.util.ArrayList) StringProperty(org.apache.jmeter.testelement.property.StringProperty) ArrayList(java.util.ArrayList) List(java.util.List) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) TestElement(org.apache.jmeter.testelement.TestElement) Test(org.junit.Test)

Example 20 with TestPlan

use of org.apache.jmeter.testelement.TestPlan in project jmeter by apache.

the class PreCompiler method addNode.

/** {@inheritDoc} */
@Override
public void addNode(Object node, HashTree subTree) {
    if (isRemote && node instanceof ResultCollector) {
        try {
            replacer.replaceValues((TestElement) node);
        } catch (InvalidVariableException e) {
            log.error("invalid variables", e);
        }
    }
    if (isRemote) {
        return;
    }
    if (node instanceof TestElement) {
        try {
            replacer.replaceValues((TestElement) node);
        } catch (InvalidVariableException e) {
            log.error("invalid variables", e);
        }
    }
    if (node instanceof TestPlan) {
        //A hack to make user-defined variables in the testplan element more dynamic
        ((TestPlan) node).prepareForPreCompile();
        Map<String, String> args = ((TestPlan) node).getUserDefinedVariables();
        replacer.setUserDefinedVariables(args);
        JMeterVariables vars = new JMeterVariables();
        vars.putAll(args);
        JMeterContextService.getContext().setVariables(vars);
    }
    if (node instanceof Arguments) {
        ((Arguments) node).setRunningVersion(true);
        Map<String, String> args = ((Arguments) node).getArgumentsAsMap();
        replacer.addVariables(args);
        JMeterContextService.getContext().getVariables().putAll(args);
    }
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) InvalidVariableException(org.apache.jmeter.functions.InvalidVariableException) TestPlan(org.apache.jmeter.testelement.TestPlan) Arguments(org.apache.jmeter.config.Arguments) TestElement(org.apache.jmeter.testelement.TestElement) ResultCollector(org.apache.jmeter.reporters.ResultCollector)

Aggregations

TestPlan (org.apache.jmeter.testelement.TestPlan)23 TestElement (org.apache.jmeter.testelement.TestElement)12 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)7 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)6 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)6 ValueReplacer (org.apache.jmeter.engine.util.ValueReplacer)5 WorkBench (org.apache.jmeter.testelement.WorkBench)4 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)4 StringProperty (org.apache.jmeter.testelement.property.StringProperty)4 Test (org.junit.Test)4 Arguments (org.apache.jmeter.config.Arguments)3 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)3 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Controller (org.apache.jmeter.control.Controller)2 InvalidVariableException (org.apache.jmeter.functions.InvalidVariableException)2 JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)2 HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)2 ResultCollector (org.apache.jmeter.reporters.ResultCollector)2