Search in sources :

Example 16 with JMeterTreeModel

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

the class ProxyControl method placeSampler.

private void placeSampler(final HTTPSamplerBase sampler, final TestElement[] testElements, JMeterTreeNode myTarget) {
    try {
        final JMeterTreeModel treeModel = getJmeterTreeModel();
        boolean firstInBatch = false;
        long now = System.currentTimeMillis();
        long deltaT = now - lastTime;
        int cachedGroupingMode = groupingMode;
        if (deltaT > SAMPLE_GAP) {
            if (!myTarget.isLeaf() && cachedGroupingMode == GROUPING_ADD_SEPARATORS) {
                addDivider(treeModel, myTarget);
            }
            if (cachedGroupingMode == GROUPING_IN_SIMPLE_CONTROLLERS) {
                addSimpleController(treeModel, myTarget, sampler.getName());
            }
            if (cachedGroupingMode == GROUPING_IN_TRANSACTION_CONTROLLERS) {
                addTransactionController(treeModel, myTarget, sampler.getName());
            }
            // Remember this was first in its batch
            firstInBatch = true;
        }
        if (lastTime == 0) {
            // Decent value for timers
            deltaT = 0;
        }
        lastTime = now;
        if (cachedGroupingMode == GROUPING_STORE_FIRST_ONLY) {
            if (!firstInBatch) {
                // Huh! don't store this one!
                return;
            }
            // If we're not storing subsequent samplers, we'll need the
            // first sampler to do all the work...:
            sampler.setFollowRedirects(true);
            sampler.setImageParser(true);
        }
        if (cachedGroupingMode == GROUPING_IN_SIMPLE_CONTROLLERS || cachedGroupingMode == GROUPING_IN_TRANSACTION_CONTROLLERS) {
            // sampler there:
            for (int i = myTarget.getChildCount() - 1; i >= 0; i--) {
                JMeterTreeNode c = (JMeterTreeNode) myTarget.getChildAt(i);
                if (c.getTestElement() instanceof GenericController) {
                    myTarget = c;
                    break;
                }
            }
        }
        final long deltaTFinal = deltaT;
        final boolean firstInBatchFinal = firstInBatch;
        final JMeterTreeNode myTargetFinal = myTarget;
        JMeterUtils.runSafe(true, () -> {
            try {
                final JMeterTreeNode newNode = treeModel.addComponent(sampler, myTargetFinal);
                if (firstInBatchFinal) {
                    if (addAssertions) {
                        addAssertion(treeModel, newNode);
                    }
                    addTimers(treeModel, newNode, deltaTFinal);
                }
                if (testElements != null) {
                    for (TestElement testElement : testElements) {
                        if (isAddableTestElement(testElement)) {
                            treeModel.addComponent(testElement, newNode);
                        }
                    }
                }
            } catch (IllegalUserActionException e) {
                log.error("Error placing sampler", e);
                JMeterUtils.reportErrorToUser(e.getMessage());
            }
        });
    } catch (Exception e) {
        log.error("Error placing sampler", e);
        JMeterUtils.reportErrorToUser(e.getMessage());
    }
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) GenericController(org.apache.jmeter.control.GenericController) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) CertificateExpiredException(java.security.cert.CertificateExpiredException) GeneralSecurityException(java.security.GeneralSecurityException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedCachePatternException(org.apache.oro.text.MalformedCachePatternException) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) InvalidVariableException(org.apache.jmeter.functions.InvalidVariableException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException)

Example 17 with JMeterTreeModel

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

the class RecordController method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == clearButton) {
        GuiPackage guiPackage = GuiPackage.getInstance();
        JMeterTreeNode currentNode = guiPackage.getTreeListener().getCurrentNode();
        if (!(currentNode.getUserObject() instanceof org.apache.jmeter.protocol.http.control.RecordingController)) {
            Toolkit.getDefaultToolkit().beep();
            return;
        }
        try {
            guiPackage.updateCurrentNode();
            JMeterTreeModel treeModel = guiPackage.getTreeModel();
            int childCount = currentNode.getChildCount();
            for (int i = 0; i < childCount; i++) {
                JMeterTreeNode node = (JMeterTreeNode) currentNode.getChildAt(0);
                treeModel.removeNodeFromParent(node);
            }
        } catch (Exception err) {
            Toolkit.getDefaultToolkit().beep();
            log.error("Error while removing recorded samples", err);
        }
    }
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) RecordingController(org.apache.jmeter.protocol.http.control.RecordingController)

Example 18 with JMeterTreeModel

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

the class UndoHistory method treeNodesChanged.

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

Example 19 with JMeterTreeModel

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

the class Duplicate method doAction.

@Override
public void doAction(ActionEvent e) {
    GuiPackage instance = GuiPackage.getInstance();
    JMeterTreeListener treeListener = instance.getTreeListener();
    JMeterTreeNode[] copiedNodes = Copy.cloneTreeNodes(treeListener.getSelectedNodes());
    JMeterTreeNode currentNode = treeListener.getCurrentNode();
    JMeterTreeNode parentNode = (JMeterTreeNode) currentNode.getParent();
    JMeterTreeModel treeModel = instance.getTreeModel();
    for (JMeterTreeNode copiedNode : copiedNodes) {
        int index = parentNode.getIndex(currentNode) + 1;
        treeModel.insertNodeInto(copiedNode, parentNode, index);
    }
    instance.getMainFrame().repaint();
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) GuiPackage(org.apache.jmeter.gui.GuiPackage) JMeterTreeListener(org.apache.jmeter.gui.tree.JMeterTreeListener) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

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