You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2017/09/02 18:15:22 UTC

svn commit: r1807067 - in /jmeter/trunk: bin/ src/components/org/apache/jmeter/gui/ src/components/org/apache/jmeter/gui/action/ src/core/org/apache/jmeter/resources/ xdocs/

Author: pmouawad
Date: Sat Sep  2 18:15:22 2017
New Revision: 1807067

URL: http://svn.apache.org/viewvc?rev=1807067&view=rev
Log:
Bug 61481 - Help Menu Item to export transaction for Web report
Bugzilla Id: 61481

Added:
    jmeter/trunk/src/components/org/apache/jmeter/gui/
    jmeter/trunk/src/components/org/apache/jmeter/gui/action/
    jmeter/trunk/src/components/org/apache/jmeter/gui/action/ExportTransactionAndSamplerNames.java   (with props)
Modified:
    jmeter/trunk/bin/reportgenerator.properties
    jmeter/trunk/bin/user.properties
    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/bin/reportgenerator.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/bin/reportgenerator.properties?rev=1807067&r1=1807066&r2=1807067&view=diff
==============================================================================
--- jmeter/trunk/bin/reportgenerator.properties (original)
+++ jmeter/trunk/bin/reportgenerator.properties Sat Sep  2 18:15:22 2017
@@ -48,6 +48,10 @@
 #                                            samples12:3000|4000;\
 #                                            scenar01-12:5000|6000 
 
+# This property is used by menu item "Export transactions for report"
+# It is used to select which transactions by default will be exported
+#jmeter.reportgenerator.exported_transactions_pattern=[a-zA-Z0-9_\\-{}\\$\\.]*[-_][0-9]*
+
 # Regular Expression which Indicates which samples to keep for graphs and statistics generation.
 # Empty value means no filtering
 #jmeter.reportgenerator.sample_filter=

Modified: jmeter/trunk/bin/user.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/bin/user.properties?rev=1807067&r1=1807066&r2=1807067&view=diff
==============================================================================
--- jmeter/trunk/bin/user.properties (original)
+++ jmeter/trunk/bin/user.properties Sat Sep  2 18:15:22 2017
@@ -96,3 +96,7 @@
 
 # Indicates whether only controller samples are displayed on graphs that support it.
 #jmeter.reportgenerator.exporter.html.show_controllers_only=false
+
+# This property is used by menu item "Export transactions for report"
+# It is used to select which transactions by default will be exported
+#jmeter.reportgenerator.exported_transactions_pattern=[a-zA-Z0-9_\\-{}\\$\\.]*[-_][0-9]*

