Search in sources :

Example 51 with JMeterContext

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"));
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) SampleResult(org.apache.jmeter.samplers.SampleResult) Test(org.junit.Test)

Example 52 with JMeterContext

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);
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) SampleResult(org.apache.jmeter.samplers.SampleResult) Test(org.junit.Test)

Example 53 with JMeterContext

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"));
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) SampleResult(org.apache.jmeter.samplers.SampleResult) Test(org.junit.Test)

Example 54 with JMeterContext

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"));
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) SampleResult(org.apache.jmeter.samplers.SampleResult) Test(org.junit.Test)

Example 55 with JMeterContext

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());
}
Also used : JMeterContext(org.apache.jmeter.threads.JMeterContext)

Aggregations

JMeterContext (org.apache.jmeter.threads.JMeterContext)98 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)64 SampleResult (org.apache.jmeter.samplers.SampleResult)47 Test (org.junit.Test)19 Test (org.junit.jupiter.api.Test)18 BeforeEach (org.junit.jupiter.api.BeforeEach)13 JSONPostProcessor (org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)10 Sampler (org.apache.jmeter.samplers.Sampler)9 TestSampler (org.apache.jmeter.junit.stubs.TestSampler)8 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)4 Properties (java.util.Properties)3 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)3 JMeterException (org.apache.jorphan.util.JMeterException)3 HashMap (java.util.HashMap)2 Bindings (javax.script.Bindings)2 Arguments (org.apache.jmeter.config.Arguments)2 ReplaceStringWithFunctions (org.apache.jmeter.engine.util.ReplaceStringWithFunctions)2