Search in sources :

Example 1 with TestElement

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

the class SwitchController method scanControllerNames.

/**
     * @param sel controller name
     * @return index of controller named sel if present, otherwise index of default if found, otherwise {@link Integer#MAX_VALUE} 
     */
private int scanControllerNames(String sel) {
    int i = 0;
    int defaultPos = Integer.MAX_VALUE;
    for (TestElement el : getSubControllers()) {
        String name = el.getName();
        if (name.equals(sel)) {
            return i;
        }
        if (name.equalsIgnoreCase("default")) {
            //$NON-NLS-1$
            defaultPos = i;
        }
        i++;
    }
    return defaultPos;
}
Also used : TestElement(org.apache.jmeter.testelement.TestElement)

Example 2 with TestElement

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

the class ModuleControllerGui method buildTreeNodeModel.

/**
     * Recursively build module to run tree. Only 4 types of elements are allowed to be added:
     * - All controllers except ModuleController
     * - TestPlan
     * - TestFragmentController
     * - AbstractThreadGroup
     * 
     * @param node - element of test plan tree
     * @param level - level of element in a tree
     * @param parent
     */
private void buildTreeNodeModel(JMeterTreeNode node, int level, DefaultMutableTreeNode parent) {
    if (node != null) {
        for (int i = 0; i < node.getChildCount(); i++) {
            JMeterTreeNode cur = (JMeterTreeNode) node.getChildAt(i);
            TestElement te = cur.getTestElement();
            if (te instanceof Controller && !(te instanceof ModuleController) && level > 0) {
                DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(cur);
                parent.add(newNode);
                buildTreeNodeModel(cur, level + 1, newNode);
            } else if (te instanceof TestFragmentController || te instanceof AbstractThreadGroup) {
                DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(cur);
                parent.add(newNode);
                buildTreeNodeModel(cur, level + 1, newNode);
            } else if (te instanceof TestPlan) {
                ((DefaultMutableTreeNode) moduleToRunTreeModel.getRoot()).setUserObject(cur);
                buildTreeNodeModel(cur, level, (DefaultMutableTreeNode) moduleToRunTreeModel.getRoot());
            }
        }
    }
}
Also used : TestFragmentController(org.apache.jmeter.control.TestFragmentController) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TestPlan(org.apache.jmeter.testelement.TestPlan) AbstractThreadGroup(org.apache.jmeter.threads.AbstractThreadGroup) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TestElement(org.apache.jmeter.testelement.TestElement) ModuleController(org.apache.jmeter.control.ModuleController) Controller(org.apache.jmeter.control.Controller) TestFragmentController(org.apache.jmeter.control.TestFragmentController) ModuleController(org.apache.jmeter.control.ModuleController)

Example 3 with TestElement

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

the class Save method convertSubTree.

// package protected to allow access from test code
void convertSubTree(HashTree tree) {
    for (Object o : new LinkedList<>(tree.list())) {
        JMeterTreeNode item = (JMeterTreeNode) o;
        convertSubTree(tree.getTree(item));
        // requires JMeterTreeNode
        TestElement testElement = item.getTestElement();
        tree.replaceKey(item, testElement);
    }
}
Also used : JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TestElement(org.apache.jmeter.testelement.TestElement) LinkedList(java.util.LinkedList)

Example 4 with TestElement

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

the class Start method removeThreadGroupsFromHashTree.

/**
     * Remove thread groups from testTree that are not in threadGroupsToKeep
     * @param testTree {@link HashTree}
     * @param threadGroupsToKeep Array of {@link AbstractThreadGroup} to keep
     */
private void removeThreadGroupsFromHashTree(HashTree testTree, AbstractThreadGroup[] threadGroupsToKeep) {
    LinkedList<Object> copyList = new LinkedList<>(testTree.list());
    for (Object o : copyList) {
        TestElement item = (TestElement) o;
        if (o instanceof AbstractThreadGroup) {
            if (!isInThreadGroups(item, threadGroupsToKeep)) {
                // where 2 AbstractTestElement can be equals but have different hashcode
                try {
                    item.setEnabled(false);
                    testTree.remove(item);
                } finally {
                    item.setEnabled(true);
                }
            } else {
                removeThreadGroupsFromHashTree(testTree.getTree(item), threadGroupsToKeep);
            }
        } else {
            removeThreadGroupsFromHashTree(testTree.getTree(item), threadGroupsToKeep);
        }
    }
}
Also used : AbstractThreadGroup(org.apache.jmeter.threads.AbstractThreadGroup) TestElement(org.apache.jmeter.testelement.TestElement) LinkedList(java.util.LinkedList)

Example 5 with TestElement

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

the class Remove method removeNode.

private static void removeNode(JMeterTreeNode node) {
    TestElement testElement = node.getTestElement();
    if (testElement.canRemove()) {
        GuiPackage.getInstance().getTreeModel().removeNodeFromParent(node);
        GuiPackage.getInstance().removeNode(testElement);
    } else {
        String message = testElement.getClass().getName() + " is busy";
        JOptionPane.showMessageDialog(null, message, "Cannot remove item", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : TestElement(org.apache.jmeter.testelement.TestElement)

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