Search in sources :

Example 71 with TestElement

use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.

the class GuiPackage method createTestElement.

/**
     * Create a TestElement for a GUI or TestBean class.
     * <p>
     * This is a utility method to help actions do with one single String
     * parameter.
     *
     * @param objClass
     *            the fully qualified class name of the GUI component or of the
     *            TestBean subclass for which a TestBeanGUI is wanted.
     * @return the test element corresponding to the specified GUI class.
     */
public TestElement createTestElement(String objClass) {
    JMeterGUIComponent comp;
    Class<?> c;
    try {
        c = Class.forName(objClass);
        if (TestBean.class.isAssignableFrom(c)) {
            comp = getGuiFromCache(TestBeanGUI.class, c);
        } else {
            comp = getGuiFromCache(c, null);
        }
        comp.clearGui();
        TestElement node = comp.createTestElement();
        nodesToGui.put(node, comp);
        return node;
    } catch (NoClassDefFoundError e) {
        log.error("Problem retrieving gui for " + objClass, e);
        String msg = "Cannot find class: " + e.getMessage();
        JOptionPane.showMessageDialog(null, msg, "Missing jar? See log file.", JOptionPane.ERROR_MESSAGE);
        // Probably a missing jar
        throw new RuntimeException(e.toString(), e);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        log.error("Problem retrieving gui for " + objClass, e);
        // Programming error: bail out.
        throw new RuntimeException(e.toString(), e);
    }
}
Also used : TestBeanGUI(org.apache.jmeter.testbeans.gui.TestBeanGUI) TestElement(org.apache.jmeter.testelement.TestElement)

Example 72 with TestElement

use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.

the class AddToTree method doAction.

/**
     * Adds the specified class to the current node of the tree.
     */
@Override
public void doAction(ActionEvent e) {
    GuiPackage guiPackage = GuiPackage.getInstance();
    try {
        guiPackage.updateCurrentNode();
        TestElement testElement = guiPackage.createTestElement(((JComponent) e.getSource()).getName());
        JMeterTreeNode parentNode = guiPackage.getCurrentNode();
        JMeterTreeNode node = guiPackage.getTreeModel().addComponent(testElement, parentNode);
        guiPackage.getNamingPolicy().nameOnCreation(node);
        guiPackage.getMainFrame().getTree().setSelectionPath(new TreePath(node.getPath()));
    } catch (Exception err) {
        // $NON-NLS-1$
        log.error("Exception while adding a component to tree.", err);
        String msg = err.getMessage();
        if (msg == null) {
            msg = err.toString();
        }
        JMeterUtils.reportErrorToUser(msg);
    }
}
Also used : TreePath(javax.swing.tree.TreePath) GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TestElement(org.apache.jmeter.testelement.TestElement)

Example 73 with TestElement

use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.

the class AddParent method doAction.

@Override
public void doAction(ActionEvent e) {
    String name = ((Component) e.getSource()).getName();
    GuiPackage guiPackage = GuiPackage.getInstance();
    try {
        guiPackage.updateCurrentNode();
        TestElement controller = guiPackage.createTestElement(name);
        addParentToTree(controller);
    } catch (Exception err) {
        log.error("Exception while adding a TestElement.", err);
    }
}
Also used : GuiPackage(org.apache.jmeter.gui.GuiPackage) Component(java.awt.Component) TestElement(org.apache.jmeter.testelement.TestElement)

Example 74 with TestElement

use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.

the class GenerateTreeGui method addSimpleController.

/**
     * Helper method to add a Simple Controller to contain the elements.
     * Called from Application Thread that needs to update GUI (JMeterTreeModel)
     * @param model
     *            Test component tree model
     * @param node
     *            Node in the tree where we will add the Controller
     * @param name
     *            A name for the Controller
     * @return the new node
     */
private JMeterTreeNode addSimpleController(JMeterTreeModel model, JMeterTreeNode node, String name) {
    final TestElement sc = new GenericController();
    sc.setProperty(TestElement.GUI_CLASS, LOGIC_CONTROLLER_GUI);
    // Use old style
    sc.setProperty(TestElement.NAME, name);
    return addToTree(model, node, sc);
}
Also used : GenericController(org.apache.jmeter.control.GenericController) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement)

Example 75 with TestElement

use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.

the class GenerateTreeGui method addElements.

private void addElements(String menuKey, String title, GuiPackage guiPackage, JMeterTreeModel treeModel, JMeterTreeNode myTarget) {
    myTarget = addSimpleController(treeModel, myTarget, title);
    JPopupMenu jp = MenuFactory.makeMenu(menuKey, "").getPopupMenu();
    for (Component comp : jp.getComponents()) {
        JMenuItem jmi = (JMenuItem) comp;
        try {
            TestElement testElement = guiPackage.createTestElement(jmi.getName());
            addToTree(treeModel, myTarget, testElement);
        } catch (Exception e) {
            addSimpleController(treeModel, myTarget, jmi.getName() + " " + e.getMessage());
        }
    }
}
Also used : UnsharedComponent(org.apache.jmeter.gui.UnsharedComponent) Component(java.awt.Component) JMenuItem(javax.swing.JMenuItem) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) JPopupMenu(javax.swing.JPopupMenu) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

TestElement (org.apache.jmeter.testelement.TestElement)83 Test (org.junit.Test)27 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)26 TestSampler (org.apache.jmeter.junit.stubs.TestSampler)21 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)18 TestPlan (org.apache.jmeter.testelement.TestPlan)12 ArrayList (java.util.ArrayList)9 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)9 StringProperty (org.apache.jmeter.testelement.property.StringProperty)7 Controller (org.apache.jmeter.control.Controller)6 JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)6 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)6 TreePath (javax.swing.tree.TreePath)5 GuiPackage (org.apache.jmeter.gui.GuiPackage)5 ActionEvent (java.awt.event.ActionEvent)4 IOException (java.io.IOException)4 LinkedList (java.util.LinkedList)4 Arguments (org.apache.jmeter.config.Arguments)4 WorkBench (org.apache.jmeter.testelement.WorkBench)4 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)4