mirror of https://github.com/apache/jmeter.git
Bug 61481 - Help Menu Item to export transaction for Web report
Bugzilla Id: 61481
git-svn-id: https://svn.apache.org/repos/asf/jmeter/trunk@1807067 13f79535-47bb-0310-9956-ffa450edef68
Former-commit-id: c6a218d62a
This commit is contained in:
parent
2495293ff5
commit
33672e4bc3
|
@ -48,6 +48,10 @@
|
||||||
# samples12:3000|4000;\
|
# samples12:3000|4000;\
|
||||||
# scenar01-12:5000|6000
|
# 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.
|
# Regular Expression which Indicates which samples to keep for graphs and statistics generation.
|
||||||
# Empty value means no filtering
|
# Empty value means no filtering
|
||||||
#jmeter.reportgenerator.sample_filter=
|
#jmeter.reportgenerator.sample_filter=
|
||||||
|
|
|
@ -96,3 +96,7 @@
|
||||||
|
|
||||||
# Indicates whether only controller samples are displayed on graphs that support it.
|
# Indicates whether only controller samples are displayed on graphs that support it.
|
||||||
#jmeter.reportgenerator.exporter.html.show_controllers_only=false
|
#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]*
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
|
@ -310,6 +310,9 @@ exit=Exit
|
||||||
find_target_element=Find target element
|
find_target_element=Find target element
|
||||||
expected_return_code_title=Expected Return Code:
|
expected_return_code_title=Expected Return Code:
|
||||||
expiration=Expiration
|
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\:
|
expression_field=CSS/JQuery expression\:
|
||||||
field_name=Field name
|
field_name=Field name
|
||||||
file=File
|
file=File
|
||||||
|
|
|
@ -304,6 +304,9 @@ example_title=Echantillon exemple
|
||||||
exit=Quitter
|
exit=Quitter
|
||||||
expected_return_code_title=Code retour attendu \:
|
expected_return_code_title=Code retour attendu \:
|
||||||
expiration=Expiration
|
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 \:
|
expression_field=Expression CSS/JQuery \:
|
||||||
field_name=Nom du champ
|
field_name=Nom du champ
|
||||||
file=Fichier
|
file=Fichier
|
||||||
|
|
|
@ -136,6 +136,7 @@ Incorporated feed back about unclear documentation.
|
||||||
|
|
||||||
<h3>Report / Dashboard</h3>
|
<h3>Report / Dashboard</h3>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li><bug>61481</bug>Help Menu Item to export transaction for Web report</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h3>General</h3>
|
<h3>General</h3>
|
||||||
|
|
Loading…
Reference in New Issue