Java Code Examples for org.apache.jmeter.threads.JMeterContext#setPreviousResult()

The following examples show how to use org.apache.jmeter.threads.JMeterContext#setPreviousResult() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcess_chinese() {
    JMeterContext context = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    String chinese = "{\"carBrandName\":\"大众\"}";

    res.setResponseData(chinese.getBytes());
    context.setPreviousResult(res);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setDefaultValue("DEFAULT");
    instance.setVar("test");
    instance.setJsonPath("$.carBrandName");
    instance.process();
    JMeterVariables vars = context.getVariables();
    // freaking "static final" DEFAULT_ENCODING field in SampleResult does not allow us to assert this
    // assertEquals("大众", vars.get("test"));
}
 
Example 2
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testYamlExtractor3() throws IOException {
    File test = new File(getClass().getResource("/test.yml").getPath());
    String response = FileUtils.readFileToString(test);

    JMeterContext context = JMeterContextService.getContext();
    JMeterVariables vars = context.getVariables();

    SampleResult samplerResult = new SampleResult();
    samplerResult.setResponseData(response.getBytes());
    context.setPreviousResult(samplerResult);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setInputFormat(JSONPathExtractor.INPUT_YAML);
    instance.setDefaultValue("DEFAULT");
    instance.setVar("developers");
    instance.setJsonPath("$.developers");
    instance.process();

    assertEquals("[\"rultor\",\"salikjan\",\"sherif\"]", vars.get("developers"));
    assertEquals("3", vars.get("developers_matchNr"));
}
 
Example 3
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testYamlExtractor1() throws IOException {
    File test = new File(getClass().getResource("/test1.yml").getPath());
    String response = FileUtils.readFileToString(test);

    JMeterContext context = JMeterContextService.getContext();
    JMeterVariables vars = context.getVariables();

    SampleResult samplerResult = new SampleResult();
    samplerResult.setResponseData(response.getBytes());
    context.setPreviousResult(samplerResult);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setInputFormat(JSONPathExtractor.INPUT_YAML);
    instance.setDefaultValue("DEFAULT");
    instance.setVar("concurrency");
    instance.setJsonPath("$.execution[*].concurrency");
    instance.process();

    assertEquals("[100]", vars.get("concurrency"));

    instance.setJsonPath("execution[*].concurrency1");
    instance.process();
    assertEquals("DEFAULT", vars.get("concurrency"));
}
 
Example 4
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Ignore
@Test // FIXME: we need to solve this one day
public void testReported2() {
    System.out.println("process reported");
    JMeterContext context = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.setResponseData(json3.getBytes());
    context.setPreviousResult(res);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setVar("var");
    instance.setJsonPath("$.data[?(@.attr.value>0)][0].attr");
    instance.setDefaultValue("NOTFOUND");
    instance.process();
    JMeterVariables vars = context.getVariables();
    assertNotEquals("NOTFOUND", vars.get("var"));
    assertEquals("{value=1}", vars.get("var"));
}
 
Example 5
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testReported1_3() {
    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==Avtovaz)].id");
    instance.setDefaultValue("NOTFOUND");
    instance.process();
    JMeterVariables vars = context.getVariables();
    assertEquals("NOTFOUND", vars.get("GroupID"));
}
 
Example 6
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testReported1_1() {
    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[*].id");
    instance.setDefaultValue("NOTFOUND");
    instance.process();
    JMeterVariables vars = context.getVariables();
    assertNotEquals("NOTFOUND", vars.get("GroupID"));
    assertEquals("e02991f4-a95d-43dd-8eb0-fbc44349e238", vars.get("GroupID_1"));
}
 
Example 7
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@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"));
}
 
Example 8
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@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"));
}
 
Example 9
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcess() {
    System.out.println("process");
    JMeterContext context = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.setResponseData(json.getBytes());
    context.setPreviousResult(res);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setDefaultValue("DEFAULT");
    instance.setVar("test");
    instance.setJsonPath("$.store.book[*].author");
    instance.process();
    JMeterVariables vars = context.getVariables();
    assertEquals("[\"Nigel Rees\",\"Evelyn Waugh\",\"Herman Melville\",\"J. R. R. Tolkien\"]", vars.get("test"));
}
 
Example 10
Source File: JMXMonCollector.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
   * 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());
  }
 
Example 11
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcess_default() {
    System.out.println("process def");
    JMeterContext context = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    context.setPreviousResult(res);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setDefaultValue("DEFAULT");
    instance.setVar("test");
    instance.process();
    JMeterVariables vars = context.getVariables();
    assertEquals("DEFAULT", vars.get("test"));
}
 
Example 12
Source File: XMLFormatPostProcessorTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * Test of process method, of class XMLFormatPostProcessor.
 */
@Test
public void testProcess() {
    System.out.println("process");
    JMeterContext threadContext = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    threadContext.setPreviousResult(res);
    XMLFormatPostProcessor instance = new XMLFormatPostProcessor();
    instance.process();
    // TODO review the generated test code and remove the default call to fail.

}
 
Example 13
Source File: JSONFormatterTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcess_Failure() {
    System.out.println("process");
    JSONFormatter instance = new JSONFormatter();
    JMeterContext threadContext = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.setResponseData("<html>", "UTF8");
    threadContext.setPreviousResult(res);
    instance.process();
}
 
Example 14
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@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"));
}
 
Example 15
Source File: JSONFormatterTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcess_null() {
    System.out.println("process null");
    JSONFormatter instance = new JSONFormatter();
    JMeterContext threadContext = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.setResponseData("null", "UTF8");
    threadContext.setPreviousResult(res);
    instance.process();
}
 
Example 16
Source File: CaseFormatTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
	changeCase = new CaseFormat();
    result = new SampleResult();
    JMeterContext jmctx = JMeterContextService.getContext();
    String data = "dummy data";
    result.setResponseData(data, null);
    JMeterVariables vars = new JMeterVariables();
    jmctx.setVariables(vars);
    jmctx.setPreviousResult(result);
    params = new LinkedList<>();
}
 
Example 17
Source File: JSONFormatterTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcess_string() {
    System.out.println("process str");
    JSONFormatter instance = new JSONFormatter();
    JMeterContext threadContext = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.setResponseData("\"str\"", "UTF8");
    threadContext.setPreviousResult(res);
    instance.process();
}
 
Example 18
Source File: JSONFormatterTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcess_array() {
    System.out.println("process array");
    JSONFormatter instance = new JSONFormatter();
    JMeterContext threadContext = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.setResponseData("[]", "UTF8");
    threadContext.setPreviousResult(res);
    instance.process();
}
 
Example 19
Source File: DummySubPostProcessorTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    JMeterContext threadContext = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.sampleStart();
    res.sampleEnd();
    threadContext.setPreviousResult(res);
}
 
Example 20
Source File: JSONFormatterTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcess_dict() {
    System.out.println("process dict");
    JSONFormatter instance = new JSONFormatter();
    JMeterContext threadContext = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.setResponseData("{\"a\":1,\"b\":2}", "UTF8");
    threadContext.setPreviousResult(res);
    instance.process();
    Assert.assertEquals("{\n    \"a\": 1,\n    \"b\": 2\n}", res.getResponseDataAsString());
}