Search in sources :

Example 1 with TestFragmentController

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

the class ModuleControllerGui method buildTreeNodeModel.

/**
 * Recursively build module to run tree. <br/>
 * Only 4 types of elements are allowed to be added:
 * <ul>
 *  <li>All controllers except ModuleController</li>
 *  <li>TestPlan</li>
 *  <li>TestFragmentController</li>
 *  <li>AbstractThreadGroup</li>
 * </ul>
 * @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 TestFragmentController || te instanceof AbstractThreadGroup || (te instanceof Controller && !(te instanceof ModuleController) && level > 0)) {
                DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(cur);
                parent.add(newNode);
                buildTreeNodeModel(cur, level + 1, newNode);
                final boolean isController = te instanceof Controller && !(te instanceof ModuleController || te instanceof AbstractThreadGroup);
                hasAtLeastOneController = hasAtLeastOneController || isController;
            } 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 TestFragmentController

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

the class TestFragmentControllerGui method createTestElement.

/**
 * Implements JMeterGUIComponent.createTestElement()
 */
@Override
public TestElement createTestElement() {
    TestFragmentController controller = new TestFragmentController();
    setEnabled(false);
    modifyTestElement(controller);
    return controller;
}
Also used : TestFragmentController(org.apache.jmeter.control.TestFragmentController)

Example 3 with TestFragmentController

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

the class MenuFactory method canAddTo.

/**
 * Determine whether or not nodes can be added to this parent.
 * <p>
 * Used by DragNDrop and Paste.
 *
 * @param parentNode The {@link JMeterTreeNode} to test, if <code>nodes[]</code>
 *            can be added to it
 * @param nodes      array of nodes that are to be added
 * @return whether it is OK to add the dragged nodes to this parent
 */
public static boolean canAddTo(JMeterTreeNode parentNode, JMeterTreeNode[] nodes) {
    if (parentNode == null || foundClass(nodes, new Class[] { TestPlan.class })) {
        return false;
    }
    TestElement parent = parentNode.getTestElement();
    // Force TestFragment to only be pastable under a Test Plan
    if (foundClass(nodes, new Class[] { TestFragmentController.class })) {
        return parent instanceof TestPlan;
    }
    // Cannot move Non-Test Elements from root of Test Plan or Test Fragment
    if (foundMenuCategories(nodes, NON_TEST_ELEMENTS) && !(parent instanceof TestPlan || parent instanceof TestFragmentController)) {
        return false;
    }
    if (parent instanceof TestPlan) {
        List<Class<?>> samplerAndController = Arrays.asList(Sampler.class, Controller.class);
        List<Class<?>> exceptions = Arrays.asList(AbstractThreadGroup.class, NonTestElement.class);
        return !foundClass(nodes, samplerAndController, exceptions);
    }
    // AbstractThreadGroup is only allowed under a TestPlan
    if (foundClass(nodes, new Class[] { AbstractThreadGroup.class })) {
        return false;
    }
    // Includes thread group; anything goes
    if (parent instanceof Controller) {
        return true;
    }
    // No Samplers and Controllers
    if (parent instanceof Sampler) {
        return !foundClass(nodes, new Class[] { Sampler.class, Controller.class });
    }
    // All other
    return false;
}
Also used : TestFragmentController(org.apache.jmeter.control.TestFragmentController) TestPlan(org.apache.jmeter.testelement.TestPlan) Sampler(org.apache.jmeter.samplers.Sampler) NonTestElement(org.apache.jmeter.testelement.NonTestElement) TestElement(org.apache.jmeter.testelement.TestElement) Controller(org.apache.jmeter.control.Controller) TestFragmentController(org.apache.jmeter.control.TestFragmentController)

Example 4 with TestFragmentController

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

the class JMeterTreeModel method moveWorkBenchToTestPlan.

/**
 * Move all Non-Test Elements from WorkBench to TestPlan root.
 * Other Test Elements will be move to WorkBench Test Fragment in TestPlan
 * @param current - TestPlan root
 * @param workbenchTree - WorkBench hash tree
 */
private void moveWorkBenchToTestPlan(JMeterTreeNode current, HashTree workbenchTree) throws IllegalUserActionException {
    Object[] workbenchTreeArray = workbenchTree.getArray();
    if (GuiPackage.getInstance() != null) {
        for (Object node : workbenchTreeArray) {
            if (isNonTestElement(node)) {
                HashTree subtree = workbenchTree.getTree(node);
                workbenchTree.remove(node);
                HashTree tree = new HashTree();
                tree.add(node);
                tree.add(node, subtree);
                ((TestElement) node).setProperty(TestElement.ENABLED, false);
                addSubTree(tree, current);
            }
        }
    }
    if (!workbenchTree.isEmpty()) {
        HashTree testFragmentTree = new HashTree();
        TestFragmentController testFragmentController = new TestFragmentController();
        testFragmentController.setProperty(TestElement.NAME, "WorkBench Test Fragment");
        testFragmentController.setProperty(TestElement.GUI_CLASS, TestFragmentControllerGui.class.getName());
        testFragmentController.setProperty(TestElement.ENABLED, false);
        testFragmentTree.add(testFragmentController);
        testFragmentTree.add(testFragmentController, workbenchTree);
        addSubTree(testFragmentTree, current);
    }
}
Also used : TestFragmentControllerGui(org.apache.jmeter.control.gui.TestFragmentControllerGui) HashTree(org.apache.jorphan.collections.HashTree) ListedHashTree(org.apache.jorphan.collections.ListedHashTree) TestFragmentController(org.apache.jmeter.control.TestFragmentController) TestElement(org.apache.jmeter.testelement.TestElement)

Aggregations

TestFragmentController (org.apache.jmeter.control.TestFragmentController)4 TestElement (org.apache.jmeter.testelement.TestElement)3 Controller (org.apache.jmeter.control.Controller)2 TestPlan (org.apache.jmeter.testelement.TestPlan)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 ModuleController (org.apache.jmeter.control.ModuleController)1 TestFragmentControllerGui (org.apache.jmeter.control.gui.TestFragmentControllerGui)1 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)1 Sampler (org.apache.jmeter.samplers.Sampler)1 NonTestElement (org.apache.jmeter.testelement.NonTestElement)1 AbstractThreadGroup (org.apache.jmeter.threads.AbstractThreadGroup)1 HashTree (org.apache.jorphan.collections.HashTree)1 ListedHashTree (org.apache.jorphan.collections.ListedHashTree)1