You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by se...@apache.org on 2016/03/17 02:11:33 UTC

svn commit: r1735354 - in /jmeter/trunk: src/core/org/apache/jmeter/gui/SavePropertyDialog.java src/core/org/apache/jmeter/samplers/SampleSaveConfiguration.java test/src/org/apache/jmeter/samplers/TestSampleSaveConfiguration.java

Author: sebb
Date: Thu Mar 17 01:11:33 2016
New Revision: 1735354

URL: http://svn.apache.org/viewvc?rev=1735354&view=rev
Log:
Sample Result SaveConfig Dialog is generated in random order
Bugzilla Id: 59171

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/gui/SavePropertyDialog.java
    jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleSaveConfiguration.java
    jmeter/trunk/test/src/org/apache/jmeter/samplers/TestSampleSaveConfiguration.java

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/SavePropertyDialog.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/SavePropertyDialog.java?rev=1735354&r1=1735353&r2=1735354&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/SavePropertyDialog.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/SavePropertyDialog.java Thu Mar 17 01:11:33 2016
@@ -28,11 +28,7 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 import javax.swing.JButton;
@@ -64,7 +60,6 @@ public class SavePropertyDialog extends
     private static final String NAME_SAVE_PFX   = "save";  // $NON-NLS-1$ i.e. boolean saveXXX()
     private static final String NAME_SET_PREFIX = "set";   // $NON-NLS-1$ i.e. void setXXX(boolean)
     private static final String RESOURCE_PREFIX = "save_"; // $NON-NLS-1$ e.g. save_XXX property
-    private static final int    NAME_SAVE_PFX_LEN = NAME_SAVE_PFX.length();
 
     private SampleSaveConfiguration saveConfig;
 
@@ -86,59 +81,27 @@ public class SavePropertyDialog extends
         initDialog();
     }
 
