use of org.apache.jmeter.testelement.TestPlan 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.TestPlan in project jmeter by apache.
the class JMeterTreeModel method addSubTree.
/**
* Adds the sub tree at the given node. Returns a boolean indicating whether
* the added sub tree was a full test plan.
*
* @param subTree
* The {@link HashTree} which is to be inserted into
* <code>current</code>
* @param current
* The node in which the <code>subTree</code> is to be inserted.
* Will be overridden, when an instance of {@link TestPlan} or
* {@link WorkBench} is found in the subtree.
* @return newly created sub tree now found at <code>current</code>
* @throws IllegalUserActionException
* when <code>current</code> is not an instance of
* {@link AbstractConfigGui} and no instance of {@link TestPlan}
* or {@link WorkBench} could be found in the
* <code>subTree</code>
*/
public HashTree addSubTree(HashTree subTree, JMeterTreeNode current) throws IllegalUserActionException {
for (Object o : subTree.list()) {
TestElement item = (TestElement) o;
if (item instanceof TestPlan) {
TestPlan tp = (TestPlan) item;
current = (JMeterTreeNode) ((JMeterTreeNode) getRoot()).getChildAt(0);
final TestPlan userObject = (TestPlan) current.getUserObject();
userObject.addTestElement(item);
userObject.setName(item.getName());
userObject.setFunctionalMode(tp.isFunctionalMode());
userObject.setSerialized(tp.isSerialized());
addSubTree(subTree.getTree(item), current);
} else if (item instanceof WorkBench) {
current = (JMeterTreeNode) ((JMeterTreeNode) getRoot()).getChildAt(1);
final TestElement testElement = (TestElement) current.getUserObject();
testElement.addTestElement(item);
testElement.setName(item.getName());
addSubTree(subTree.getTree(item), current);
} else {
addSubTree(subTree.getTree(item), addComponent(item, current));
}
}
return getCurrentSubTree(current);
}
use of org.apache.jmeter.testelement.TestPlan in project jmeter by apache.
the class Load method insertLoadedTree.
/**
* Inserts (or merges) the tree into the GUI.
* Does not check if the previous tree has been saved.
* Clears the existing GUI test plan if we are inserting a complete plan.
* @param id the id for the ActionEvent that is created
* @param tree the tree to load
* @param merging true if the tree is to be merged; false if it is to replace the existing tree
* @return true if the loaded tree was a full test plan
* @throws IllegalUserActionException if the tree cannot be merged at the selected position or the tree is empty
*/
// Does not appear to be used externally; called by #loadProjectFile()
public static boolean insertLoadedTree(final int id, final HashTree tree, final boolean merging) throws IllegalUserActionException {
if (tree == null) {
throw new IllegalUserActionException("Empty TestPlan or error reading test plan - see log file");
}
final boolean isTestPlan = tree.getArray()[0] instanceof TestPlan;
// If we are loading a new test plan, initialize the tree with the testplan node we are loading
final GuiPackage guiInstance = GuiPackage.getInstance();
if (isTestPlan && !merging) {
// Why does this not call guiInstance.clearTestPlan() ?
// Is there a reason for not clearing everything?
guiInstance.clearTestPlan((TestElement) tree.getArray()[0]);
}
if (merging) {
// Check if target of merge is reasonable
final TestElement te = (TestElement) tree.getArray()[0];
if (!(te instanceof WorkBench || te instanceof TestPlan)) {
// These are handled specially by addToTree
final boolean ok = MenuFactory.canAddTo(guiInstance.getCurrentNode(), te);
if (!ok) {
String name = te.getName();
String className = te.getClass().getName();
className = className.substring(className.lastIndexOf('.') + 1);
throw new IllegalUserActionException("Can't merge " + name + " (" + className + ") here");
}
}
}
final HashTree newTree = guiInstance.addSubTree(tree);
guiInstance.updateCurrentGui();
guiInstance.getMainFrame().getTree().setSelectionPath(new TreePath(((JMeterTreeNode) newTree.getArray()[0]).getPath()));
final HashTree subTree = guiInstance.getCurrentSubTree();
// Send different event wether we are merging a test plan into another test plan,
// or loading a testplan from scratch
ActionEvent actionEvent = new ActionEvent(subTree.get(subTree.getArray()[subTree.size() - 1]), id, merging ? ActionNames.SUB_TREE_MERGED : ActionNames.SUB_TREE_LOADED);
ActionRouter.getInstance().actionPerformed(actionEvent);
final JTree jTree = guiInstance.getMainFrame().getTree();
if (EXPAND_TREE && !merging) {
// don't automatically expand when merging
for (int i = 0; i < jTree.getRowCount(); i++) {
jTree.expandRow(i);
}
} else {
jTree.expandRow(0);
}
jTree.setSelectionPath(jTree.getPathForRow(1));
FocusRequester.requestFocus(jTree);
return isTestPlan;
}
use of org.apache.jmeter.testelement.TestPlan in project jmeter by apache.
the class TestPlanGui method configure.
/**
* A newly created component can be initialized with the contents of a Test
* Element object by calling this method. The component is responsible for
* querying the Test Element object for the relevant information to display
* in its GUI.
*
* @param el
* the TestElement to configure
*/
@Override
public void configure(TestElement el) {
super.configure(el);
if (el instanceof TestPlan) {
TestPlan tp = (TestPlan) el;
functionalMode.setSelected(tp.isFunctionalMode());
serializedMode.setSelected(tp.isSerialized());
tearDownOnShutdown.setSelected(tp.isTearDownOnShutdown());
final JMeterProperty udv = tp.getUserDefinedVariablesAsProperty();
if (udv != null) {
argsPanel.configure((Arguments) udv.getObjectValue());
}
browseJar.setFiles(tp.getTestPlanClasspathArray());
}
}
use of org.apache.jmeter.testelement.TestPlan in project jmeter by apache.
the class ProxyControl method addTimers.
/**
* Helper method to replicate any timers found within the Proxy Controller
* into the provided sampler, while replacing any occurrences of string _T_
* in the timer's configuration with the provided deltaT.
* Called from AWT Event thread
* @param model
* Test component tree model
* @param node
* Sampler node in where we will add the timers
* @param deltaT
* Time interval from the previous request
*/
private void addTimers(JMeterTreeModel model, JMeterTreeNode node, long deltaT) {
TestPlan variables = new TestPlan();
// $NON-NLS-1$
variables.addParameter("T", Long.toString(deltaT));
ValueReplacer replacer = new ValueReplacer(variables);
JMeterTreeNode mySelf = model.getNodeOf(this);
Enumeration<JMeterTreeNode> children = mySelf.children();
while (children.hasMoreElements()) {
JMeterTreeNode templateNode = children.nextElement();
if (templateNode.isEnabled()) {
TestElement template = templateNode.getTestElement();
if (template instanceof Timer) {
TestElement timer = (TestElement) template.clone();
try {
timer.setComment("Recorded:" + Long.toString(deltaT) + "ms");
replacer.undoReverseReplace(timer);
model.addComponent(timer, node);
} catch (InvalidVariableException | IllegalUserActionException e) {
// Not 100% sure, but I believe this can't happen, so
// I'll log and throw an error:
log.error("Program error", e);
throw new Error(e);
}
}
}
}
}
Aggregations