| 1 | |
package kg.apc.jmeter.functions; |
| 2 | |
|
| 3 | |
import org.apache.jmeter.engine.util.CompoundVariable; |
| 4 | |
import org.apache.jmeter.functions.AbstractFunction; |
| 5 | |
import org.apache.jmeter.functions.InvalidVariableException; |
| 6 | |
import org.apache.jmeter.samplers.SampleResult; |
| 7 | |
import org.apache.jmeter.samplers.Sampler; |
| 8 | |
import org.apache.jmeter.threads.JMeterVariables; |
| 9 | |
|
| 10 | |
import java.util.Collection; |
| 11 | |
import java.util.LinkedList; |
| 12 | |
import java.util.List; |
| 13 | |
|
| 14 | |
public class UpperCase extends AbstractFunction { |
| 15 | |
|
| 16 | 1 | private static final List<String> desc = new LinkedList<String>(); |
| 17 | |
private static final String KEY = "__uppercase"; |
| 18 | |
|
| 19 | |
static { |
| 20 | 1 | desc.add("String to convert to uppercase"); |
| 21 | 1 | desc.add("Name of variable in which to store the result (optional)"); |
| 22 | 1 | } |
| 23 | |
|
| 24 | |
private Object[] values; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | 4 | public UpperCase() { |
| 30 | 4 | } |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
@Override |
| 36 | |
public synchronized String execute(SampleResult previousResult, Sampler currentSampler) |
| 37 | |
throws InvalidVariableException { |
| 38 | 1 | JMeterVariables vars = getVariables(); |
| 39 | 1 | String res = ((CompoundVariable) values[0]).execute().toUpperCase(); |
| 40 | |
|
| 41 | 1 | if (vars != null && values.length > 1) { |
| 42 | 1 | String varName = ((CompoundVariable) values[1]).execute().trim(); |
| 43 | 1 | vars.put(varName, res); |
| 44 | |
} |
| 45 | |
|
| 46 | 1 | return res; |
| 47 | |
|
| 48 | |
} |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
@Override |
| 54 | |
public synchronized void setParameters(Collection<CompoundVariable> parameters) throws InvalidVariableException { |
| 55 | 2 | checkMinParameterCount(parameters, 1); |
| 56 | 2 | values = parameters.toArray(); |
| 57 | 2 | } |
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
@Override |
| 63 | |
public String getReferenceKey() { |
| 64 | 1 | return KEY; |
| 65 | |
} |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
@Override |
| 71 | |
public List<String> getArgumentDesc() { |
| 72 | 1 | return desc; |
| 73 | |
} |
| 74 | |
} |