You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2008/10/09 19:53:10 UTC

svn commit: r703217 - in /jakarta/jmeter/trunk: docs/images/screenshots/ src/core/org/apache/jmeter/control/ src/core/org/apache/jmeter/control/gui/ src/core/org/apache/jmeter/resources/ xdocs/ xdocs/images/screenshots/ xdocs/usermanual/

Author: sebb
Date: Thu Oct  9 10:53:10 2008
New Revision: 703217

URL: http://svn.apache.org/viewvc?rev=703217&view=rev
Log:
Allow If Controller to use variable expressions (not just Javascript)

Modified:
    jakarta/jmeter/trunk/docs/images/screenshots/ifcontroller.png
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/IfController.java
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/gui/IfControllerPanel.java
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jakarta/jmeter/trunk/xdocs/changes.xml
    jakarta/jmeter/trunk/xdocs/images/screenshots/ifcontroller.png
    jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jakarta/jmeter/trunk/docs/images/screenshots/ifcontroller.png
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/docs/images/screenshots/ifcontroller.png?rev=703217&r1=703216&r2=703217&view=diff
==============================================================================
Binary files - no diff available.

Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/IfController.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/IfController.java?rev=703217&r1=703216&r2=703217&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/IfController.java (original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/IfController.java Thu Oct  9 10:53:10 2008
@@ -29,7 +29,6 @@
 
 /*******************************************************************************
  *
- * @author Cyrus Montakab created 2003/06/30
  *
  * This is a Conditional Controller; it will execute the set of statements
  * (samplers/controllers, etc) while the 'condition' is true.
@@ -47,6 +46,8 @@
  *
  ******************************************************************************/
 
+// for unit test code @see TestIfController
+
 public class IfController extends GenericController implements Serializable {
 
     private static final Logger logger = LoggingManager.getLoggerForClass();
@@ -55,6 +56,8 @@
 
     private final static String EVALUATE_ALL = "IfController.evaluateAll"; //$NON-NLS-1$
 
+    private static final String USE_EXPRESSION = "IfController.useExpression"; //$NON-NLS-1$
+
     /**
      * constructor
      */
@@ -87,7 +90,7 @@
     /**
      * evaluate the condition clause log error if bad condition
      */
-    static boolean evaluateCondition(String cond) {
+    private static boolean evaluateCondition(String cond) {
         logger.debug("    getCondition() : [" + cond + "]");
 
         String resultStr = "";
@@ -120,6 +123,10 @@
         return result;
     }
 
+    private static boolean evaluateExpression(String cond) {
+        return cond.equalsIgnoreCase("true"); // $NON-NLS-1$
+    }
+
     /**
      * This is overriding the parent method. IsDone indicates whether the
      * termination condition is reached. I.e. if the condition evaluates to
@@ -148,7 +155,10 @@
         // so then we just pass the control to the next item inside the if control
         boolean result = true;
         if(isEvaluateAll() || isFirst()) {
-            result = evaluateCondition(getCondition());
+            result = isUseExpression() ? 
+                    evaluateExpression(getCondition())
+                    :
+                    evaluateCondition(getCondition());
         }
 
         if (result) {
@@ -168,4 +178,12 @@
     public void setEvaluateAll(boolean b) {
         setProperty(EVALUATE_ALL,b);
     }
+
+    public boolean isUseExpression() {
+        return getPropertyAsBoolean(USE_EXPRESSION, false);
+    }
+
+    public void setUseExpression(boolean selected) {
+        setProperty(USE_EXPRESSION, selected, false);
+    }
 }

Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/gui/IfControllerPanel.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/gui/IfControllerPanel.java?rev=703217&r1=703216&r2=703217&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/gui/IfControllerPanel.java (original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/gui/IfControllerPanel.java Thu Oct  9 10:53:10 2008
@@ -48,6 +48,8 @@
      */
     private JTextField theCondition;
 
+    private JCheckBox useExpression;
+    
     private JCheckBox evaluateAll;
 
     /**
@@ -94,6 +96,7 @@
             IfController ifController = (IfController) element;
             theCondition.setText(ifController.getCondition());
             evaluateAll.setSelected(ifController.isEvaluateAll());
+            useExpression.setSelected(ifController.isUseExpression());
         }
 
     }
@@ -116,6 +119,7 @@
             IfController ifController = (IfController) controller;
             ifController.setCondition(theCondition.getText());
             ifController.setEvaluateAll(evaluateAll.isSelected());
+            ifController.setUseExpression(useExpression.isSelected());
         }
     }
 
@@ -185,9 +189,17 @@
         conditionPanel.add(Box.createHorizontalStrut(conditionLabel.getPreferredSize().width
                 + theCondition.getPreferredSize().width), BorderLayout.NORTH);
 
+        JPanel optionPanel = new JPanel();
+        
+        // Use expression instead of Javascript
+        useExpression = new JCheckBox(JMeterUtils.getResString("if_controller_expression")); // $NON-NLS-1$
+        optionPanel.add(useExpression);
+        
         // Evaluate All checkbox
         evaluateAll = new JCheckBox(JMeterUtils.getResString("if_controller_evaluate_all")); // $NON-NLS-1$
-        conditionPanel.add(evaluateAll,BorderLayout.SOUTH);
+        optionPanel.add(evaluateAll);
+
+        conditionPanel.add(optionPanel,BorderLayout.SOUTH);
         return conditionPanel;
     }
 }
\ No newline at end of file

Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=703217&r1=703216&r2=703217&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Thu Oct  9 10:53:10 2008
@@ -290,8 +290,9 @@
 httpmirror_title=HTTP Mirror Server
 id_prefix=ID Prefix
 id_suffix=ID Suffix
+if_controller_expression=Interpret Condition as Variable Expression?
 if_controller_evaluate_all=Evaluate for all children?
-if_controller_label=Condition (Javascript)
+if_controller_label=Condition (default Javascript)
 if_controller_title=If Controller
 ignore_subcontrollers=Ignore sub-controller blocks
 include_controller=Include Controller

Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=703217&r1=703216&r2=703217&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Thu Oct  9 10:53:10 2008
@@ -133,6 +133,7 @@
 <li>Bug 45571 - JMS Sampler correlation enhancement</li>
 <li>Bug 45479 - Support for multiple HTTP Header Manager nodes</li>
 <li>Bug 43119 - Save Responses to file: optionally omit the file number</li>
+<li>Allow If Controller to use variable expressions (not just Javascript)</li>
 </ul>
 
 <h3>Non-functional changes</h3>

Modified: jakarta/jmeter/trunk/xdocs/images/screenshots/ifcontroller.png
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/images/screenshots/ifcontroller.png?rev=703217&r1=703216&r2=703217&view=diff
==============================================================================
Binary files - no diff available.

Modified: jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=703217&r1=703216&r2=703217&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml Thu Oct  9 10:53:10 2008
@@ -1474,7 +1474,7 @@
 </properties>
 </component>
 
-<component name="If Controller" index="&sect-num;.2.9"  width="358" height="131" screenshot="ifcontroller.png">
+<component name="If Controller" index="&sect-num;.2.9"  width="489" height="145" screenshot="ifcontroller.png">
 	<description>
 		<p>The If Controller allows the user to control whether the test elements below it (its children) are run or not.</p>
 		<p>
@@ -1483,16 +1483,31 @@
 		However, the original behaviour is also useful, so versions of JMeter after 2.3RC4 have an additional
 		option to select the original behaviour.
 		</p>
+		<p>
+		Versions of JMeter after 2.3.2 allow the script to be processed as a variable expression, rather than requiring Javascript.
+		It was always possible to use functions and variables in the Javascript condition, so long as they evaluated to "true" or "false";
+		now this can be done without the overhead of using Javascript as well. For example, previously one could use the condition:
+		<code>${__jexl(${VAR} == 23)}</code> and this would be evaluated as true/false, the result would then be passed to Javascript
+		which would then return true/false. If the Variable Expression option is selected, then the expression is evaluated
+		and compared with "true", without needing to use Javascript. 
+		Also, variable expressions can return any value, whereas the
+		Javascript condition must return "true"/"false" or an error is logged.
+		</p>
 	</description>
 <properties>
     <property name="Name" required="No">Descriptive name for this controller that is shown in the tree.</property>
-	<property name="Condition" required="Yes"><b>Javascript</b> code that returns "true" or "false"</property>
+	<property name="Condition (default Javascript)" required="Yes">By default the condition is interpreted as <b>Javascript</b> code that returns "true" or "false",
+	but this can be overriden (see below)</property>
+	<property name="Interpret Condition as Variable Expression?" required="Yes">If this is selected, then the condition must be an expression that evaluates to "true" (case is ignored).
+	For example, <code>${FOUND}</code> or <code>${__jexl(${VAR} > 100)}</code>.
+	Unlike the Javascript case, the condition is only checked to see if it matches "true" (case is ignored). 
+	</property>
 	<property name="Evaluate for all children" required="Yes">
 	Should condition be evaluated for all children?
 	If not checked, then the condition is only evaluated on entry.
 	</property>
 </properties>
-	<p>Examples:
+	<p><b>Examples (Javascript):</b>
 		<ul>
 			<li>${COUNT} &lt; 10</li>
 			<li>"${VAR}" == "abcd"</li>
@@ -1500,6 +1515,12 @@
 		</ul>
 		If there is an error interpreting the code, the condition is assumed to be false, and a message is logged in jmeter.log.
 	</p>
+    <p><b>Examples (Variable Expression):</b>
+        <ul>
+            <li>${__jexl(${COUNT} &lt; 10)}</li>
+            <li>${RESULT}</li>
+        </ul>
+	</p>
 </component>
 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org