Search in sources :

Example 1 with Assertion

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

the class TestCompiler method saveTransactionControllerConfigs.

private void saveTransactionControllerConfigs(TransactionController tc) {
    List<ConfigTestElement> configs = new LinkedList<>();
    List<Controller> controllers = new LinkedList<>();
    List<SampleListener> listeners = new LinkedList<>();
    List<Timer> timers = new LinkedList<>();
    List<Assertion> assertions = new LinkedList<>();
    LinkedList<PostProcessor> posts = new LinkedList<>();
    LinkedList<PreProcessor> pres = new LinkedList<>();
    for (int i = stack.size(); i > 0; i--) {
        addDirectParentControllers(controllers, stack.get(i - 1));
        for (Object item : testTree.list(stack.subList(0, i))) {
            if (item instanceof SampleListener) {
                listeners.add((SampleListener) item);
            }
            if (item instanceof Assertion) {
                assertions.add((Assertion) item);
            }
        }
    }
    SamplePackage pack = new SamplePackage(configs, listeners, timers, assertions, posts, pres, controllers);
    pack.setSampler(new TransactionSampler(tc, tc.getName()));
    pack.setRunningVersion(true);
    transactionControllerConfigMap.put(tc, pack);
}
Also used : Assertion(org.apache.jmeter.assertions.Assertion) PreProcessor(org.apache.jmeter.processor.PreProcessor) Controller(org.apache.jmeter.control.Controller) TransactionController(org.apache.jmeter.control.TransactionController) SampleListener(org.apache.jmeter.samplers.SampleListener) LinkedList(java.util.LinkedList) Timer(org.apache.jmeter.timers.Timer) TransactionSampler(org.apache.jmeter.control.TransactionSampler) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) PostProcessor(org.apache.jmeter.processor.PostProcessor)

Example 2 with Assertion

use of org.apache.jmeter.assertions.Assertion 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)2 LinkedList (java.util.LinkedList)1 AssertionResult (org.apache.jmeter.assertions.AssertionResult)1 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)1 Controller (org.apache.jmeter.control.Controller)1 TransactionController (org.apache.jmeter.control.TransactionController)1 TransactionSampler (org.apache.jmeter.control.TransactionSampler)1 PostProcessor (org.apache.jmeter.processor.PostProcessor)1 PreProcessor (org.apache.jmeter.processor.PreProcessor)1 SampleListener (org.apache.jmeter.samplers.SampleListener)1 SampleResult (org.apache.jmeter.samplers.SampleResult)1 AbstractScopedAssertion (org.apache.jmeter.testelement.AbstractScopedAssertion)1 Timer (org.apache.jmeter.timers.Timer)1