use of org.apache.jmeter.testelement.TestElement 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.TestElement 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.TestElement in project jmeter by apache.
the class GenericController method next.
/**
* <p>
* Determines the next sampler to be processed.
* </p>
*
* <p>
* If {@link #isDone()} is <code>true</code>, returns null.
* </p>
*
* <p>
* Gets the list element using current pointer.
* If this is <code>null</code>, calls {@link #nextIsNull()}.
* </p>
*
* <p>
* If the list element is a {@link Sampler}, calls {@link #nextIsASampler(Sampler)},
* otherwise calls {@link #nextIsAController(Controller)}
* </p>
*
* <p>
* If any of the called methods throws {@link NextIsNullException}, returns <code>null</code>,
* otherwise the value obtained above is returned.
* </p>
*
* @return the next sampler or <code>null</code>
*/
@Override
public Sampler next() {
fireIterEvents();
log.debug("Calling next on: {}", GenericController.class);
if (isDone()) {
return null;
}
Sampler returnValue = null;
try {
TestElement currentElement = getCurrentElement();
setCurrentElement(currentElement);
if (currentElement == null) {
returnValue = nextIsNull();
} else {
if (currentElement instanceof Sampler) {
returnValue = nextIsASampler((Sampler) currentElement);
} else {
// must be a controller
returnValue = nextIsAController((Controller) currentElement);
}
}
} catch (NextIsNullException e) {
// NOOP
}
return returnValue;
}
use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.
the class TestBeanHelper method unwrapProperty.
private static Object unwrapProperty(PropertyDescriptor desc, JMeterProperty jprop, Class<?> type) {
Object value;
if (jprop instanceof TestElementProperty) {
TestElement te = ((TestElementProperty) jprop).getElement();
if (te instanceof TestBean) {
prepare(te);
}
value = te;
} else if (jprop instanceof MultiProperty) {
value = unwrapCollection((MultiProperty) jprop, (String) desc.getValue(TableEditor.CLASSNAME));
} else // value was not provided, and this is allowed
if (jprop instanceof NullProperty && // use negative condition so missing (null) value is treated as FALSE
!Boolean.TRUE.equals(desc.getValue(GenericTestBeanCustomizer.NOT_UNDEFINED))) {
value = null;
} else {
value = Converter.convert(jprop.getStringValue(), type);
}
return value;
}
use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.
the class TestBeanGUI method createTestElement.
/**
* {@inheritDoc}
*/
@Override
public TestElement createTestElement() {
try {
TestElement element = (TestElement) testBeanClass.newInstance();
// otherwise we will get values as computed by customizer reset and not default ones
if (initialized) {
setValues(element);
}
// configure(element);
// super.clear(); // set name, enabled.
// put the default values back into the
modifyTestElement(element);
// new element
return element;
} catch (InstantiationException | IllegalAccessException e) {
log.error("Can't create test element", e);
// Programming error. Don't
throw new Error(e.toString());
// continue.
}
}
Aggregations