Search in sources :

Example 1 with Controller

use of org.apache.jmeter.control.Controller 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 2 with Controller

use of org.apache.jmeter.control.Controller in project jmeter by apache.

the class AddThinkTimeBetweenEachStep method addThinkTimeToChildren.

/**
     * Add Think Time to children of parentNode
     * @param guiPackage {@link GuiPackage}
     * @param parentNode Parent node of elements on which we add think times
     * @throws IllegalUserActionException 
     */
private void addThinkTimeToChildren(GuiPackage guiPackage, JMeterTreeNode parentNode) throws IllegalUserActionException {
    guiPackage.updateCurrentNode();
    boolean insertThinkTime = false;
    try {
        int index = 0;
        while (true) {
            if (index == parentNode.getChildCount()) {
                index++;
                break;
            }
            JMeterTreeNode childNode = (JMeterTreeNode) parentNode.getChildAt(index);
            Object userObject = childNode.getUserObject();
            if (userObject instanceof Sampler || userObject instanceof Controller) {
                insertThinkTime = true;
            }
            if (insertThinkTime) {
                JMeterTreeNode[] nodes = createThinkTime(guiPackage, parentNode);
                if (nodes.length != 2) {
                    throw new IllegalArgumentException("Invalid Think Time, expected 2 nodes, got:" + nodes.length);
                }
                index++;
                addNodesToTreeHierachically(guiPackage, parentNode, nodes, index);
                insertThinkTime = false;
            }
            index++;
        }
    } catch (Exception ex) {
        throw new IllegalUserActionException("Cannot add think times", ex);
    }
}
Also used : Sampler(org.apache.jmeter.samplers.Sampler) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) Controller(org.apache.jmeter.control.Controller) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException)

Example 3 with Controller

use of org.apache.jmeter.control.Controller in project jmeter by apache.

the class AddThinkTimeBetweenEachStep method doAction.

@Override
public void doAction(ActionEvent e) {
    GuiPackage guiPackage = GuiPackage.getInstance();
    JMeterTreeNode currentNode = guiPackage.getTreeListener().getCurrentNode();
    if (!(currentNode.getUserObject() instanceof Controller || currentNode.getUserObject() instanceof ThreadGroup)) {
        Toolkit.getDefaultToolkit().beep();
        return;
    }
    try {
        addThinkTimeToChildren(guiPackage, currentNode);
    } catch (Exception err) {
        Toolkit.getDefaultToolkit().beep();
        log.error("Failed to add think times", err);
        JMeterUtils.reportErrorToUser("Failed to add think times", err);
    }
}
Also used : GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) ThreadGroup(org.apache.jmeter.threads.ThreadGroup) Controller(org.apache.jmeter.control.Controller) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException)

Example 4 with Controller

use of org.apache.jmeter.control.Controller in project jmeter by apache.

the class ApplyNamingConvention method doAction.

@Override
public void doAction(ActionEvent e) {
    GuiPackage guiPackage = GuiPackage.getInstance();
    JMeterTreeNode currentNode = guiPackage.getTreeListener().getCurrentNode();
    if (!(currentNode.getUserObject() instanceof Controller)) {
        Toolkit.getDefaultToolkit().beep();
        return;
    }
    try {
        applyNamingPolicyToCurrentNode(guiPackage, currentNode);
    } catch (Exception err) {
        Toolkit.getDefaultToolkit().beep();
        log.error("Failed to apply naming policy", err);
        JMeterUtils.reportErrorToUser("Failed to apply naming policy", err);
    }
}
Also used : GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) Controller(org.apache.jmeter.control.Controller)

Example 5 with Controller

use of org.apache.jmeter.control.Controller in project jmeter by apache.

the class ChangeParent method changeParent.

private void changeParent(TestElement newParent, GuiPackage guiPackage, JMeterTreeNode currentNode) {
    // keep the old name if it was not the default one
    Controller currentController = (Controller) currentNode.getUserObject();
    JMeterGUIComponent currentGui = guiPackage.getCurrentGui();
    String defaultName = JMeterUtils.getResString(currentGui.getLabelResource());
    if (StringUtils.isNotBlank(currentController.getName()) && !currentController.getName().equals(defaultName)) {
        newParent.setName(currentController.getName());
    }
    JMeterTreeModel treeModel = guiPackage.getTreeModel();
    JMeterTreeNode newNode = new JMeterTreeNode(newParent, treeModel);
    JMeterTreeNode parentNode = (JMeterTreeNode) currentNode.getParent();
    int index = parentNode.getIndex(currentNode);
    treeModel.insertNodeInto(newNode, parentNode, index);
    treeModel.removeNodeFromParent(currentNode);
    int childCount = currentNode.getChildCount();
    for (int i = 0; i < childCount; i++) {
        // Using index 0 is voluntary as child is removed in next step and added to new parent
        JMeterTreeNode node = (JMeterTreeNode) currentNode.getChildAt(0);
        treeModel.removeNodeFromParent(node);
        treeModel.insertNodeInto(node, newNode, newNode.getChildCount());
    }
    // select the node
    TreeNode[] nodes = treeModel.getPathToRoot(newNode);
    JTree tree = guiPackage.getTreeListener().getJTree();
    tree.setSelectionPath(new TreePath(nodes));
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TreeNode(javax.swing.tree.TreeNode) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) JMeterGUIComponent(org.apache.jmeter.gui.JMeterGUIComponent) Controller(org.apache.jmeter.control.Controller)

Aggregations

Controller (org.apache.jmeter.control.Controller)13 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)7 TestElement (org.apache.jmeter.testelement.TestElement)6 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)3 TransactionController (org.apache.jmeter.control.TransactionController)3 TransactionSampler (org.apache.jmeter.control.TransactionSampler)3 GuiPackage (org.apache.jmeter.gui.GuiPackage)3 Sampler (org.apache.jmeter.samplers.Sampler)3 LinkedList (java.util.LinkedList)2 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)2 JMeterGUIComponent (org.apache.jmeter.gui.JMeterGUIComponent)2 TestPlan (org.apache.jmeter.testelement.TestPlan)2 Component (java.awt.Component)1 ArrayList (java.util.ArrayList)1 JTree (javax.swing.JTree)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 TreeNode (javax.swing.tree.TreeNode)1 TreePath (javax.swing.tree.TreePath)1 Assertion (org.apache.jmeter.assertions.Assertion)1 LoopController (org.apache.jmeter.control.LoopController)1