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);
}
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()));
}
Aggregations