use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class SizeAssertionTest method setUp.
@Before
public void setUp() {
JMeterContext jmctx = JMeterContextService.getContext();
assertion = new SizeAssertion();
assertion.setThreadContext(jmctx);
assertion.setTestFieldResponseBody();
JMeterVariables vars = new JMeterVariables();
jmctx.setVariables(vars);
sample0 = new SampleResult();
sample1 = new SampleResult();
sample1.setResponseData(data1, null);
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class TestRandomVariableConfig method setUp.
@Before
public void setUp() {
JMeterContext jmcx = JMeterContextService.getContext();
jmcx.setVariables(new JMeterVariables());
threadVars = jmcx.getVariables();
config.setRandomSeed("abcd");
config.setVariableName("randomVar");
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class XPathAssertionTest method setUp.
@Before
public void setUp() throws Exception {
jmctx = JMeterContextService.getContext();
assertion = new XPathAssertion();
// This would be done by the run command
assertion.setThreadContext(jmctx);
result = new SampleResult();
result.setResponseData(readFile("testfiles/XPathAssertionTest.xml"));
vars = new JMeterVariables();
jmctx.setVariables(vars);
jmctx.setPreviousResult(result);
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class XPathAssertionTest method testNoTolerance.
@Test
public void testNoTolerance() throws Exception {
String data = "<html><head><title>testtitle</title></head>" + "<body>" + "<p><i><b>invalid tag nesting</i></b><hr>" + "</body></html>";
result.setResponseData(data, null);
vars = new JMeterVariables();
jmctx.setVariables(vars);
jmctx.setPreviousResult(result);
assertion.setXPathString("/html/head/title");
assertion.setValidating(false);
assertion.setTolerant(false);
AssertionResult res = assertion.getResult(result);
log.debug("failureMessage: {}", res.getFailureMessage());
assertTrue(res.isError());
assertFalse(res.isFailure());
}
use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.
the class CSVDataSet method iterationStart.
@Override
public void iterationStart(LoopIterationEvent iterEvent) {
FileServer server = FileServer.getFileServer();
final JMeterContext context = getThreadContext();
String delim = getDelimiter();
if ("\\t".equals(delim)) {
// $NON-NLS-1$
// Make it easier to enter a Tab // $NON-NLS-1$
delim = "\t";
} else if (delim.isEmpty()) {
log.debug("Empty delimiter, will use ','");
delim = ",";
}
if (vars == null) {
String fileName = getFilename().trim();
String mode = getShareMode();
int modeInt = CSVDataSetBeanInfo.getShareModeAsInt(mode);
switch(modeInt) {
case CSVDataSetBeanInfo.SHARE_ALL:
alias = fileName;
break;
case CSVDataSetBeanInfo.SHARE_GROUP:
alias = fileName + "@" + System.identityHashCode(context.getThreadGroup());
break;
case CSVDataSetBeanInfo.SHARE_THREAD:
alias = fileName + "@" + System.identityHashCode(context.getThread());
break;
default:
// user-specified key
alias = fileName + "@" + mode;
break;
}
final String names = getVariableNames();
if (StringUtils.isEmpty(names)) {
String header = server.reserveFile(fileName, getFileEncoding(), alias, true);
try {
vars = CSVSaveService.csvSplitString(header, delim.charAt(0));
firstLineIsNames = true;
} catch (IOException e) {
throw new IllegalArgumentException("Could not split CSV header line from file:" + fileName, e);
}
} else {
server.reserveFile(fileName, getFileEncoding(), alias, ignoreFirstLine);
// $NON-NLS-1$
vars = JOrphanUtils.split(names, ",");
}
trimVarNames(vars);
}
// TODO: fetch this once as per vars above?
JMeterVariables threadVars = context.getVariables();
String[] lineValues = {};
try {
if (getQuotedData()) {
lineValues = server.getParsedLine(alias, recycle, firstLineIsNames || ignoreFirstLine, delim.charAt(0));
} else {
String line = server.readLine(alias, recycle, firstLineIsNames || ignoreFirstLine);
lineValues = JOrphanUtils.split(line, delim, false);
}
for (int a = 0; a < vars.length && a < lineValues.length; a++) {
threadVars.put(vars[a], lineValues[a]);
}
} catch (IOException e) {
// treat the same as EOF
log.error(e.toString());
}
if (lineValues.length == 0) {
// i.e. EOF
if (getStopThread()) {
throw new JMeterStopThreadException("End of file:" + getFilename() + " detected for CSV DataSet:" + getName() + " configured with stopThread:" + getStopThread() + ", recycle:" + getRecycle());
}
for (String var : vars) {
threadVars.put(var, EOFVALUE);
}
}
}
Aggregations