Search in sources :

Example 6 with JMeterTreeModel

use of org.apache.jmeter.gui.tree.JMeterTreeModel in project jmeter by apache.

the class ProxyControl method setAuthorization.

/**
     * Find if there is any AuthManager in JMeterTreeModel
     * If there is no one, create and add it to tree
     * Add authorization object to AuthManager
     * @param authorization {@link Authorization}
     * @param target {@link JMeterTreeNode}
     */
private void setAuthorization(Authorization authorization, JMeterTreeNode target) {
    JMeterTreeModel jmeterTreeModel = getJmeterTreeModel();
    List<JMeterTreeNode> authManagerNodes = jmeterTreeModel.getNodesOfType(AuthManager.class);
    if (authManagerNodes.isEmpty()) {
        try {
            log.debug("Creating HTTP Authentication manager for authorization:" + authorization);
            AuthManager authManager = newAuthorizationManager(authorization);
            jmeterTreeModel.addComponent(authManager, target);
        } catch (IllegalUserActionException e) {
            log.error("Failed to add Authorization Manager to target node:" + target.getName(), e);
        }
    } else {
        AuthManager authManager = (AuthManager) authManagerNodes.get(0).getTestElement();
        authManager.addAuth(authorization);
    }
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) AuthManager(org.apache.jmeter.protocol.http.control.AuthManager) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException)

Example 7 with JMeterTreeModel

use of org.apache.jmeter.gui.tree.JMeterTreeModel in project jmeter by apache.

the class ProxyControl method notifyTestListenersOfStart.

/**
     * This will notify test listeners directly within the Proxy that the 'test'
     * (here meaning the proxy recording) has started.
     */
private void notifyTestListenersOfStart() {
    JMeterTreeModel treeModel = getJmeterTreeModel();
    JMeterTreeNode myNode = treeModel.getNodeOf(this);
    Enumeration<JMeterTreeNode> kids = myNode.children();
    while (kids.hasMoreElements()) {
        JMeterTreeNode subNode = kids.nextElement();
        if (subNode.isEnabled()) {
            TestElement testElement = subNode.getTestElement();
            if (testElement instanceof TestStateListener) {
                ((TestStateListener) testElement).testStarted();
            }
        }
    }
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TestStateListener(org.apache.jmeter.testelement.TestStateListener) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement)

Example 8 with JMeterTreeModel

use of org.apache.jmeter.gui.tree.JMeterTreeModel in project jmeter by apache.

the class GenerateTreeGui method actionPerformed.

@Override
public void actionPerformed(ActionEvent action) {
    GuiPackage guiPackage = GuiPackage.getInstance();
    JMeterTreeModel treeModel = guiPackage.getTreeModel();
    JMeterTreeNode myTarget = findFirstNodeOfType(org.apache.jmeter.threads.ThreadGroup.class, treeModel);
    if (myTarget == null) {
        JMeterUtils.reportErrorToUser("Cannot find Thread Group");
        return;
    }
    addElements(MenuFactory.CONTROLLERS, "Controllers", guiPackage, treeModel, myTarget);
    addElements(MenuFactory.CONFIG_ELEMENTS, "Config Elements", guiPackage, treeModel, myTarget);
    addElements(MenuFactory.TIMERS, "Timers", guiPackage, treeModel, myTarget);
    addElements(MenuFactory.PRE_PROCESSORS, "Pre Processors", guiPackage, treeModel, myTarget);
    addElements(MenuFactory.SAMPLERS, "Samplers", guiPackage, treeModel, myTarget);
    addElements(MenuFactory.POST_PROCESSORS, "Post Processors", guiPackage, treeModel, myTarget);
    addElements(MenuFactory.ASSERTIONS, "Assertions", guiPackage, treeModel, myTarget);
    addElements(MenuFactory.LISTENERS, "Listeners", guiPackage, treeModel, myTarget);
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Example 9 with JMeterTreeModel

use of org.apache.jmeter.gui.tree.JMeterTreeModel in project jmeter by apache.

the class UndoHistory method treeNodesInserted.

/**
     * Record adding nodes as the undo step
     *
     * @param tme {@link TreeModelEvent} with event details
     */
@Override
public void treeNodesInserted(TreeModelEvent tme) {
    String name = ((JMeterTreeNode) tme.getTreePath().getLastPathComponent()).getName();
    log.debug("Nodes inserted {}", name);
    final JMeterTreeModel sender = (JMeterTreeModel) tme.getSource();
    add(sender, "Add " + name);
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Example 10 with JMeterTreeModel

use of org.apache.jmeter.gui.tree.JMeterTreeModel 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));
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TreeNode(javax.swing.tree.TreeNode) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) JMeterGUIComponent(org.apache.jmeter.gui.JMeterGUIComponent) Controller(org.apache.jmeter.control.Controller)

Aggregations

JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)19 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)18 GuiPackage (org.apache.jmeter.gui.GuiPackage)6 TestElement (org.apache.jmeter.testelement.TestElement)6 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)5 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)5 IOException (java.io.IOException)4 JTree (javax.swing.JTree)4 TreePath (javax.swing.tree.TreePath)4 ActionEvent (java.awt.event.ActionEvent)3 MalformedURLException (java.net.MalformedURLException)3 Searchable (org.apache.jmeter.gui.Searchable)3 ConversionException (com.thoughtworks.xstream.converters.ConversionException)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 SocketException (java.net.SocketException)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 JMeterTreeListener (org.apache.jmeter.gui.tree.JMeterTreeListener)2 ConfigurationException (org.apache.jmeter.report.config.ConfigurationException)2