use of org.apache.jmeter.threads.JMeterContext in project jmeter by apache.
the class TestXPath2Extractor method testPreviousResultIsEmpty.
@Test
public void testPreviousResultIsEmpty() throws Exception {
JMeterContext jmc = JMeterContextService.getContext();
extractor = new XPath2Extractor();
// This would be done by the run command
extractor.setThreadContext(jmctx);
extractor.setRefName(VAL_NAME);
extractor.setDefaultValue("Default");
jmc.setPreviousResult(null);
extractor.setXPathQuery("/book/preface");
extractor.process();
assertEquals(null, vars.get(VAL_NAME));
}
use of org.apache.jmeter.threads.JMeterContext in project jmeter by apache.
the class TestRandomVariableConfig method setUp.
@BeforeEach
public void setUp() {
JMeterContext jmcx = JMeterContextService.getContext();
jmcx.setVariables(new JMeterVariables());
threadVars = jmcx.getVariables();
config.setRandomSeed("abcd");
config.setVariableName(RANDOM_VAR_NAME);
}
use of org.apache.jmeter.threads.JMeterContext in project jmeter by apache.
the class ResponseAssertionTest method setUp.
@BeforeEach
public void setUp() throws MalformedURLException {
JMeterContext jmctx = JMeterContextService.getContext();
assertion = new ResponseAssertion();
assertion.setThreadContext(jmctx);
sample = new SampleResult();
JMeterVariables vars = new JMeterVariables();
jmctx.setVariables(vars);
jmctx.setPreviousResult(sample);
sample.setResponseData("response Data\nline 2\n\nEOF", null);
sample.setURL(new URL("http://localhost/Sampler/Data/"));
sample.setResponseCode("401");
sample.setResponseHeaders("X-Header: abcd");
sample.setRequestHeaders("X-reqHeader: cdef");
}
use of org.apache.jmeter.threads.JMeterContext in project jmeter by apache.
the class SizeAssertionTest method setUp.
@BeforeEach
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.JMeterContext in project jmeter by apache.
the class TestJSONPostProcessor method testExtractComplexElements.
@Test
void testExtractComplexElements() {
JMeterContext context = JMeterContextService.getContext();
JSONPostProcessor processor = setupProcessor(context, "-1");
String data = "[{\"a\":[1,{\"d\":2},3]},[\"b\",{\"h\":23}],3]";
SampleResult result = new SampleResult();
result.setResponseData(data.getBytes(StandardCharsets.UTF_8));
JMeterVariables vars = new JMeterVariables();
context.setVariables(vars);
context.setPreviousResult(result);
processor.setJsonPathExpressions("$[*]");
processor.process();
String jsonWithoutOuterParens = data.substring(1, data.length() - 1);
assertEquals(jsonWithoutOuterParens, vars.get(VAR_NAME + "_ALL"));
assertEquals("{\"a\":[1,{\"d\":2},3]}", vars.get(VAR_NAME + "_1"));
assertEquals("[\"b\",{\"h\":23}]", vars.get(VAR_NAME + "_2"));
assertEquals("3", vars.get(VAR_NAME + "_3"));
assertEquals("3", vars.get(VAR_NAME + "_matchNr"));
}
Aggregations