Search in sources :

Example 6 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter-plugins by undera.

the class Env method execute.

/**
 * {@inheritDoc}
 */
@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
    String propertyName = values[0].execute();
    String propertyDefault = propertyName;
    if (values.length > 2) {
        // We have a 3rd parameter
        propertyDefault = values[2].execute();
    }
    String propertyValue = JMeterPluginsUtils.getEnvDefault(propertyName, propertyDefault);
    if (values.length > 1) {
        String variableName = values[1].execute();
        if (variableName.length() > 0) {
            // Allow for empty name
            final JMeterVariables variables = getVariables();
            if (variables != null) {
                variables.put(variableName, propertyValue);
            }
        }
    }
    return propertyValue;
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables)

Example 7 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter-plugins by undera.

the class IsDefined method execute.

/**
 * {@inheritDoc}
 */
@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
    JMeterVariables vars = getVariables();
    String res = ((CompoundVariable) values[0]).execute().trim();
    if (vars != null) {
        Object var = vars.getObject(res);
        if (var != null) {
            return "1";
        }
    }
    return "0";
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables)

Example 8 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter-plugins by undera.

the class LowerCase method execute.

/**
 * {@inheritDoc}
 */
@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
    JMeterVariables vars = getVariables();
    String res = ((CompoundVariable) values[0]).execute().toLowerCase();
    if (vars != null && values.length > 1) {
        String varName = ((CompoundVariable) values[1]).execute().trim();
        vars.put(varName, res);
    }
    return res;
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables)

Example 9 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter-plugins by undera.

the class StrLen method execute.

/**
 * {@inheritDoc}
 */
@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
    JMeterVariables vars = getVariables();
    Integer len = ((CompoundVariable) values[0]).execute().length();
    if (vars != null && values.length > 1) {
        String varName = ((CompoundVariable) values[1]).execute().trim();
        vars.put(varName, len.toString());
    }
    return len.toString();
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables)

Example 10 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter-plugins by undera.

the class StrReplace method execute.

@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
    String totalString = getParameter(0).replace(getParameter(1), getParameter(2));
    JMeterVariables vars = getVariables();
    if (values.length > 3) {
        String varName = getParameter(3);
        if (vars != null && varName != null && varName.length() > 0) {
            // vars will be null on TestPlan
            vars.put(varName, totalString);
        }
    }
    return totalString;
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables)

Aggregations

JMeterVariables (org.apache.jmeter.threads.JMeterVariables)193 SampleResult (org.apache.jmeter.samplers.SampleResult)71 JMeterContext (org.apache.jmeter.threads.JMeterContext)64 BeforeEach (org.junit.jupiter.api.BeforeEach)46 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)27 Test (org.junit.jupiter.api.Test)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 Test (org.junit.Test)16 JSONPostProcessor (org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor)11 Before (org.junit.Before)10 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 TestSampler (org.apache.jmeter.junit.stubs.TestSampler)6 TestPlan (org.apache.jmeter.testelement.TestPlan)6 HashMap (java.util.HashMap)5 ValueReplacer (org.apache.jmeter.engine.util.ValueReplacer)5 URL (java.net.URL)4 Arguments (org.apache.jmeter.config.Arguments)4 DebugSampler (org.apache.jmeter.sampler.DebugSampler)4