jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1827141 - in /jmeter/trunk: src/functions/org/apache/jmeter/functions/Variable.java test/src/org/apache/jmeter/functions/VariableTest.java xdocs/changes.xml xdocs/usermanual/functions.xml
Date Sun, 18 Mar 2018 14:30:39 GMT
Author: pmouawad
Date: Sun Mar 18 14:30:39 2018
New Revision: 1827141

URL: http://svn.apache.org/viewvc?rev=1827141&view=rev
Log:
Bug 62178 - Add default value to __V function
Contributed by Orimarko
Bugzilla Id: 62178

Modified:
    jmeter/trunk/src/functions/org/apache/jmeter/functions/Variable.java
    jmeter/trunk/test/src/org/apache/jmeter/functions/VariableTest.java
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/functions.xml

Modified: jmeter/trunk/src/functions/org/apache/jmeter/functions/Variable.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/functions/org/apache/jmeter/functions/Variable.java?rev=1827141&r1=1827140&r2=1827141&view=diff
==============================================================================
--- jmeter/trunk/src/functions/org/apache/jmeter/functions/Variable.java (original)
+++ jmeter/trunk/src/functions/org/apache/jmeter/functions/Variable.java Sun Mar 18 14:30:39
2018
@@ -33,10 +33,11 @@ import org.apache.jmeter.util.JMeterUtil
  *
  * Parameters:
  * - variable name
+ * - default value
  *
  * Returns:
  * - the variable value, but if not found
- * - the variable name itself
+ * - the default value if set, and if not the variable name itself
  * @since 2.3RC3
  */
 public class Variable extends AbstractFunction {
@@ -47,25 +48,29 @@ public class Variable extends AbstractFu
 
     // Number of parameters expected - used to reject invalid calls
     private static final int MIN_PARAMETER_COUNT = 1;
-    private static final int MAX_PARAMETER_COUNT = 1;
+    private static final int MAX_PARAMETER_COUNT = 2;
 
     static {
         desc.add(JMeterUtils.getResString("variable_name_param")); //$NON-NLS-1$
+        desc.add(JMeterUtils.getResString("property_default_param")); //$NON-NLS-1$
     }
 
     private Object[] values;
 
-    public Variable() {
+    public Variable() { 
+        //used for test
     }
 
     /** {@inheritDoc} */
     @Override
-    public String execute(SampleResult previousResult, Sampler currentSampler)
-            throws InvalidVariableException {
+    public String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException
{
         String variableName = ((CompoundVariable) values[0]).execute();
+        String variableDefault = variableName;
+        if (values.length > 1) {
+            variableDefault = ((CompoundVariable) values[1]).execute();
+        }
         String variableValue = getVariables().get(variableName);
-        return variableValue == null? variableName : variableValue;
-
+        return variableValue == null ? variableDefault : variableValue;
     }
 
     /** {@inheritDoc} */

Modified: jmeter/trunk/test/src/org/apache/jmeter/functions/VariableTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/functions/VariableTest.java?rev=1827141&r1=1827140&r2=1827141&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/functions/VariableTest.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/functions/VariableTest.java Sun Mar 18 14:30:39
2018
@@ -57,7 +57,17 @@ public class VariableTest extends JMeter
         parms = makeParams("V",null,null);
         r.setParameters(parms);
         s = r.execute(null,null);
-        assertEquals("A",s);
+        assertEquals("A",s);        
+        
+        parms = makeParams("V","DEFAULT",null);
+        r.setParameters(parms);
+        s = r.execute(null,null);
+        assertEquals("A",s);        
+        
+        parms = makeParams("EMPTY","DEFAULT",null);
+        r.setParameters(parms);
+        s = r.execute(null,null);
+        assertEquals("DEFAULT",s);
         
         parms = makeParams("X",null,null);
         r.setParameters(parms);

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1827141&r1=1827140&r2=1827141&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sun Mar 18 14:30:39 2018
@@ -106,6 +106,7 @@ this behaviour, set <code>httpclient.res
 
 <h3>Functions</h3>
 <ul>
+    <li><bug>62178</bug>Add default value to <code>__V</code>
function. Contributed by orimarko at gmail.com</li>
 </ul>
 
 <h3>I18N</h3>

Modified: jmeter/trunk/xdocs/usermanual/functions.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/functions.xml?rev=1827141&r1=1827140&r2=1827141&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/functions.xml (original)
+++ jmeter/trunk/xdocs/usermanual/functions.xml Sun Mar 18 14:30:39 2018
@@ -1244,6 +1244,9 @@ i.intValue(); // or use i.longValue()
         <property name="Variable name" required="Yes">
         The variable to be evaluated. 
         </property>
+        <property name="Default value" required="No">
+        The default value in case no variable found, if it's empty and no variable found
function returns the variable name 
+        </property>
 </properties>
 </component>
 



Mime
View raw message