use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class TestResultAction method setUp.
@BeforeEach
public void setUp() {
JMeterContext jmctx = JMeterContextService.getContext();
resultAction = new ResultAction();
resultAction.setThreadContext(jmctx);
JMeterVariables vars = new JMeterVariables();
jmctx.setVariables(vars);
sampleResult = new SampleResult();
sampleResult.setResponseData(data, null);
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class JMeterContextExtension method beforeEach.
@Override
public void beforeEach(ExtensionContext context) throws Exception {
JMeterContext jMeterContext = JMeterContextService.getContext();
jMeterContext.clear();
jMeterContext.setVariables(new JMeterVariables());
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class SimpleVariable method toString.
/**
* @see org.apache.jmeter.functions.Function#execute
*/
@Override
public String toString() {
String ret = null;
JMeterVariables vars = getVariables();
if (vars != null) {
ret = vars.get(name);
}
if (ret == null) {
return "${" + name + "}";
}
return ret;
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class EvalVarFunction method execute.
/**
* {@inheritDoc}
*/
@Override
public String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
String variableName = ((CompoundVariable) values[0]).execute();
final JMeterVariables vars = getVariables();
if (vars == null) {
log.error("Variables have not yet been defined");
return "**ERROR - see log file**";
}
String variableValue = vars.get(variableName);
CompoundVariable cv = new CompoundVariable(variableValue);
return cv.execute();
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class FileToString method execute.
/**
* {@inheritDoc}
*/
@Override
public String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
String fileName = ((CompoundVariable) values[0]).execute();
// means platform default
String encoding = null;
if (values.length >= ENCODING) {
encoding = ((CompoundVariable) values[ENCODING - 1]).execute().trim();
if (encoding.length() <= 0) {
// empty encoding, return to platform default
encoding = null;
}
}
// $NON-NLS-1$
String myName = "";
if (values.length >= PARAM_NAME) {
myName = ((CompoundVariable) values[PARAM_NAME - 1]).execute().trim();
}
String myValue = ERR_IND;
try {
File file = new File(fileName);
if (file.exists() && file.canRead()) {
myValue = FileUtils.readFileToString(new File(fileName), encoding);
} else {
log.warn("Could not read open: {} ", fileName);
}
} catch (IOException e) {
log.warn("Could not read file: {} {}", fileName, e.getMessage(), e);
}
if (myName.length() > 0) {
JMeterVariables vars = getVariables();
if (vars != null) {
// Can be null if called from Config item testEnded() method
vars.put(myName, myValue);
}
}
if (log.isDebugEnabled()) {
// $NON-NLS-1$
log.debug("{} name: {} value: {}", Thread.currentThread().getName(), myName, myValue);
}
return myValue;
}
Aggregations