Author: pmouawad
Date: Sat Sep  8 16:27:24 2018
New Revision: 1840368

URL: http://svn.apache.org/viewvc?rev=1840368&view=rev
Log:
Bug 61834 - Function Helper Dialog : Improve tests by showing variables and 
keeping them available between evaluations
Bugzilla Id: 61834

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/functions/gui/FunctionHelper.java
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
    jmeter/trunk/xdocs/changes.xml

Modified: 
jmeter/trunk/src/core/org/apache/jmeter/functions/gui/FunctionHelper.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/functions/gui/FunctionHelper.java?rev=1840368&r1=1840367&r2=1840368&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/functions/gui/FunctionHelper.java 
(original)
+++ jmeter/trunk/src/core/org/apache/jmeter/functions/gui/FunctionHelper.java 
Sat Sep  8 16:27:24 2018
@@ -53,6 +53,11 @@ import org.apache.jmeter.gui.util.JSynta
 import org.apache.jmeter.gui.util.JTextScrollPane;
 import org.apache.jmeter.gui.util.VerticalPanel;
 import org.apache.jmeter.testelement.property.PropertyIterator;
+import org.apache.jmeter.threads.JMeterContext;
+import org.apache.jmeter.threads.JMeterContextService;
+import org.apache.jmeter.threads.JMeterThread;
+import org.apache.jmeter.threads.JMeterVariables;
+import org.apache.jmeter.threads.ThreadGroup;
 import org.apache.jmeter.util.JMeterUtils;
 import org.apache.jmeter.util.LocaleChangeEvent;
 import org.apache.jmeter.util.LocaleChangeListener;
@@ -68,6 +73,10 @@ public class FunctionHelper extends JDia
 
     private static final Logger log = 
LoggerFactory.getLogger(ClientJMeterEngine.class);
 
+    private static final String GENERATE = "GENERATE";
+    
+    private static final String RESET_VARS = "RESET_VARS";
+
     private JLabeledChoice functionList;
 
     private ArgumentsPanel parameterPanel;
@@ -75,6 +84,10 @@ public class FunctionHelper extends JDia
     private JLabeledTextField cutPasteFunction;
     
     private JSyntaxTextArea resultTextArea;
