Lines 33-42
Link Here
|
33 |
* |
33 |
* |
34 |
* Parameters: |
34 |
* Parameters: |
35 |
* - variable name |
35 |
* - variable name |
|
|
36 |
* - default value |
36 |
* |
37 |
* |
37 |
* Returns: |
38 |
* Returns: |
38 |
* - the variable value, but if not found |
39 |
* - the variable value, but if not found |
39 |
* - the variable name itself |
40 |
* - the default value if sent, and if not the variable name itself |
40 |
* @since 2.3RC3 |
41 |
* @since 2.3RC3 |
41 |
*/ |
42 |
*/ |
42 |
public class Variable extends AbstractFunction { |
43 |
public class Variable extends AbstractFunction { |
Lines 47-73
Link Here
|
47 |
|
48 |
|
48 |
// Number of parameters expected - used to reject invalid calls |
49 |
// Number of parameters expected - used to reject invalid calls |
49 |
private static final int MIN_PARAMETER_COUNT = 1; |
50 |
private static final int MIN_PARAMETER_COUNT = 1; |
50 |
private static final int MAX_PARAMETER_COUNT = 1; |
51 |
private static final int MAX_PARAMETER_COUNT = 2; |
51 |
|
52 |
|
52 |
static { |
53 |
static { |
53 |
desc.add(JMeterUtils.getResString("variable_name_param")); //$NON-NLS-1$ |
54 |
desc.add(JMeterUtils.getResString("variable_name_param")); //$NON-NLS-1$ |
|
|
55 |
desc.add(JMeterUtils.getResString("property_default_param")); //$NON-NLS-1$ |
54 |
} |
56 |
} |
55 |
|
57 |
|
56 |
private Object[] values; |
58 |
private Object[] values; |
57 |
|
59 |
|
58 |
public Variable() { |
60 |
public Variable() { |
|
|
61 |
//used for test |
59 |
} |
62 |
} |
60 |
|
63 |
|
61 |
/** {@inheritDoc} */ |
64 |
/** {@inheritDoc} */ |
62 |
@Override |
65 |
@Override |
63 |
public String execute(SampleResult previousResult, Sampler currentSampler) |
66 |
public String execute(SampleResult previousResult, Sampler currentSampler) |
64 |
throws InvalidVariableException { |
67 |
throws InvalidVariableException { |
65 |
String variableName = ((CompoundVariable) values[0]).execute(); |
68 |
String variableName = ((CompoundVariable) values[0]).execute(); |
66 |
String variableValue = getVariables().get(variableName); |
69 |
String variableDefault = variableName; |
67 |
return variableValue == null? variableName : variableValue; |
70 |
if (values.length > 1) { |
|
|
71 |
variableDefault = ((CompoundVariable) values[1]).execute(); |
72 |
} |
73 |
String variableValue = getVariables().get(variableName); |
74 |
return variableValue == null ? variableDefault : variableValue; |
75 |
} |
68 |
|
76 |
|
69 |
} |
|
|
70 |
|
71 |
/** {@inheritDoc} */ |
77 |
/** {@inheritDoc} */ |
72 |
@Override |
78 |
@Override |
73 |
public void setParameters(Collection<CompoundVariable> parameters) throws InvalidVariableException { |
79 |
public void setParameters(Collection<CompoundVariable> parameters) throws InvalidVariableException { |