Search in sources :

Example 76 with TestElement

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

Example 77 with TestElement

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

the class SimpleConfigGui method createTestElement.

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

Example 78 with TestElement

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

the class TestCompiler method trackIterationListeners.

private void trackIterationListeners(LinkedList<TestElement> pStack) {
    TestElement child = pStack.getLast();
    if (child instanceof LoopIterationListener) {
        ListIterator<TestElement> iter = pStack.listIterator(pStack.size());
        while (iter.hasPrevious()) {
            TestElement item = iter.previous();
            if (item == child) {
                continue;
            }
            if (item instanceof Controller) {
                TestBeanHelper.prepare(child);
                ((Controller) item).addIterationListener((LoopIterationListener) child);
                break;
            }
        }
    }
}
Also used : LoopIterationListener(org.apache.jmeter.engine.event.LoopIterationListener) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) Controller(org.apache.jmeter.control.Controller) TransactionController(org.apache.jmeter.control.TransactionController)

Example 79 with TestElement

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

the class TestInterleaveControl method testProcessing4.

@Test
public void testProcessing4() throws Exception {
    testLog.debug("Testing Interleave Controller 4");
    GenericController controller = new GenericController();
    InterleaveControl sub_1 = new InterleaveControl();
    sub_1.setStyle(InterleaveControl.IGNORE_SUB_CONTROLLERS);
    controller.addTestElement(sub_1);
    GenericController sub_2 = new GenericController();
    sub_2.addTestElement(new TestSampler("one"));
    sub_2.addTestElement(new TestSampler("two"));
    sub_1.addTestElement(sub_2);
    GenericController sub_3 = new GenericController();
    sub_3.addTestElement(new TestSampler("three"));
    sub_3.addTestElement(new TestSampler("four"));
    sub_1.addTestElement(sub_3);
    String[] order = new String[] { "one", "three", "two", "four" };
    int counter = 0;
    controller.setRunningVersion(true);
    sub_1.setRunningVersion(true);
    sub_2.setRunningVersion(true);
    sub_3.setRunningVersion(true);
    controller.initialize();
    while (counter < order.length) {
        TestElement sampler = null;
        while ((sampler = controller.next()) != null) {
            assertEquals("failed on" + counter, order[counter], sampler.getName());
            counter++;
        }
    }
}
Also used : TestSampler(org.apache.jmeter.junit.stubs.TestSampler) TestElement(org.apache.jmeter.testelement.TestElement) Test(org.junit.Test)

Example 80 with TestElement

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

the class TestInterleaveControl method testProcessing2.

@Test
public void testProcessing2() throws Exception {
    testLog.debug("Testing Interleave Controller 2");
    GenericController controller = new GenericController();
    InterleaveControl sub_1 = new InterleaveControl();
    sub_1.setStyle(InterleaveControl.IGNORE_SUB_CONTROLLERS);
    sub_1.addTestElement(new TestSampler("one"));
    sub_1.addTestElement(new TestSampler("two"));
    controller.addTestElement(sub_1);
    controller.addTestElement(new TestSampler("three"));
    LoopController sub_2 = new LoopController();
    sub_2.setLoops(3);
    GenericController sub_3 = new GenericController();
    sub_2.addTestElement(new TestSampler("four"));
    sub_3.addTestElement(new TestSampler("five"));
    sub_3.addTestElement(new TestSampler("six"));
    sub_2.addTestElement(sub_3);
    sub_2.addTestElement(new TestSampler("seven"));
    sub_1.addTestElement(sub_2);
    String[] order = new String[] { "one", "three", "two", "three", "four", "three", "one", "three", "two", "three", "five", "three", "one", "three", "two", "three", "six", "three", "one", "three" };
    int counter = 0;
    controller.setRunningVersion(true);
    sub_1.setRunningVersion(true);
    sub_2.setRunningVersion(true);
    sub_3.setRunningVersion(true);
    controller.initialize();
    while (counter < order.length) {
        TestElement sampler = null;
        while ((sampler = controller.next()) != null) {
            assertEquals("failed on " + counter, order[counter], sampler.getName());
            counter++;
        }
    }
}
Also used : TestSampler(org.apache.jmeter.junit.stubs.TestSampler) TestElement(org.apache.jmeter.testelement.TestElement) Test(org.junit.Test)

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