Search in sources :

Example 46 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.

the class TestJavascriptFunction method setUp.

@Before
public void setUp() {
    function = new JavaScript();
    result = new SampleResult();
    jmctx = JMeterContextService.getContext();
    String data = "The quick brown fox";
    result.setResponseData(data, null);
    vars = new JMeterVariables();
    jmctx.setVariables(vars);
    jmctx.setPreviousResult(result);
    params = new LinkedList<>();
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) SampleResult(org.apache.jmeter.samplers.SampleResult) Before(org.junit.Before)

Example 47 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.

the class TestMachineIPName method setUp.

@Before
public void setUp() {
    result = new SampleResult();
    jmctx = JMeterContextService.getContext();
    String data = "The quick brown fox";
    result.setResponseData(data, null);
    vars = new JMeterVariables();
    jmctx.setVariables(vars);
    jmctx.setPreviousResult(result);
    params = new LinkedList<>();
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) SampleResult(org.apache.jmeter.samplers.SampleResult) Before(org.junit.Before)

Example 48 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.

the class TestTimeFunction method setUp.

@Before
public void setUp() {
    jmctx = JMeterContextService.getContext();
    vars = new JMeterVariables();
    jmctx.setVariables(vars);
    jmctx.setPreviousResult(result);
    params = new LinkedList<>();
    result = new SampleResult();
    variable = new TimeFunction();
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) SampleResult(org.apache.jmeter.samplers.SampleResult) Before(org.junit.Before)

Example 49 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.

the class TestRandomFromMultipleVars method setUp.

@Before
public void setUp() {
    result = new SampleResult();
    jmctx = JMeterContextService.getContext();
    String data = "The quick brown fox";
    result.setResponseData(data, null);
    function = new RandomFromMultipleVars();
    vars = new JMeterVariables();
    jmctx.setVariables(vars);
    jmctx.setPreviousResult(result);
    params = new LinkedList<>();
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) SampleResult(org.apache.jmeter.samplers.SampleResult) Before(org.junit.Before)

Example 50 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.

the class TestHTTPSamplersAgainstHttpMirrorServer method testPostRequest_UrlEncoded.

