Search in sources :

Example 1 with ResponseAssertion

use of org.apache.jmeter.assertions.ResponseAssertion in project jmeter by apache.

the class AssertionGui method modifyTestElement.

/* Implements JMeterGUIComponent.modifyTestElement(TestElement) */
@Override
public void modifyTestElement(TestElement el) {
    GuiUtils.stopTableEditing(stringTable);
    configureTestElement(el);
    if (el instanceof ResponseAssertion) {
        ResponseAssertion ra = (ResponseAssertion) el;
        ra.setCustomFailureMessage(alternativeFailureMessage.getText());
        saveScopeSettings(ra);
        ra.clearTestStrings();
        String[] testStrings = tableModel.getData().getColumn(COL_RESOURCE_NAME);
        for (String testString : testStrings) {
            ra.addTestString(testString);
        }
        if (responseStringButton.isSelected()) {
            ra.setTestFieldResponseData();
        } else if (responseAsDocumentButton.isSelected()) {
            ra.setTestFieldResponseDataAsDocument();
        } else if (responseCodeButton.isSelected()) {
            ra.setTestFieldResponseCode();
        } else if (responseMessageButton.isSelected()) {
            ra.setTestFieldResponseMessage();
        } else if (requestHeadersButton.isSelected()) {
            ra.setTestFieldRequestHeaders();
        } else if (requestDataButton.isSelected()) {
            ra.setTestFieldRequestData();
        } else if (responseHeadersButton.isSelected()) {
            ra.setTestFieldResponseHeaders();
        } else {
            // Assume URL
            ra.setTestFieldURL();
        }
        ra.setAssumeSuccess(assumeSuccess.isSelected());
        if (containsBox.isSelected()) {
            ra.setToContainsType();
        } else if (equalsBox.isSelected()) {
            ra.setToEqualsType();
        } else if (substringBox.isSelected()) {
            ra.setToSubstringType();
        } else {
            ra.setToMatchType();
        }
        if (notBox.isSelected()) {
            ra.setToNotType();
        } else {
            ra.unsetNotType();
        }
        if (orBox.isSelected()) {
            ra.setToOrType();
        } else {
            ra.unsetOrType();
        }
    }
}
Also used : ResponseAssertion(org.apache.jmeter.assertions.ResponseAssertion)

Example 2 with ResponseAssertion

use of org.apache.jmeter.assertions.ResponseAssertion in project jmeter by apache.

the class TestTransactionController method testIssue57958.

@Test
public void testIssue57958() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());
    TestSampleListener listener = new TestSampleListener();
    TransactionController transactionController = new TransactionController();
    transactionController.setGenerateParentSample(true);
    ResponseAssertion assertion = new ResponseAssertion();
    assertion.setTestFieldResponseCode();
    assertion.setToEqualsType();
    assertion.addTestString("201");
    DebugSampler debugSampler = new DebugSampler();
    debugSampler.addTestElement(assertion);
    LoopController loop = new LoopController();
    loop.setLoops(1);
    loop.setContinueForever(false);
    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(loop);
    hashTree.add(loop, transactionController);
    hashTree.add(transactionController, debugSampler);
    hashTree.add(transactionController, listener);
    hashTree.add(debugSampler, assertion);
    TestCompiler compiler = new TestCompiler(hashTree);
    hashTree.traverse(compiler);
    ThreadGroup threadGroup = new ThreadGroup();
    threadGroup.setNumThreads(1);
    ListenerNotifier notifier = new ListenerNotifier();
    JMeterThread thread = new JMeterThread(hashTree, threadGroup, notifier);
    thread.setThreadGroup(threadGroup);
    thread.setOnErrorStopThread(true);
    thread.run();
    assertEquals("Must one transaction samples with parent debug sample", 1, listener.events.size());
    assertEquals("Number of samples in transaction : 1, number of failing samples : 1", listener.events.get(0).getResult().getResponseMessage());
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) ListedHashTree(org.apache.jorphan.collections.ListedHashTree) ResponseAssertion(org.apache.jmeter.assertions.ResponseAssertion) DebugSampler(org.apache.jmeter.sampler.DebugSampler) TestCompiler(org.apache.jmeter.threads.TestCompiler) ThreadGroup(org.apache.jmeter.threads.ThreadGroup) JMeterThread(org.apache.jmeter.threads.JMeterThread) ListenerNotifier(org.apache.jmeter.threads.ListenerNotifier) Test(org.junit.jupiter.api.Test)

