Search in sources :

Example 1 with AbstractScopedAssertion

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

the class JMeterThread method checkAssertions.

private void checkAssertions(List<Assertion> assertions, SampleResult parent, JMeterContext threadContext) {
    for (Assertion assertion : assertions) {
        TestBeanHelper.prepare((TestElement) assertion);
        if (assertion instanceof AbstractScopedAssertion) {
            AbstractScopedAssertion scopedAssertion = (AbstractScopedAssertion) assertion;
            String scope = scopedAssertion.fetchScope();
            if (scopedAssertion.isScopeParent(scope) || scopedAssertion.isScopeAll(scope) || scopedAssertion.isScopeVariable(scope)) {
                processAssertion(parent, assertion);
            }
            if (scopedAssertion.isScopeChildren(scope) || scopedAssertion.isScopeAll(scope)) {
                SampleResult[] children = parent.getSubResults();
                boolean childError = false;
                for (SampleResult childSampleResult : children) {
                    processAssertion(childSampleResult, assertion);
                    if (!childSampleResult.isSuccessful()) {
                        childError = true;
                    }
                }
                // If parent is OK, but child failed, add a message and flag the parent as failed
                if (childError && parent.isSuccessful()) {
                    AssertionResult assertionResult = new AssertionResult(((AbstractTestElement) assertion).getName());
                    assertionResult.setResultForFailure("One or more sub-samples failed");
                    parent.addAssertionResult(assertionResult);
                    parent.setSuccessful(false);
                }
            }
        } else {
            processAssertion(parent, assertion);
        }
    }
    threadContext.getVariables().put(LAST_SAMPLE_OK, Boolean.toString(parent.isSuccessful()));
}
Also used : AssertionResult(org.apache.jmeter.assertions.AssertionResult) Assertion(org.apache.jmeter.assertions.Assertion) AbstractScopedAssertion(org.apache.jmeter.testelement.AbstractScopedAssertion) AbstractScopedAssertion(org.apache.jmeter.testelement.AbstractScopedAssertion) SampleResult(org.apache.jmeter.samplers.SampleResult)

Aggregations

Assertion (org.apache.jmeter.assertions.Assertion)1 AssertionResult (org.apache.jmeter.assertions.AssertionResult)1 SampleResult (org.apache.jmeter.samplers.SampleResult)1 AbstractScopedAssertion (org.apache.jmeter.testelement.AbstractScopedAssertion)1