use of org.apache.jmeter.threads.JMeterContext in project jmeter-plugins by undera.
the class JSONPathExtractorTest method testProcess_from_var.
@Test
public void testProcess_from_var() {
System.out.println("process fromvar");
JMeterContext context = JMeterContextService.getContext();
JMeterVariables vars = context.getVariables();
SampleResult res = new SampleResult();
res.setResponseData("".getBytes());
context.setPreviousResult(res);
vars.put("SVAR", json);
JSONPathExtractor instance = new JSONPathExtractor();
instance.setDefaultValue("DEFAULT");
instance.setVar("test");
instance.setJsonPath("$.store.book[*].author");
instance.setSubject(JSONPathExtractor.SUBJECT_VARIABLE);
instance.setSrcVariableName("SVAR");
instance.process();
assertEquals("[\"Nigel Rees\",\"Evelyn Waugh\",\"Herman Melville\",\"J. R. R. Tolkien\"]", vars.get("test"));
}
use of org.apache.jmeter.threads.JMeterContext in project jmeter-plugins by undera.
the class JSONPathExtractorTest method testProcess_from_var_2.
@Test
public void testProcess_from_var_2() {
System.out.println("process fromvar");
JMeterContext context = JMeterContextService.getContext();
JMeterVariables vars = context.getVariables();
SampleResult res = new SampleResult();
res.setResponseData("".getBytes());
context.setPreviousResult(res);
vars.put("SVAR", json);
JSONPathExtractor instance = new JSONPathExtractor();
instance.setDefaultValue("DEFAULT");
instance.setVar("test");
instance.setJsonPath("$.store.bicycle");
instance.setSubject(JSONPathExtractor.SUBJECT_VARIABLE);
instance.setSrcVariableName("SVAR");
instance.process();
String test = vars.get("test");
boolean thiis = "{\"color\":\"red\",\"price\":19.95}".equals(test);
boolean thaat = "{\"price\":19.95,\"color\":\"red\"}".equals(test);
assertTrue(thiis || thaat);
}
use of org.apache.jmeter.threads.JMeterContext in project jmeter-plugins by undera.
the class JSONPathExtractorTest method testProcess_list.
@Test
public void testProcess_list() {
System.out.println("process list");
JMeterContext context = JMeterContextService.getContext();
SampleResult res = new SampleResult();
res.setResponseData("{\"myval\": [{\"test\":1},{\"test\":{\"dict\":1}},{\"test\":null}]}".getBytes());
context.setPreviousResult(res);
JSONPathExtractor instance = new JSONPathExtractor();
instance.setDefaultValue("DEFAULT");
instance.setVar("test");
instance.setJsonPath("$.myval[*].test");
instance.process();
JMeterVariables vars = context.getVariables();
assertEquals("[1,{\"dict\":1},null]", vars.get("test"));
assertEquals("1", vars.get("test_1"));
assertEquals("{\"dict\":1}", vars.get("test_2"));
assertEquals("null", vars.get("test_3"));
// test for cleaning prev vars
res.setResponseData("{\"myval\": [{\"test\":1},{\"test\":2}]}".getBytes());
instance.process();
assertEquals("[1,2]", vars.get("test"));
assertEquals("1", vars.get("test_1"));
assertEquals("2", vars.get("test_2"));
assertEquals(null, vars.get("test_3"));
}
use of org.apache.jmeter.threads.JMeterContext in project jmeter-plugins by undera.
the class JSONPathExtractorTest method testReported1.
@Test
public void testReported1() {
System.out.println("process reported");
JMeterContext context = JMeterContextService.getContext();
SampleResult res = new SampleResult();
res.setResponseData(json2.getBytes());
context.setPreviousResult(res);
JSONPathExtractor instance = new JSONPathExtractor();
instance.setVar("GroupID");
instance.setJsonPath("$.data.groups[?(@.name=='Zaz')].id");
instance.setDefaultValue("NOTFOUND");
instance.process();
JMeterVariables vars = context.getVariables();
assertNotEquals("NOTFOUND", vars.get("GroupID"));
assertEquals("378e9b20-99bb-4d1f-bf2c-6a4a6c69a8ed", vars.get("GroupID_1"));
}
use of org.apache.jmeter.threads.JMeterContext in project jmeter-plugins by undera.
the class MonitoringResultsCollector method syncContext.
/**
* Update the worker thread jmeter context with the main thread one
* @param isInit if true the context a full copy is done, if false only update is done
*/
private void syncContext(boolean isInit) {
// jmeter context synchronisation
JMeterContext current = JMeterContextService.getContext();
JMeterContext ctx = this.getThreadContext();
if (isInit) {
current.setCurrentSampler(ctx.getCurrentSampler());
current.setEngine(ctx.getEngine());
current.setRestartNextLoop(ctx.isRestartNextLoop());
current.setSamplingStarted(ctx.isSamplingStarted());
current.setThread(ctx.getThread());
current.setThreadGroup(ctx.getThreadGroup());
current.setThreadNum(ctx.getThreadNum());
}
current.setVariables(ctx.getVariables());
current.setPreviousResult(ctx.getPreviousResult());
// current.getSamplerContext().putAll(ctx.getSamplerContext());
}
Aggregations