+    
+    private JSyntaxTextArea variablesTextArea;
+    
+    private JMeterVariables jMeterVariables = new JMeterVariables();
 
     public FunctionHelper() {
         super((JFrame) null, 
JMeterUtils.getResString("function_helper_title"), false); //$NON-NLS-1$
@@ -117,18 +130,31 @@ public class FunctionHelper extends JDia
         JPanel resultsPanel = new VerticalPanel();
         JPanel generatePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
         JPanel displayPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+        JPanel variablesPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
         cutPasteFunction = new 
JLabeledTextField(JMeterUtils.getResString("cut_paste_function"), 35, null, 
false); //$NON-NLS-1$
         generatePanel.add(cutPasteFunction);
         JButton generateButton = new 
JButton(JMeterUtils.getResString("generate")); //$NON-NLS-1$
+        generateButton.setActionCommand(GENERATE);
         generateButton.addActionListener(this);
         generatePanel.add(generateButton);
+
+        JButton resetVarsButton = new 
JButton(JMeterUtils.getResString("function_helper_reset_vars")); //$NON-NLS-1$
+        resetVarsButton.setActionCommand(RESET_VARS);
+        resetVarsButton.addActionListener(this);
+        generatePanel.add(resetVarsButton);
+
         resultTextArea = JSyntaxTextArea.getInstance(5,60);
         
resultTextArea.setToolTipText(JMeterUtils.getResString("function_helper_dialog_result_warn"));
         displayPanel.add(new 
JLabel(JMeterUtils.getResString("result_function")));
         displayPanel.add(JTextScrollPane.getInstance(resultTextArea));
+
+        variablesTextArea = JSyntaxTextArea.getInstance(10,60);
+        variablesPanel.add(new 
JLabel(JMeterUtils.getResString("function_helper_dialog_variables")));
+        variablesPanel.add(JTextScrollPane.getInstance(variablesTextArea));
         
         resultsPanel.add(generatePanel);
         resultsPanel.add(displayPanel);
+        resultsPanel.add(variablesPanel);
         
         this.getContentPane().add(resultsPanel, BorderLayout.SOUTH);
         this.pack();
@@ -175,22 +201,44 @@ public class FunctionHelper extends JDia
 
     @Override
     public void actionPerformed(ActionEvent e) {
-        String functionName = functionList.getText();
-        Arguments args = (Arguments) parameterPanel.createTestElement();
-        String functionCall = buildFunctionCallString(functionName, args);
-        cutPasteFunction.setText(functionCall);
-        GuiUtils.copyTextToClipboard(cutPasteFunction.getText());
-        CompoundVariable function = new CompoundVariable(functionCall);
-        try {
-            resultTextArea.setText(function.execute().trim());
-        } catch(Exception ex) {
-            log.error("Error calling function {}", functionCall, ex);
-            resultTextArea.setText(ex.getMessage() + ", \nstacktrace:\n "+
-                    ExceptionUtils.getStackTrace(ex));
-            resultTextArea.setCaretPosition(0);
+        String actionCommand = e.getActionCommand();
+        if(GENERATE.equals(actionCommand)) {
+            String functionName = functionList.getText();
+            Arguments args = (Arguments) parameterPanel.createTestElement();
+            String functionCall = buildFunctionCallString(functionName, args);
+            cutPasteFunction.setText(functionCall);
+            GuiUtils.copyTextToClipboard(cutPasteFunction.getText());
+            CompoundVariable function = new CompoundVariable(functionCall);
+            JMeterContext threadContext = JMeterContextService.getContext();
+            threadContext.setVariables(jMeterVariables);
+            threadContext.setThreadNum(1);
+            threadContext.getVariables().put(JMeterThread.LAST_SAMPLE_OK, 
"true");
+            ThreadGroup threadGroup = new ThreadGroup();
+            threadGroup.setName("FunctionHelper-Dialog-ThreadGroup");
+            threadContext.setThreadGroup(threadGroup);
+            
+            try {
+                resultTextArea.setText(function.execute().trim());
+            } catch(Exception ex) {
+                log.error("Error calling function {}", functionCall, ex);
+                resultTextArea.setText(ex.getMessage() + ", \nstacktrace:\n "+
+                        ExceptionUtils.getStackTrace(ex));
+                resultTextArea.setCaretPosition(0);
+            }
+            
+            variablesTextArea.setText(variablesToString(jMeterVariables));
+        } else {
+            jMeterVariables = new JMeterVariables();
+            variablesTextArea.setText(variablesToString(jMeterVariables));
         }
     }
 
+    private String variablesToString(JMeterVariables jMeterVariables) {
+        StringBuilder sb = new StringBuilder();
+        
jMeterVariables.entrySet().forEach(e->sb.append(e.getKey()).append("=").append(e.getValue()).append("\r\n"));
+        return sb.toString();
+    }
+
     private String buildFunctionCallString(String functionName, Arguments 
args) {
         StringBuilder functionCall = new StringBuilder("${");
         functionCall.append(functionName);

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=1840368&r1=1840367&r2=1840368&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties 
(original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Sat 
Sep  8 16:27:24 2018
@@ -374,6 +374,8 @@ ftp_save_response_data=Save File in Resp
 ftp_testing_title=FTP Request
 function_dialog_menu_item=Function Helper Dialog
 function_helper_dialog_result_warn=If function uses variables or a running 
context, results will not reflect reality
+function_helper_dialog_variables=Current JMeter Variables 
+function_helper_reset_vars=Reset Variables
 function_helper_title=Function Helper
 function_name_param=Name of variable in which to store the result (required)
 function_name_paropt=Name of variable in which to store the result (optional)

Modified: 
jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties?rev=1840368&r1=1840367&r2=1840368&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties 
(original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties 
Sat Sep  8 16:27:24 2018
@@ -369,6 +369,8 @@ ftp_testing_title=Requ\u00EAte FTP
 function_dialog_menu_item=Assistant de fonctions
 function_helper_dialog_result_warn=Si la fonction utilise des variables ou le 
contexte d'ex\u00E9cution, le r\u00E9sultat affich\u00E9 ne refl\u00E8te pas la 
r\u00E9alit\u00E9
 function_helper_title=Assistant de fonctions
+function_helper_dialog_variables=Variables JMeter actuelles 
+function_helper_reset_vars=R\u00E9initialiser Variables
 function_name_param=Nom de la fonction. Utilis\u00E9 pour stocker les valeurs 
\u00E0 utiliser ailleurs dans la plan de test
 function_name_paropt=Nom de variable dans laquelle le r\u00E9sultat sera 
stock\u00E9 (optionnel)
 function_params=Param\u00E8tres de fonction (Remplissez les valeurs ci-dessous 
et cliquez sur G\u00E9n\u00E9rer)

Modified: jmeter/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1840368&r1=1840367&r2=1840368&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sat Sep  8 16:27:24 2018
@@ -131,6 +131,7 @@ this behaviour, set <code>httpclient.res
     <li><bug>62178</bug>Add function <code>__threadGroupName</code> function 
to obtain ThreadGroup name. Mainly contributed by orimarko at gmail.com</li>
     <li><bug>62533</bug>Allow use epoch time as Date String value in function 
<code>__dateTimeConvert</code> </li>
     <li><bug>62541</bug>Allow <code>__jexl3</code>,<code>__jexl2</code> 
functions to support new syntax as <code>var x;</code>. Contributed by orimarko 
at gmail.com</li>
+    <li><bug>61834</bug>Function Helper Dialog : Improve tests by showing 
variables and keeping them available between evaluations</li>
 </ul>
 <h3>I18N</h3>
 <ul>


Reply via email to