use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.
the class BeanShell method execute.
/** {@inheritDoc} */
@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
if (// did we find BeanShell?
bshInterpreter == null) {
throw new InvalidVariableException("BeanShell not found");
}
JMeterContext jmctx = JMeterContextService.getContext();
JMeterVariables vars = jmctx.getVariables();
String script = ((CompoundVariable) values[0]).execute();
//$NON-NLS-1$
String varName = "";
if (values.length > 1) {
varName = ((CompoundVariable) values[1]).execute().trim();
}
//$NON-NLS-1$
String resultStr = "";
try {
// Pass in some variables
if (currentSampler != null) {
//$NON-NLS-1$
bshInterpreter.set("Sampler", currentSampler);
}
if (previousResult != null) {
//$NON-NLS-1$
bshInterpreter.set("SampleResult", previousResult);
}
// Allow access to context and variables directly
//$NON-NLS-1$
bshInterpreter.set("ctx", jmctx);
//$NON-NLS-1$
bshInterpreter.set("vars", vars);
//$NON-NLS-1$
bshInterpreter.set("props", JMeterUtils.getJMeterProperties());
//$NON-NLS-1$
bshInterpreter.set("threadName", Thread.currentThread().getName());
// Execute the script
Object bshOut = bshInterpreter.eval(script);
if (bshOut != null) {
resultStr = bshOut.toString();
}
if (vars != null && varName.length() > 0) {
// vars will be null on TestPlan
vars.put(varName, resultStr);
}
} catch (// Mainly for bsh.EvalError
Exception ex) {
log.warn("Error running BSH script", ex);
}
if (log.isDebugEnabled()) {
log.debug("__Beanshell(" + script + "," + varName + ")=" + resultStr);
}
return resultStr;
}
use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.
the class TestUrlEncodeDecode method testUrlDecode.
@Test
public void testUrlDecode() throws Exception {
AbstractFunction function = new UrlDecode();
params.add(new CompoundVariable("Veni%2C+vidi%2C+vici+%3F"));
function.setParameters(params);
String returnValue = function.execute(result, null);
assertEquals("Veni, vidi, vici ?", returnValue);
}
use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.
the class JMeterTestCaseJUnit method checkInvalidParameterCounts.
protected void checkInvalidParameterCounts(AbstractFunction func, int minimum) throws Exception {
Collection<CompoundVariable> parms = new LinkedList<>();
for (int c = 0; c < minimum; c++) {
try {
func.setParameters(parms);
fail("Should have generated InvalidVariableException for " + parms.size() + " parameters");
} catch (InvalidVariableException ignored) {
}
parms.add(new CompoundVariable());
}
func.setParameters(parms);
}
use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.
the class JMeterTestCase method checkInvalidParameterCounts.
protected void checkInvalidParameterCounts(AbstractFunction func, int minimum) throws Exception {
Collection<CompoundVariable> parms = new LinkedList<>();
for (int c = 0; c < minimum; c++) {
try {
func.setParameters(parms);
fail("Should have generated InvalidVariableException for " + parms.size() + " parameters");
} catch (InvalidVariableException ignored) {
}
parms.add(new CompoundVariable());
}
func.setParameters(parms);
}
use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.
the class TestTimeFunction method testMixed.
@Test
public void testMixed() throws Exception {
params.add(new CompoundVariable("G"));
variable.setParameters(params);
Locale locale = Locale.getDefault();
Locale.setDefault(Locale.ENGLISH);
value = variable.execute(result, null);
Locale.setDefault(locale);
assertEquals("AD", value);
}
Aggregations