Added: jmeter/trunk/src/components/org/apache/jmeter/gui/action/ExportTransactionAndSamplerNames.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/gui/action/ExportTransactionAndSamplerNames.java?rev=1807067&view=auto
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/gui/action/ExportTransactionAndSamplerNames.java (added)
+++ jmeter/trunk/src/components/org/apache/jmeter/gui/action/ExportTransactionAndSamplerNames.java Sat Sep  2 18:15:22 2017
@@ -0,0 +1,212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.gui.action;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.swing.JLabel;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.MenuElement;
+import javax.swing.SwingUtilities;
+
+import org.apache.jmeter.control.TransactionController;
+import org.apache.jmeter.gui.GuiPackage;
+import org.apache.jmeter.gui.plugin.MenuCreator;
+import org.apache.jmeter.gui.tree.JMeterTreeNode;
+import org.apache.jmeter.gui.util.EscapeDialog;
+import org.apache.jmeter.gui.util.JSyntaxTextArea;
+import org.apache.jmeter.gui.util.JTextScrollPane;
+import org.apache.jmeter.gui.util.VerticalPanel;
+import org.apache.jmeter.sampler.DebugSampler;
+import org.apache.jmeter.sampler.TestAction;
+import org.apache.jmeter.samplers.Sampler;
+import org.apache.jmeter.testelement.TestElement;
+import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.collections.HashTree;
+import org.apache.jorphan.collections.HashTreeTraverser;
+import org.apache.jorphan.gui.ComponentUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Export transactions names for web report
+ * @since 3.3
+ */
+public class ExportTransactionAndSamplerNames extends AbstractAction implements MenuCreator {
+    private static final Logger log = LoggerFactory.getLogger(ExportTransactionAndSamplerNames.class);
+    
+    private static final String TRANSACTIONS_REGEX_PATTERN = 
+            JMeterUtils.getPropDefault("jmeter.reportgenerator.exported_transactions_pattern", 
+                    "[a-zA-Z0-9_\\-{}\\$\\.]*[-_][0-9]*");
+    
+    private static final Pattern TRANSACTIONS_REGEX = 
+            Pattern.compile(TRANSACTIONS_REGEX_PATTERN);
+    
+    private static final Set<String> commands = new HashSet<>();
+
+    private static final String EXPORT_NAMES = "export_trans_names";
+    
+
+    static {
+        commands.add(EXPORT_NAMES);
+    }
+
+    /**
+     * Visitor to collect nodes matching the name
+     */
+    private static class SamplerAndTransactionNameVisitor implements HashTreeTraverser {
+        private Set<String> listOfTransactions = new TreeSet<>();
+        public SamplerAndTransactionNameVisitor() {
+            super();
+        }
+        @Override
+        public void addNode(Object object, HashTree subTree) {
+            JMeterTreeNode treeNode = (JMeterTreeNode) object;
+            Object userObject = treeNode.getUserObject();
+            
+            if (userObject instanceof TransactionController
+                    || (userObject instanceof Sampler && !(userObject instanceof TestAction) 
+                            && !(userObject instanceof DebugSampler))) {
+                Matcher matcher = TRANSACTIONS_REGEX.matcher(((TestElement)userObject).getName());
+                if(!matcher.matches()) {
+                    listOfTransactions.add(((TestElement)userObject).getName());
+                }
+            }
+        }
+
+        @Override
+        public void subtractNode() {
+            // NOOP
+        }
+        @Override
+        public void processPath() {
+            // NOOP
+        }
+        /**
+         * @return the listOfTransactions
+         */
+        public Set<String> getListOfTransactions() {
+            return listOfTransactions;
+        }
+    }
+
+
+    public ExportTransactionAndSamplerNames() {
+        super();
+    }
+
+    /**
+     * @see Command#doAction(ActionEvent)
+     */
+    @Override
+    public void doAction(ActionEvent e) {
+        HashTree wholeTree = GuiPackage.getInstance().getTreeModel().getTestPlan();
+        SamplerAndTransactionNameVisitor visitor = new SamplerAndTransactionNameVisitor();
+        wholeTree.traverse(visitor);
+        Set<String> sampleNames = visitor.getListOfTransactions();
+        if(sampleNames.isEmpty()) {
+            log.warn("No transaction exported using regexp '{}', modify property '{}' to fix this problem",
+                    TRANSACTIONS_REGEX_PATTERN, "report_transactions_pattern");
+            showResult("No transaction exported using regexp '"
+                    +TRANSACTIONS_REGEX_PATTERN
+                    +"', modify property 'report_transactions_pattern' to fix this problem");
+        } else {
+            StringBuilder builder = new StringBuilder();
+            for (String sampleName : sampleNames) {
+                builder.append(sampleName).append('|');
+            }
+            builder.setLength(builder.length()-1);
+            String result = builder.toString();
+            log.info("Exported transactions: jmeter.reportgenerator.exporter.html.series_filter=^({})(-success|-failure)?$", 
+                    result);
+
+            showResult("jmeter.reportgenerator.exporter.html.series_filter=^("
+                    +result
+                    +")(-success|-failure)?$");
+            
+        }
+    }
+
+    /**
+     * Display result in popup
+     * @param result String 
+     */
+    private static final void showResult(String result) {
+        EscapeDialog messageDialog = new EscapeDialog(GuiPackage.getInstance().getMainFrame(),
+                JMeterUtils.getResString("export_transactions_title"), true); //$NON-NLS-1$
+        VerticalPanel verticalPanel = new VerticalPanel();
+        messageDialog.getContentPane().add(verticalPanel);
+        verticalPanel.add(new JLabel(
+                JMeterUtils.getResString("export_transactions_exported_property")));//$NON-NLS-1$
+        JSyntaxTextArea syntaxTextArea = JSyntaxTextArea.getInstance(10, 80, true);
+        syntaxTextArea.setText(result);
+        syntaxTextArea.setCaretPosition(0);
+        verticalPanel.add(JTextScrollPane.getInstance(syntaxTextArea));
+        messageDialog.pack();
+        ComponentUtil.centerComponentInComponent(GuiPackage.getInstance().getMainFrame(), messageDialog);
+        SwingUtilities.invokeLater(() -> messageDialog.setVisible(true));
+    }
+
+
+    /**
+     * @see Command#getActionNames()
+     */
+    @Override
+    public Set<String> getActionNames() {
+        return commands;
+    }
+
+    @Override
+    public JMenuItem[] getMenuItemsAtLocation(MENU_LOCATION location) {
+        if(location == MENU_LOCATION.HELP) {
+            
+            JMenuItem menuItemIC = new JMenuItem(
+                    JMeterUtils.getResString("export_transactions_menu"), KeyEvent.VK_UNDEFINED);
+            menuItemIC.setName(ExportTransactionAndSamplerNames.EXPORT_NAMES);
+            menuItemIC.setActionCommand(ExportTransactionAndSamplerNames.EXPORT_NAMES);
+            menuItemIC.setAccelerator(null);
+            menuItemIC.addActionListener(ActionRouter.getInstance());
+
+            return new JMenuItem[]{menuItemIC};
+        }
+        return new JMenuItem[0];
+    }
+
+    @Override
+    public JMenu[] getTopLevelMenus() {
+        return new JMenu[0];
+    }
+
+    @Override
+    public boolean localeChanged(MenuElement menu) {
+        return false;
+    }
+
+    @Override
+    public void localeChanged() {
+        // NOOP
+    }
+}

