Search in sources :

Example 61 with TestElement

use of org.apache.jmeter.testelement.TestElement 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 62 with TestElement

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

the class TestThroughputController method testByPercent100.

@Test
public void testByPercent100() throws Exception {
    ThroughputController sub_1 = new ThroughputController();
    sub_1.setStyle(ThroughputController.BYPERCENT);
    sub_1.setPercentThroughput(100.0f);
    sub_1.addTestElement(new TestSampler("one"));
    sub_1.addTestElement(new TestSampler("two"));
    LoopController controller = new LoopController();
    controller.setLoops(150);
    controller.addTestElement(new TestSampler("zero"));
    controller.addTestElement(sub_1);
    controller.addIterationListener(sub_1);
    controller.addTestElement(new TestSampler("three"));
    String[] order = new String[] { "zero", "one", "two", "three" };
    int counter = 0;
    controller.setRunningVersion(true);
    sub_1.setRunningVersion(true);
    sub_1.testStarted();
    controller.initialize();
    for (int i = 0; i < 3; i++) {
        TestElement sampler = null;
        while ((sampler = controller.next()) != null) {
            assertEquals("Counter: " + counter + ", i: " + i, order[counter % order.length], sampler.getName());
            counter++;
        }
        assertEquals(counter, 150 * order.length);
        counter = 0;
    }
    sub_1.testEnded();
}
Also used : TestSampler(org.apache.jmeter.junit.stubs.TestSampler) TestElement(org.apache.jmeter.testelement.TestElement) Test(org.junit.Test)

Example 63 with TestElement

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

the class TestThroughputController method testByPercentZero.

@Test
public void testByPercentZero() throws Exception {
    ThroughputController sub_1 = new ThroughputController();
    sub_1.setStyle(ThroughputController.BYPERCENT);
    sub_1.setPercentThroughput(0.0f);
    sub_1.addTestElement(new TestSampler("one"));
    sub_1.addTestElement(new TestSampler("two"));
    LoopController controller = new LoopController();
    controller.setLoops(150);
    controller.addTestElement(new TestSampler("zero"));
    controller.addTestElement(sub_1);
    controller.addIterationListener(sub_1);
    controller.addTestElement(new TestSampler("three"));
    String[] order = new String[] { "zero", "three" };
    int counter = 0;
    controller.setRunningVersion(true);
    sub_1.setRunningVersion(true);
    sub_1.testStarted();
    controller.initialize();
    for (int i = 0; i < 3; i++) {
        TestElement sampler = null;
        while ((sampler = controller.next()) != null) {
            assertEquals("Counter: " + counter + ", i: " + i, order[counter % order.length], sampler.getName());
            counter++;
        }
        assertEquals(counter, 150 * order.length);
        counter = 0;
    }
    sub_1.testEnded();
}
Also used : TestSampler(org.apache.jmeter.junit.stubs.TestSampler) TestElement(org.apache.jmeter.testelement.TestElement) Test(org.junit.Test)

Example 64 with TestElement

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

the class PropertyControlGui method createTestElement.

@Override
public TestElement createTestElement() {
    TestElement el = new ConfigTestElement();
    modifyTestElement(el);
    return el;
}
Also used : TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement)

Example 65 with TestElement

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

the class JMeter method convertSubTree.

/**
     * Remove disabled elements
     * Replace the ReplaceableController with the target subtree
     *
     * @param tree The {@link HashTree} to convert
     */
public static void convertSubTree(HashTree tree) {
    LinkedList<Object> copyList = new LinkedList<>(tree.list());
    for (Object o : copyList) {
        if (o instanceof TestElement) {
            TestElement item = (TestElement) o;
            if (item.isEnabled()) {
                if (item instanceof ReplaceableController) {
                    ReplaceableController rc = ensureReplaceableControllerIsLoaded(item);
                    HashTree subTree = tree.getTree(item);
                    if (subTree != null) {
                        HashTree replacementTree = rc.getReplacementSubTree();
                        if (replacementTree != null) {
                            convertSubTree(replacementTree);
                            tree.replaceKey(item, rc);
                            tree.set(rc, replacementTree);
                        }
                    }
                } else {
                    // not Replaceable Controller
                    convertSubTree(tree.getTree(item));
                }
            } else {
                // Not enabled
                tree.remove(item);
            }
        } else {
            // Not a TestElement
            JMeterTreeNode item = (JMeterTreeNode) o;
            if (item.isEnabled()) {
                // @see StandardJMeterEngine.run()
                if (item.getUserObject() instanceof ReplaceableController) {
                    TestElement controllerAsItem = item.getTestElement();
                    ReplaceableController rc = ensureReplaceableControllerIsLoaded(controllerAsItem);
                    HashTree subTree = tree.getTree(item);
                    if (subTree != null) {
                        HashTree replacementTree = rc.getReplacementSubTree();
                        if (replacementTree != null) {
                            convertSubTree(replacementTree);
                            tree.replaceKey(item, rc);
                            tree.set(rc, replacementTree);
                        }
                    }
                } else {
                    // Not a ReplaceableController
                    convertSubTree(tree.getTree(item));
                    TestElement testElement = item.getTestElement();
                    tree.replaceKey(item, testElement);
                }
            } else {
                // Not enabled
                tree.remove(item);
            }
        }
    }
}
Also used : HashTree(org.apache.jorphan.collections.HashTree) ReplaceableController(org.apache.jmeter.control.ReplaceableController) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TestElement(org.apache.jmeter.testelement.TestElement) RemoteThreadsListenerTestElement(org.apache.jmeter.threads.RemoteThreadsListenerTestElement) LinkedList(java.util.LinkedList)

Aggregations

TestElement (org.apache.jmeter.testelement.TestElement)83 Test (org.junit.Test)27 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)26 TestSampler (org.apache.jmeter.junit.stubs.TestSampler)21 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)18 TestPlan (org.apache.jmeter.testelement.TestPlan)12 ArrayList (java.util.ArrayList)9 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)9 StringProperty (org.apache.jmeter.testelement.property.StringProperty)7 Controller (org.apache.jmeter.control.Controller)6 JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)6 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)6 TreePath (javax.swing.tree.TreePath)5 GuiPackage (org.apache.jmeter.gui.GuiPackage)5 ActionEvent (java.awt.event.ActionEvent)4 IOException (java.io.IOException)4 LinkedList (java.util.LinkedList)4 Arguments (org.apache.jmeter.config.Arguments)4 WorkBench (org.apache.jmeter.testelement.WorkBench)4 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)4