* {@inheritDoc}
*/
public AssertionResult getResult(SampleResult response) {
AssertionResult result = new AssertionResult(getName());
final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
if (bshInterpreter == null) {
result.setFailure(true);
result.setError(true);
result.setFailureMessage("BeanShell Interpreter not found");
return result;
}
try {
String request = getScript();
String fileName = getFilename();
bshInterpreter.set("FileName", getFilename());//$NON-NLS-1$
// Set params as a single line
bshInterpreter.set("Parameters", getParameters()); // $NON-NLS-1$
bshInterpreter.set("bsh.args",//$NON-NLS-1$
JOrphanUtils.split(getParameters(), " "));//$NON-NLS-1$
// Add SamplerData for consistency with BeanShell Sampler
bshInterpreter.set("SampleResult", response); //$NON-NLS-1$
bshInterpreter.set("Response", response); //$NON-NLS-1$
bshInterpreter.set("ResponseData", response.getResponseData());//$NON-NLS-1$
bshInterpreter.set("ResponseCode", response.getResponseCode());//$NON-NLS-1$
bshInterpreter.set("ResponseMessage", response.getResponseMessage());//$NON-NLS-1$
bshInterpreter.set("ResponseHeaders", response.getResponseHeaders());//$NON-NLS-1$
bshInterpreter.set("RequestHeaders", response.getRequestHeaders());//$NON-NLS-1$
bshInterpreter.set("SampleLabel", response.getSampleLabel());//$NON-NLS-1$
bshInterpreter.set("SamplerData", response.getSamplerData());//$NON-NLS-1$
bshInterpreter.set("Successful", response.isSuccessful());//$NON-NLS-1$
// The following are used to set the Result details on return from
// the script:
bshInterpreter.set("FailureMessage", "");//$NON-NLS-1$ //$NON-NLS-2$
bshInterpreter.set("Failure", false);//$NON-NLS-1$
// Add variables for access to context and variables
JMeterContext jmctx = JMeterContextService.getContext();
JMeterVariables vars = jmctx.getVariables();
bshInterpreter.set("ctx", jmctx);//$NON-NLS-1$
bshInterpreter.set("vars", vars);//$NON-NLS-1$
// Object bshOut;
if (fileName.length() == 0) {
// bshOut =
bshInterpreter.eval(request);
} else {
// bshOut =
bshInterpreter.source(fileName);
}
result.setFailureMessage(bshInterpreter.get("FailureMessage").toString());//$NON-NLS-1$
result.setFailure(Boolean.valueOf(bshInterpreter.get("Failure") //$NON-NLS-1$
.toString()).booleanValue());
result.setError(false);
}
/*
* To avoid class loading problems when the BSH jar is missing, we don't