Propchange: jmeter/trunk/src/components/org/apache/jmeter/gui/action/ExportTransactionAndSamplerNames.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jmeter/trunk/src/components/org/apache/jmeter/gui/action/ExportTransactionAndSamplerNames.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=1807067&r1=1807066&r2=1807067&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  2 18:15:22 2017
@@ -310,6 +310,9 @@ exit=Exit
 find_target_element=Find target element
 expected_return_code_title=Expected Return Code: 
 expiration=Expiration
+export_transactions_exported_property=Dashboard report property value
+export_transactions_menu=Export transactions for report
+export_transactions_title=Export Transactions Result
 expression_field=CSS/JQuery expression\:
 field_name=Field name
 file=File

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=1807067&r1=1807066&r2=1807067&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  2 18:15:22 2017
@@ -304,6 +304,9 @@ example_title=Echantillon exemple
 exit=Quitter
 expected_return_code_title=Code retour attendu \: 
 expiration=Expiration
+export_transactions_exported_property=Valeur de la propri\u00E9t\u00E9 du rapport
+export_transactions_menu=Exporter transactions pour rapport
+export_transactions_title=Export des transactions 
 expression_field=Expression CSS/JQuery \:
 field_name=Nom du champ
 file=Fichier

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1807067&r1=1807066&r2=1807067&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sat Sep  2 18:15:22 2017
@@ -136,6 +136,7 @@ Incorporated feed back about unclear doc
 
 <h3>Report / Dashboard</h3>
 <ul>
+    <li><bug>61481</bug>Help Menu Item to export transaction for Web report</li>
 </ul>
 
 <h3>General</h3>