Search in sources :

Example 86 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter by apache.

the class ViewResultsFullVisualizer method updateGui.

/**
 * Update the visualizer with new data.
 */
private void updateGui() {
    TreePath selectedPath = null;
    Object oldSelectedElement;
    Set<Object> oldExpandedElements;
    Set<TreePath> newExpandedPaths = new HashSet<>();
    synchronized (buffer) {
        if (!dataChanged) {
            return;
        }
        final Enumeration<TreePath> expandedElements = jTree.getExpandedDescendants(new TreePath(root));
        oldExpandedElements = extractExpandedObjects(expandedElements);
        oldSelectedElement = getSelectedObject();
        root.removeAllChildren();
        for (SampleResult sampler : buffer) {
            SampleResult res = sampler;
            // Add sample
            DefaultMutableTreeNode currNode = new SearchableTreeNode(res, treeModel);
            treeModel.insertNodeInto(currNode, root, root.getChildCount());
            List<TreeNode> path = new ArrayList<>(Arrays.asList(root, currNode));
            selectedPath = checkExpandedOrSelected(path, res, oldSelectedElement, oldExpandedElements, newExpandedPaths, selectedPath);
            TreePath potentialSelection = addSubResults(currNode, res, path, oldSelectedElement, oldExpandedElements, newExpandedPaths);
            if (potentialSelection != null) {
                selectedPath = potentialSelection;
            }
            // Add any assertion that failed as children of the sample node
            AssertionResult[] assertionResults = res.getAssertionResults();
            int assertionIndex = currNode.getChildCount();
            for (AssertionResult assertionResult : assertionResults) {
                if (assertionResult.isFailure() || assertionResult.isError()) {
                    DefaultMutableTreeNode assertionNode = new SearchableTreeNode(assertionResult, treeModel);
                    treeModel.insertNodeInto(assertionNode, currNode, assertionIndex++);
                    selectedPath = checkExpandedOrSelected(path, assertionResult, oldSelectedElement, oldExpandedElements, newExpandedPaths, selectedPath, assertionNode);
                }
            }
        }
        treeModel.nodeStructureChanged(root);
        dataChanged = false;
    }
    if (root.getChildCount() == 1) {
        jTree.expandPath(new TreePath(root));
    }
    newExpandedPaths.stream().forEach(jTree::expandPath);
    if (selectedPath != null) {
        jTree.setSelectionPath(selectedPath);
    }
    if (autoScrollCB.isSelected() && root.getChildCount() > 1) {
        jTree.scrollPathToVisible(new TreePath(new Object[] { root, treeModel.getChild(root, root.getChildCount() - 1) }));
    }
}
Also used : AssertionResult(org.apache.jmeter.assertions.AssertionResult) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) SampleResult(org.apache.jmeter.samplers.SampleResult) HashSet(java.util.HashSet)

Example 87 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter by apache.

the class ViewResultsFullVisualizer method addSubResults.

private TreePath addSubResults(DefaultMutableTreeNode currNode, SampleResult res, List<TreeNode> path, Object selectedObject, Set<Object> oldExpandedObjects, Set<TreePath> newExpandedPaths) {
    SampleResult[] subResults = res.getSubResults();
    int leafIndex = 0;
    TreePath result = null;
    for (SampleResult child : subResults) {
        log.debug("updateGui1 : child sample result - {}", child);
        DefaultMutableTreeNode leafNode = new SearchableTreeNode(child, treeModel);
        treeModel.insertNodeInto(leafNode, currNode, leafIndex++);
        List<TreeNode> newPath = new ArrayList<>(path);
        newPath.add(leafNode);
        result = checkExpandedOrSelected(newPath, child, selectedObject, oldExpandedObjects, newExpandedPaths, result);
        addSubResults(leafNode, child, newPath, selectedObject, oldExpandedObjects, newExpandedPaths);
        // Add any assertion that failed as children of the sample node
        AssertionResult[] assertionResults = child.getAssertionResults();
        int assertionIndex = leafNode.getChildCount();
        for (AssertionResult item : assertionResults) {
            if (item.isFailure() || item.isError()) {
                DefaultMutableTreeNode assertionNode = new SearchableTreeNode(item, treeModel);
                treeModel.insertNodeInto(assertionNode, leafNode, assertionIndex++);
                result = checkExpandedOrSelected(path, item, selectedObject, oldExpandedObjects, newExpandedPaths, result, assertionNode);
            }
        }
    }
    return result;
}
Also used : AssertionResult(org.apache.jmeter.assertions.AssertionResult) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) ArrayList(java.util.ArrayList) SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 88 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter by apache.

the class SMIMEAssertionTest method setUp.

@BeforeEach
public void setUp() throws MessagingException, IOException {
    Session mailSession = Session.getDefaultInstance(new Properties());
    msg = new MimeMessage(mailSession, this.getClass().getResourceAsStream("signed_email.eml"));
    parent = new SampleResult();
    parent.sampleStart();
    parent.addSubResult(createChildSample());
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) SampleResult(org.apache.jmeter.samplers.SampleResult) Properties(java.util.Properties) Session(javax.mail.Session) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 89 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter by apache.

the class SMIMEAssertionTest method createChildSample.

private SampleResult createChildSample() throws MessagingException, IOException {
    SampleResult child = new SampleResult();
    child.setSampleLabel("Message " + msg.getMessageNumber());
    child.setContentType(msg.getContentType());
    child.setEncodingAndType(msg.getContentType());
    ByteArrayOutputStream outbuf = new ByteArrayOutputStream();
    msg.writeTo(outbuf);
    child.setResponseData(outbuf.toByteArray());
    child.setDataType(SampleResult.TEXT);
    child.setResponseOK();
    return child;
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 90 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter by apache.

the class TestJSONPathAssertion method testGetResult_null_novalidate.

@Test
void testGetResult_null_novalidate() {
    SampleResult samplerResult = new SampleResult();
    samplerResult.setResponseData("{\"myval\": null}".getBytes());
    JSONPathAssertion instance = new JSONPathAssertion();
    instance.setJsonPath("$.myval");
    instance.setJsonValidationBool(false);
    AssertionResult expResult = new AssertionResult("");
    AssertionResult result = instance.getResult(samplerResult);
    assertEquals(expResult.getName(), result.getName());
    assertFalse(result.isFailure());
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

SampleResult (org.apache.jmeter.samplers.SampleResult)379 Test (org.junit.Test)83 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)71 Test (org.junit.jupiter.api.Test)59 JMeterContext (org.apache.jmeter.threads.JMeterContext)47 BeforeEach (org.junit.jupiter.api.BeforeEach)36 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 SampleEvent (org.apache.jmeter.samplers.SampleEvent)30 Sampler (org.apache.jmeter.samplers.Sampler)30 AssertionResult (org.apache.jmeter.assertions.AssertionResult)27 ArrayList (java.util.ArrayList)26 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)20 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)20 IOException (java.io.IOException)17 Arguments (org.apache.jmeter.config.Arguments)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)13 CorrectedResultCollector (kg.apc.jmeter.vizualizers.CorrectedResultCollector)12 URL (java.net.URL)9 File (java.io.File)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7