-    private int countMethods(Method[] methods) {
-        int count = 0;
-        for (Method method : methods) {
-            if (method.getName().startsWith(NAME_SAVE_PFX)) {
-                count++;
-            }
-        }
-        return count;
-    }
-
     private void initDialog() {
         this.getContentPane().setLayout(new BorderLayout());
-        Method[] methods = SampleSaveConfiguration.class.getMethods();
-        int x = (countMethods(methods) / 3) + 1;
-        log.debug("grid panel is " + 3 + " by " + x);
-        JPanel checkPanel = new JPanel(new GridLayout(x, 3));
-        List<JCheckBox> checks = new ArrayList<>();
-        for (Method method : methods) {
-            String name = method.getName();
-            if (name.startsWith(NAME_SAVE_PFX) && method.getParameterTypes().length == 0) {
-                try {
-                    name = name.substring(NAME_SAVE_PFX_LEN);
-                    JCheckBox check = new JCheckBox(
-                            JMeterUtils.getResString(RESOURCE_PREFIX + name),
-                            ((Boolean) method.invoke(saveConfig, new Object[0])).booleanValue());
-                    checks.add(check);
-                    check.addActionListener(this);
-                    String actionCommand = NAME_SET_PREFIX + name; // $NON-NLS-1$
-                    check.setActionCommand(actionCommand);
-                    if (!functors.containsKey(actionCommand)) {
-                        functors.put(actionCommand, new Functor(actionCommand));
-                    }
-                } catch (IllegalAccessException | InvocationTargetException e) {
-                    log.warn("Problem creating save config dialog", e);
+        final int configCount = (SampleSaveConfiguration.SAVE_CONFIG_NAMES.size() / 3) + 1;
+        log.debug("grid panel is " + 3 + " by " + configCount);
+        JPanel checkPanel = new JPanel(new GridLayout(configCount, 3));
+        for (final String name : SampleSaveConfiguration.SAVE_CONFIG_NAMES) {
+            try {
+                JCheckBox check = new JCheckBox(
+                        JMeterUtils.getResString(RESOURCE_PREFIX + name),
+                        getSaveState(NAME_SAVE_PFX + name));
+                check.addActionListener(this);
+                final String actionCommand = NAME_SET_PREFIX + name; // $NON-NLS-1$
+                check.setActionCommand(actionCommand);
+                if (!functors.containsKey(actionCommand)) {
+                    functors.put(actionCommand, new Functor(actionCommand));
                 }
+                checkPanel.add(check, BorderLayout.NORTH);
+            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+                log.warn("Problem creating save config dialog", e);
             }
         }
-        // sortOrder is a temporary hack to allow easy testing of sort alternatives (Bug 59171)
-        final String sortOrder = JMeterUtils.getPropDefault("saveconfig.sort", "");
-        if (sortOrder.length() > 0) {
-            Collections.sort(checks, new Comparator<JCheckBox>(){
-                @Override
-                public int compare(JCheckBox o1, JCheckBox o2) {
-                    if ("text".equals(sortOrder)) {
-                        return o1.getText().compareToIgnoreCase(o2.getText()); // depends on language
-                    } else {
-                        return o1.getActionCommand().compareToIgnoreCase(o2.getActionCommand()); // propName
-                    }
-                }});            
-        }
-        for(JCheckBox check : checks) {
-            checkPanel.add(check, BorderLayout.NORTH);
-        }
         getContentPane().add(checkPanel, BorderLayout.NORTH);
         JButton exit = new JButton(JMeterUtils.getResString("done")); // $NON-NLS-1$
         this.getContentPane().add(exit, BorderLayout.SOUTH);
@@ -154,8 +117,12 @@ public class SavePropertyDialog extends
     public void actionPerformed(ActionEvent e) {
         String action = e.getActionCommand();
         Functor f = functors.get(action);
-        f.invoke(saveConfig, new Object[] {
-                Boolean.valueOf(((JCheckBox) e.getSource()).isSelected()) });
+        f.invoke(saveConfig, new Object[] {Boolean.valueOf(((JCheckBox) e.getSource()).isSelected()) });
+    }
+
+    private boolean getSaveState(String methodName) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+        Method method = SampleSaveConfiguration.class.getMethod(methodName);
+        return ((Boolean) method.invoke(saveConfig)).booleanValue();
     }
 
     /**

Modified: jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleSaveConfiguration.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleSaveConfiguration.java?rev=1735354&r1=1735353&r2=1735354&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleSaveConfiguration.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleSaveConfiguration.java Thu Mar 17 01:11:33 2016
@@ -24,6 +24,9 @@ package org.apache.jmeter.samplers;
 import java.io.Serializable;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
 import java.util.Properties;
 
 import org.apache.commons.lang3.CharUtils;
@@ -41,6 +44,7 @@ import org.apache.log.Logger;
  * - clone s.xyz = xyz (perhaps)
  * - setXyz(boolean)
  * - saveXyz()
+ * - add Xyz to SAVE_CONFIG_NAMES list
  * - update SampleSaveConfigurationConverter to add new fields to marshall() and shouldSerialiseMember()
  * - update ctor SampleSaveConfiguration(boolean value) to set the value if it is a boolean property
  * - update SampleResultConverter and/or HTTPSampleConverter
@@ -425,6 +429,42 @@ public class SampleSaveConfiguration imp
         return _static;
     }
 
+    /**
+     * List of saveXXX/setXXX(boolean) methods which is used to build the Sample Result Save Configuration dialog.
+     * New method names should be added at the end so that existing layouts are not affected.
+     */
+    // The current order is derived from http://jmeter.apache.org/usermanual/listeners.html#sample_configuration
+    // TODO this is not a particularly sensible order; fix and update the screenshot(s)
+    public static final List<String> SAVE_CONFIG_NAMES = Collections.unmodifiableList(Arrays.asList(new String[]{
+        "AsXml",
+        "FieldNames", // CSV
+        "AssertionResultsFailureMessage",
+        "ResponseHeaders", // XML
+        "RequestHeaders", // XML
+        "Assertions", // XML
+        "Code",
+        "DataType",
+        "Encoding",
+        "Label",
+        "Latency",
+        "Message",
+        "ResponseData", // XML
+        "SamplerData", // XML
+        "Subresults", // XML
+        "Success",
+        "ThreadName",
+        "Time",
+        "Timestamp",
+        "Url",
+        "Bytes",
+        "FileName",
+        "ThreadCounts",
+        "SampleCount",
+        "Hostname",
+        "IdleTime",
+        "ConnectTime",
+    }));
+    
     public SampleSaveConfiguration() {
     }
 

Modified: jmeter/trunk/test/src/org/apache/jmeter/samplers/TestSampleSaveConfiguration.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/samplers/TestSampleSaveConfiguration.java?rev=1735354&r1=1735353&r2=1735354&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/samplers/TestSampleSaveConfiguration.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/samplers/TestSampleSaveConfiguration.java Thu Mar 17 01:11:33 2016
@@ -24,7 +24,10 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertTrue;
 
+import java.lang.reflect.Method;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.jmeter.junit.JMeterTestCase;
 import org.junit.Test;
@@ -145,5 +148,32 @@ public class TestSampleSaveConfiguration
         assertTrue("Objects should be equal",b.equals(a));
     }
 
+    @Test
+    // Checks that all the saveXX() and setXXX(boolean) methods are in the list
+    public void testSaveConfigNames() throws Exception {
+        List<String> saveMethodNames = new ArrayList<>();
+        List<String> setMethodNames = new ArrayList<>();
+        Method[] methods = SampleSaveConfiguration.class.getMethods();
+        for(Method method : methods) {
+            String name = method.getName();
+            final String SAVE = "save";
+            if (name.startsWith(SAVE) && method.getParameterTypes().length == 0) {
+                name = name.substring(SAVE.length());
+                saveMethodNames.add(name);
+                assertTrue("SAVE_CONFIG_NAMES should contain save" + name, SampleSaveConfiguration.SAVE_CONFIG_NAMES.contains(name));
+            }
+            final String SET = "set";
+            if (name.startsWith(SET) && method.getParameterTypes().length == 1 && boolean.class.equals(method.getParameterTypes()[0])) {
+                name = name.substring(SET.length());
+                setMethodNames.add(name);
+                assertTrue("SAVE_CONFIG_NAMES should contain set" + name, SampleSaveConfiguration.SAVE_CONFIG_NAMES.contains(name));
+            }
+        }
+        for (String name : SampleSaveConfiguration.SAVE_CONFIG_NAMES) {
+            assertTrue("SAVE_CONFIG_NAMES should NOT contain save" + name, saveMethodNames.contains(name));
+            assertTrue("SAVE_CONFIG_NAMES should NOT contain set" + name, setMethodNames.contains(name));
+        }
+    }
+
  }