diff --git a/src/components/src/test/java/org/apache/jmeter/gui/action/TestSave.java b/src/components/src/test/java/org/apache/jmeter/gui/action/TestSave.java index ad20a90a20f..2c959b50b9a 100644 --- a/src/components/src/test/java/org/apache/jmeter/gui/action/TestSave.java +++ b/src/components/src/test/java/org/apache/jmeter/gui/action/TestSave.java @@ -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; @@ -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()); + } } diff --git a/src/core/src/main/java/org/apache/jmeter/gui/action/Save.java b/src/core/src/main/java/org/apache/jmeter/gui/action/Save.java index 225a1d297af..65069a179f6 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/action/Save.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/action/Save.java @@ -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; @@ -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 { @@ -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) { @@ -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 */ diff --git a/xdocs/changes.xml b/xdocs/changes.xml index f7cd1536686..624768bc6ac 100644 --- a/xdocs/changes.xml +++ b/xdocs/changes.xml @@ -168,6 +168,7 @@ Summary
File → Exit again on Linux and Windows. It was hidden because Darklaf sets apple.laf.useScreenMenuBar on every platform; it is now hidden only on macOS, where the application menu provides Quit.-t when nothing was changed.Save as Test Fragment. Contributed by Orimarko (github.com/orimarko)client.rmi.localport is set. The SSL socket factories
now implement equals, so RMI shares the listening socket between the remote listeners of the controller instead of
failing with Address already in use. Contributed by Sander Yazıcıoglu (github.com/SanderYaz)We also thank bug reporters who helped us improve JMeter.