Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.control.TestFragmentController;
import org.apache.jmeter.gui.tree.JMeterTreeNode;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jorphan.collections.HashTree;
import org.apache.jorphan.collections.ListedHashTree;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -47,4 +49,26 @@ public void testTreeConversion() throws Exception {
assertEquals(tree.getTree(tree.getArray()[0]).getArray()[0].getClass().getName(), root.getTestElement()
.getClass().getName());
}

@Test
public void testTestFragmentNameIsPreservedForSingleFragmentSelection() {
TestFragmentController source = new TestFragmentController();
source.setName("My Test Fragment");
TestElement target = new TestFragmentController();

Save.setTestFragmentName(target, new JMeterTreeNode[] {new JMeterTreeNode(source, null)});

assertEquals("My Test Fragment", target.getName());
}

@Test
public void testTestFragmentNameIsNotCopiedForOtherSelections() {
TestElement target = new TestFragmentController();
target.setName("Test Fragment");
JMeterTreeNode source = new JMeterTreeNode(new Arguments(), null);

Save.setTestFragmentName(target, new JMeterTreeNode[] {source});

assertEquals("Test Fragment", target.getName());
}
}
11 changes: 10 additions & 1 deletion src/core/src/main/java/org/apache/jmeter/gui/action/Save.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import javax.swing.JOptionPane;
import javax.swing.tree.DefaultMutableTreeNode;

import org.apache.jmeter.control.TestFragmentController;
import org.apache.jmeter.control.gui.TestFragmentControllerGui;
import org.apache.jmeter.engine.TreeCloner;
import org.apache.jmeter.exceptions.IllegalUserActionException;
Expand Down Expand Up @@ -148,6 +149,7 @@ public void doAction(ActionEvent e) throws IllegalUserActionException {
else if (e.getActionCommand().equals(ActionNames.SAVE_AS_TEST_FRAGMENT)) {
JMeterTreeNode[] nodes = GuiPackage.getInstance().getTreeListener().getSelectedNodes();
if(checkAcceptableForTestFragment(nodes)) {
GuiPackage.getInstance().updateCurrentNode();
// Create Test Fragment node
subTree = createTestFragmentNode(nodes);
} else {
Expand Down Expand Up @@ -187,7 +189,8 @@ else if (e.getActionCommand().equals(ActionNames.SAVE_AS_TEST_FRAGMENT)) {
* @return {@link HashTree} new test plan
*/
private static HashTree createTestFragmentNode(JMeterTreeNode[] nodes) {
TestElement element = GuiPackage.getInstance().createTestElement(TestFragmentControllerGui.class.getName());
TestElement element = new TestFragmentControllerGui().createTestElement();
setTestFragmentName(element, nodes);
HashTree hashTree = new ListedHashTree();
HashTree tfTree = hashTree.add(new JMeterTreeNode(element, null));
for (JMeterTreeNode node : nodes) {
Expand All @@ -200,6 +203,12 @@ private static HashTree createTestFragmentNode(JMeterTreeNode[] nodes) {
return hashTree;
}

static void setTestFragmentName(TestElement target, JMeterTreeNode[] nodes) {
if (nodes.length == 1 && nodes[0].getTestElement() instanceof TestFragmentController) {
target.setName(nodes[0].getName());
}
}

/**
* @return String new file name or null if user want to cancel
*/
Expand Down
2 changes: 2 additions & 0 deletions xdocs/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ Summary
<li><pr>6879</pr>Show <code>File → Exit</code> again on Linux and Windows. It was hidden because Darklaf sets <code>apple.laf.useScreenMenuBar</code> on every platform; it is now hidden only on macOS, where the application menu provides Quit.</li>
<li><pr>6880</pr>Do not ask to save a test plan loaded at startup with <code>-t</code> when nothing was changed.</li>
<li><pr>6880</pr>Forget the previous file name when a template replaces the test plan, so Save asks for a new file instead of overwriting the plan that was open. Applying a template also no longer changes the folder which file dialogs open in.</li>
<li><pr>6934</pr><issue>6170</issue>Keep the name of a Test Fragment when saving it with <code>Save as Test Fragment</code>. Contributed by Orimarko (github.com/orimarko)</li>
<li><pr>6933</pr><issue>6929</issue>Allow distributed testing with RMI over SSL when <code>client.rmi.localport</code> is set. The SSL socket factories
now implement <code>equals</code>, so RMI shares the listening socket between the remote listeners of the controller instead of
failing with <code>Address already in use</code>. Contributed by Sander Yazıcıoglu (github.com/SanderYaz)</li>
Expand Down Expand Up @@ -205,6 +206,7 @@ Summary
<li>Patrick Uiterwijk (patrick at puiterwijk.org)</li>
<li>Piotr P. Karwasz (github.com/piotrgithub)</li>
<li>Andreas Lind (github.com/andreaslind01)</li>
<li>Orimarko (github.com/orimarko)</li>
<li>Sander Yazıcıoglu (github.com/SanderYaz)</li>
</ul>
<p>We also thank bug reporters who helped us improve JMeter.</p>
Expand Down
Loading