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