Search in sources :

Example 71 with JMeterContext

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

Example 72 with JMeterContext

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

Example 73 with JMeterContext

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");
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) SampleResult(org.apache.jmeter.samplers.SampleResult) URL(java.net.URL) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 74 with JMeterContext

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

Example 75 with JMeterContext

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"));
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) JSONPostProcessor(org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor) SampleResult(org.apache.jmeter.samplers.SampleResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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