private void testPostRequest_UrlEncoded(int samplerType, String samplerDefaultEncoding, int test) throws Exception {
    String titleField = "title";
    String titleValue = "mytitle";
    String descriptionField = "description";
    String descriptionValue = "mydescription";
    HTTPSamplerBase sampler = createHttpSampler(samplerType);
    HTTPSampleResult res;
    String contentEncoding;
    switch(test) {
        case 0:
            // Test sending data with default encoding
            contentEncoding = "";
            setupUrl(sampler, contentEncoding);
            setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
            res = executeSampler(sampler);
            checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
            break;
        case 1:
            // Test sending data as ISO-8859-1
            contentEncoding = ISO_8859_1;
            setupUrl(sampler, contentEncoding);
            setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
            res = executeSampler(sampler);
            checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
            break;
        case 2:
            // Test sending data as UTF-8
            contentEncoding = "UTF-8";
            titleValue = "mytitle2œ₡ĕÅ";
            descriptionValue = "mydescription2œ₡ĕÅ";
            setupUrl(sampler, contentEncoding);
            setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
            res = executeSampler(sampler);
            checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
            break;
        case 3:
            // Test sending data as UTF-8, with values that will change when urlencoded
            contentEncoding = "UTF-8";
            titleValue = "mytitle3/=";
            descriptionValue = "mydescription3   /\\";
            setupUrl(sampler, contentEncoding);
            setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
            res = executeSampler(sampler);
            checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
            break;
        case 4:
            // Test sending data as UTF-8, with values that have been urlencoded
            contentEncoding = "UTF-8";
            titleValue = "mytitle4%2F%3D";
            descriptionValue = "mydescription4+++%2F%5C";
            setupUrl(sampler, contentEncoding);
            setupFormData(sampler, true, titleField, titleValue, descriptionField, descriptionValue);
            res = executeSampler(sampler);
            checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, true);
            break;
        case 5:
            // Test sending data as UTF-8, with values similar to __VIEWSTATE parameter that .net uses
            contentEncoding = "UTF-8";
            titleValue = "/wEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ/rA+8DZ2dnZ2dnZ2d/GNDar6OshPwdJc=";
            descriptionValue = "mydescription5";
            setupUrl(sampler, contentEncoding);
            setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
            res = executeSampler(sampler);
            checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, false);
            break;
        case 6:
            // Test sending data as UTF-8, with values similar to __VIEWSTATE parameter that .net uses,
            // with values urlencoded, but the always encode set to false for the arguments
            // This is how the HTTP Proxy server adds arguments to the sampler
            contentEncoding = "UTF-8";
            titleValue = "%2FwEPDwULLTE2MzM2OTA0NTYPZBYCAgMPZ%2FrA%2B8DZ2dnZ2dnZ2d%2FGNDar6OshPwdJc%3D";
            descriptionValue = "mydescription6";
            setupUrl(sampler, contentEncoding);
            setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
            ((HTTPArgument) sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
            ((HTTPArgument) sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
            res = executeSampler(sampler);
            assertFalse(((HTTPArgument) sampler.getArguments().getArgument(0)).isAlwaysEncoded());
            assertFalse(((HTTPArgument) sampler.getArguments().getArgument(1)).isAlwaysEncoded());
            checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, titleValue, descriptionField, descriptionValue, true);
            break;
        case 7:
            // Test sending data as UTF-8, where user defined variables are used
            // to set the value for form data
            JMeterUtils.setLocale(Locale.ENGLISH);
            TestPlan testPlan = new TestPlan();
            JMeterVariables vars = new JMeterVariables();
            vars.put("title_prefix", "a testÅ");
            vars.put("description_suffix", "the_end");
            JMeterContextService.getContext().setVariables(vars);
            JMeterContextService.getContext().setSamplingStarted(true);
            ValueReplacer replacer = new ValueReplacer();
            replacer.setUserDefinedVariables(testPlan.getUserDefinedVariables());
            contentEncoding = "UTF-8";
            titleValue = "${title_prefix}mytitle7œ₡ĕÅ";
            descriptionValue = "mydescription7œ₡ĕÅ${description_suffix}";
            setupUrl(sampler, contentEncoding);
            setupFormData(sampler, false, titleField, titleValue, descriptionField, descriptionValue);
            // Replace the variables in the sampler
            replacer.replaceValues(sampler);
            res = executeSampler(sampler);
            String expectedTitleValue = "a testÅmytitle7œ₡ĕÅ";
            String expectedDescriptionValue = "mydescription7œ₡ĕÅthe_end";
            checkPostRequestUrlEncoded(sampler, res, samplerDefaultEncoding, contentEncoding, titleField, expectedTitleValue, descriptionField, expectedDescriptionValue, false);
            break;
        case 8:
            break;
        case 9:
            break;
        case 10:
            break;
        default:
            fail("Unexpected switch value: " + test);
    }
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) HTTPArgument(org.apache.jmeter.protocol.http.util.HTTPArgument) TestPlan(org.apache.jmeter.testelement.TestPlan) ValueReplacer(org.apache.jmeter.engine.util.ValueReplacer)

Aggregations

JMeterVariables (org.apache.jmeter.threads.JMeterVariables)96 SampleResult (org.apache.jmeter.samplers.SampleResult)35 JMeterContext (org.apache.jmeter.threads.JMeterContext)33 Before (org.junit.Before)33 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)17 Test (org.junit.Test)16 JSONPostProcessor (org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor)8 TestPlan (org.apache.jmeter.testelement.TestPlan)6 HashMap (java.util.HashMap)5 Sampler (org.apache.jmeter.samplers.Sampler)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ValueReplacer (org.apache.jmeter.engine.util.ValueReplacer)4 Properties (java.util.Properties)3 TestSampler (org.apache.jmeter.junit.stubs.TestSampler)3 Logger (org.slf4j.Logger)3 URL (java.net.URL)2 Arguments (org.apache.jmeter.config.Arguments)2 ReplaceStringWithFunctions (org.apache.jmeter.engine.util.ReplaceStringWithFunctions)2 HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)2