Example 3 with ResponseAssertion

use of org.apache.jmeter.assertions.ResponseAssertion in project jmeter by apache.

the class AssertionGui method configure.

/**
 * A newly created component can be initialized with the contents of a Test
 * Element object by calling this method. The component is responsible for
 * querying the Test Element object for the relevant information to display
 * in its GUI.
 *
 * @param el
 *            the TestElement to configure
 */
@Override
public void configure(TestElement el) {
    super.configure(el);
    ResponseAssertion model = (ResponseAssertion) el;
    showScopeSettings(model, true);
    if (model.getCustomFailureMessage() != null) {
        alternativeFailureMessage.setText(model.getCustomFailureMessage());
    }
    if (model.isContainsType()) {
        containsBox.setSelected(true);
    } else if (model.isEqualsType()) {
        equalsBox.setSelected(true);
    } else if (model.isSubstringType()) {
        substringBox.setSelected(true);
    } else {
        matchesBox.setSelected(true);
    }
    notBox.setSelected(model.isNotType());
    orBox.setSelected(model.isOrType());
    if (model.isTestFieldResponseData()) {
        responseStringButton.setSelected(true);
    } else if (model.isTestFieldResponseDataAsDocument()) {
        responseAsDocumentButton.setSelected(true);
    } else if (model.isTestFieldResponseCode()) {
        responseCodeButton.setSelected(true);
    } else if (model.isTestFieldResponseMessage()) {
        responseMessageButton.setSelected(true);
    } else if (model.isTestFieldRequestHeaders()) {
        requestHeadersButton.setSelected(true);
    } else if (model.isTestFieldRequestData()) {
        requestDataButton.setSelected(true);
    } else if (model.isTestFieldResponseHeaders()) {
        responseHeadersButton.setSelected(true);
    } else // Assume it is the URL
    {
        urlButton.setSelected(true);
    }
    assumeSuccess.setSelected(model.getAssumeSuccess());
    tableModel.clearData();
    for (JMeterProperty jMeterProperty : model.getTestStrings()) {
        tableModel.addRow(new Object[] { jMeterProperty.getStringValue() });
    }
    boolean testStringsPresent = model.getTestStrings().size() != 0;
    deletePattern.setEnabled(testStringsPresent);
    tableModel.fireTableDataChanged();
}
Also used : ResponseAssertion(org.apache.jmeter.assertions.ResponseAssertion) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty)

Example 4 with ResponseAssertion

use of org.apache.jmeter.assertions.ResponseAssertion in project jmeter by apache.

the class AssertionGui method createTestElement.

/* Implements JMeterGUIComponent.createTestElement() */
@Override
public TestElement createTestElement() {
    ResponseAssertion el = new ResponseAssertion();
    modifyTestElement(el);
    return el;
}
Also used : ResponseAssertion(org.apache.jmeter.assertions.ResponseAssertion)

Example 5 with ResponseAssertion

use of org.apache.jmeter.assertions.ResponseAssertion in project jmeter by apache.

the class ProxyControl method addAssertion.

/**
 * Helper method to add a Response Assertion
 * Called from AWT Event thread
 */
private void addAssertion(JMeterTreeModel model, JMeterTreeNode node) throws IllegalUserActionException {
    ResponseAssertion ra = new ResponseAssertion();
    ra.setProperty(TestElement.GUI_CLASS, ASSERTION_GUI);
    // $NON-NLS-1$
    ra.setName(JMeterUtils.getResString("assertion_title"));
    ra.setTestFieldResponseData();
    model.addComponent(ra, node);
}
Also used : ResponseAssertion(org.apache.jmeter.assertions.ResponseAssertion)

Aggregations

ResponseAssertion (org.apache.jmeter.assertions.ResponseAssertion)5 DebugSampler (org.apache.jmeter.sampler.DebugSampler)1 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)1 JMeterThread (org.apache.jmeter.threads.JMeterThread)1 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)1 ListenerNotifier (org.apache.jmeter.threads.ListenerNotifier)1 TestCompiler (org.apache.jmeter.threads.TestCompiler)1 ThreadGroup (org.apache.jmeter.threads.ThreadGroup)1 ListedHashTree (org.apache.jorphan.collections.ListedHashTree)1 Test (org.junit.jupiter.api.Test)1