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