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());
}
}
}
}
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;
}
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;
}
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);
}
}
Aggregations