diff --git a/src/core/src/main/java/org/apache/jmeter/control/gui/TransactionControllerGui.java b/src/core/src/main/java/org/apache/jmeter/control/gui/TransactionControllerGui.java index 1b4ea1aeb2d..ee513facade 100644 --- a/src/core/src/main/java/org/apache/jmeter/control/gui/TransactionControllerGui.java +++ b/src/core/src/main/java/org/apache/jmeter/control/gui/TransactionControllerGui.java @@ -17,12 +17,11 @@ package org.apache.jmeter.control.gui; -import javax.swing.JCheckBox; - import org.apache.jmeter.control.TransactionController; +import org.apache.jmeter.control.TransactionControllerSchema; import org.apache.jmeter.gui.GUIMenuSortOrder; +import org.apache.jmeter.gui.JBooleanPropertyEditor; import org.apache.jmeter.gui.TestElementMetadata; -import org.apache.jmeter.gui.util.CheckBoxPanel; import org.apache.jmeter.testelement.TestElement; import org.apache.jmeter.util.JMeterUtils; import org.apache.jorphan.gui.layout.VerticalLayout; @@ -37,40 +36,36 @@ public class TransactionControllerGui extends AbstractControllerGui { private static final long serialVersionUID = 240L; /** If selected, then generate parent sample, otherwise as per original controller */ - private JCheckBox generateParentSample; + private final JBooleanPropertyEditor generateParentSample = + new JBooleanPropertyEditor( + TransactionControllerSchema.INSTANCE.getGenearteParentSample(), + JMeterUtils.getResString("transaction_controller_parent")); /** if selected, add duration of timers to total runtime */ - private JCheckBox includeTimers; + private final JBooleanPropertyEditor includeTimers = + new JBooleanPropertyEditor( + TransactionControllerSchema.INSTANCE.getIncludeTimers(), + JMeterUtils.getResString("transaction_controller_include_timers")); /** * Create a new TransactionControllerGui instance. */ public TransactionControllerGui() { init(); + bindingGroup.add(generateParentSample); + bindingGroup.add(includeTimers); } @Override - public TestElement createTestElement() { - TransactionController lc = new TransactionController(); - lc.setIncludeTimers(false); // change default for new test elements - configureTestElement(lc); - return lc; - } - - @Override - public void configure(TestElement el) { - super.configure(el); - generateParentSample.setSelected(((TransactionController) el).isGenerateParentSample()); - includeTimers.setSelected(((TransactionController) el).isIncludeTimers()); + public TestElement makeTestElement() { + return new TransactionController(); } @Override - public void modifyTestElement(TestElement el) { - configureTestElement(el); - ((TransactionController) el).setGenerateParentSample(generateParentSample.isSelected()); - TransactionController tc = (TransactionController) el; - tc.setGenerateParentSample(generateParentSample.isSelected()); - tc.setIncludeTimers(includeTimers.isSelected()); + public void assignDefaultValues(TestElement element) { + super.assignDefaultValues(element); + // See https://github.com/apache/jmeter/issues/3282 + ((TransactionController) element).setIncludeTimers(false); } @Override @@ -85,9 +80,7 @@ private void init() { // WARNING: called from ctor so must not be overridden (i. setLayout(new VerticalLayout(5, VerticalLayout.BOTH, VerticalLayout.TOP)); setBorder(makeBorder()); add(makeTitlePanel()); - generateParentSample = new JCheckBox(JMeterUtils.getResString("transaction_controller_parent")); // $NON-NLS-1$ - add(CheckBoxPanel.wrap(generateParentSample)); - includeTimers = new JCheckBox(JMeterUtils.getResString("transaction_controller_include_timers"), true); // $NON-NLS-1$ - add(CheckBoxPanel.wrap(includeTimers)); + add(generateParentSample); + add(includeTimers); } } diff --git a/src/core/src/main/kotlin/org/apache/jmeter/threads/openmodel/gui/OpenModelThreadGroupGui.kt b/src/core/src/main/kotlin/org/apache/jmeter/threads/openmodel/gui/OpenModelThreadGroupGui.kt index a83f4ff6667..5188b1da8f3 100644 --- a/src/core/src/main/kotlin/org/apache/jmeter/threads/openmodel/gui/OpenModelThreadGroupGui.kt +++ b/src/core/src/main/kotlin/org/apache/jmeter/threads/openmodel/gui/OpenModelThreadGroupGui.kt @@ -24,6 +24,7 @@ import org.apache.jmeter.gui.TestElementMetadata import org.apache.jmeter.testelement.TestElement import org.apache.jmeter.threads.gui.AbstractThreadGroupGui import org.apache.jmeter.threads.openmodel.OpenModelThreadGroup +import org.apache.jmeter.threads.openmodel.OpenModelThreadGroupController import org.apache.jmeter.threads.openmodel.OpenModelThreadGroupSchema import org.apache.jmeter.threads.openmodel.ThreadSchedule import org.apache.jmeter.threads.openmodel.ThreadScheduleStep @@ -140,4 +141,9 @@ public class OpenModelThreadGroupGui : AbstractThreadGroupGui() { private fun evaluate(input: String): String = CompoundVariable(input).execute() override fun makeTestElement(): TestElement = OpenModelThreadGroup() + + override fun modifyTestElement(element: TestElement) { + super.modifyTestElement(element) + element[OpenModelThreadGroupSchema.mainController] = OpenModelThreadGroupController() + } } diff --git a/src/dist-check/src/test/java/org/apache/jmeter/junit/JMeterTest.java b/src/dist-check/src/test/java/org/apache/jmeter/junit/JMeterTest.java index f442cb64dc0..ed5ae0e55ad 100644 --- a/src/dist-check/src/test/java/org/apache/jmeter/junit/JMeterTest.java +++ b/src/dist-check/src/test/java/org/apache/jmeter/junit/JMeterTest.java @@ -53,6 +53,8 @@ import org.apache.jmeter.gui.UnsharedComponent; import org.apache.jmeter.gui.tree.JMeterTreeNode; import org.apache.jmeter.loadsave.IsEnabledNormalizer; +import org.apache.jmeter.protocol.http.control.gui.GraphQLHTTPSamplerGui; +import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBaseSchema; import org.apache.jmeter.save.SaveService; import org.apache.jmeter.testbeans.TestBean; import org.apache.jmeter.testbeans.gui.TestBeanGUI; @@ -279,6 +281,7 @@ private static Test suiteGUIComponents() throws Throwable { ts.addTest(new JMeterTest("GUIComponents2", item)); ts.addTest(new JMeterTest("saveLoadShouldKeepElementIntact", item)); ts.addTest(new JMeterTest("propertiesShouldNotBeInitializedToNullValues", item)); + ts.addTest(new JMeterTest("elementShouldNotBeModifiedWithConfigureModify", item)); ts.addTest(new JMeterTest("runGUITitle", item)); } suite.addTest(ts); @@ -300,6 +303,7 @@ private static Test suiteBeanComponents() throws Throwable { ts.addTest(new JMeterTest("GUIComponents2", item)); ts.addTest(new JMeterTest("saveLoadShouldKeepElementIntact", item)); ts.addTest(new JMeterTest("propertiesShouldNotBeInitializedToNullValues", item)); + ts.addTest(new JMeterTest("elementShouldNotBeModifiedWithConfigureModify", item)); ts.addTest(new JMeterTest("runGUITitle", item)); suite.addTest(ts); } catch (IllegalArgumentException e) { @@ -427,6 +431,39 @@ public void propertiesShouldNotBeInitializedToNullValues() { } } + public void elementShouldNotBeModifiedWithConfigureModify() { + TestElement expected = guiItem.createTestElement(); + TestElement actual = guiItem.createTestElement(); + guiItem.configure(actual); + if (!Objects.equals(expected, actual)) { + boolean breakpointForDebugging = Objects.equals(expected, actual); + String expectedStr = new DslPrinterTraverser(DslPrinterTraverser.DetailLevel.ALL).append(expected).toString(); + String actualStr = new DslPrinterTraverser(DslPrinterTraverser.DetailLevel.ALL).append(actual).toString(); + assertEquals( + "TestElement should not be modified by " + guiItem.getClass().getName() + ".configure(element)", + expectedStr, + actualStr + ); + } + guiItem.modifyTestElement(actual); + if (guiItem.getClass() == GraphQLHTTPSamplerGui.class) { + // GraphQL sampler computes its arguments, so we don't compare them + // See org.apache.jmeter.protocol.http.config.gui.GraphQLUrlConfigGui.modifyTestElement + expected.removeProperty(HTTPSamplerBaseSchema.INSTANCE.getArguments()); + actual.removeProperty(HTTPSamplerBaseSchema.INSTANCE.getArguments()); + } + if (!Objects.equals(expected, actual)) { + boolean breakpointForDebugging = Objects.equals(expected, actual); + String expectedStr = new DslPrinterTraverser(DslPrinterTraverser.DetailLevel.ALL).append(expected).toString(); + String actualStr = new DslPrinterTraverser(DslPrinterTraverser.DetailLevel.ALL).append(actual).toString(); + assertEquals( + "TestElement should not be modified by " + guiItem.getClass().getName() + ".configure(element); gui.modifyTestElement(element)", + expectedStr, + actualStr + ); + } + } + public void saveLoadShouldKeepElementIntact() throws IOException { TestElement expected = guiItem.createTestElement(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); @@ -442,7 +479,7 @@ private static void compareAllProperties(TestElement expected, TestElement actua String expectedStr = new DslPrinterTraverser(DslPrinterTraverser.DetailLevel.ALL).append(expected).toString(); if (!Objects.equals(expected, actual)) { - boolean abc = Objects.equals(expected, actual); + boolean breakpointForDebugging = Objects.equals(expected, actual); assertEquals( "TestElement after 'save+load' should match the one created in GUI\n" + "JMX is " + new String(serializedBytes, StandardCharsets.UTF_8), diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/GraphQLUrlConfigGui.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/GraphQLUrlConfigGui.java index d729b0e7727..fa2ced67245 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/GraphQLUrlConfigGui.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/GraphQLUrlConfigGui.java @@ -17,6 +17,8 @@ package org.apache.jmeter.protocol.http.config.gui; +import static org.apache.commons.lang3.StringUtils.defaultIfEmpty; + import java.awt.Component; import javax.swing.BorderFactory; @@ -93,9 +95,9 @@ public void modifyTestElement(TestElement element) { final GraphQLRequestParams params = new GraphQLRequestParams(operationNameText.getText(), queryContent.getText(), variablesContent.getText()); - element.setProperty(OPERATION_NAME, params.getOperationName()); - element.setProperty(QUERY, params.getQuery()); - element.setProperty(VARIABLES, params.getVariables()); + element.setProperty(OPERATION_NAME, defaultIfEmpty(params.getOperationName(), null)); + element.setProperty(QUERY, defaultIfEmpty(params.getQuery(), null)); + element.setProperty(VARIABLES, defaultIfEmpty(params.getVariables(), null)); element.setProperty(HTTPSamplerBase.POST_BODY_RAW, !HTTPConstants.GET.equals(method)); final Arguments args; diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java index e1c09a6f2c1..bb0ce92879e 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java @@ -238,7 +238,9 @@ public void modifyTestElement(TestElement element) { } public void assignDefaultValues(TestElement element) { - ((HTTPSamplerBase) element).setArguments(argsPanel.createTestElement()); + HTTPSamplerBase httpSampler = (HTTPSamplerBase) element; + httpSampler.setPostBodyRaw(false); + httpSampler.setArguments(argsPanel.createTestElement()); } // Just append all the parameter values, and use that as the post body diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/gui/GraphQLHTTPSamplerGui.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/gui/GraphQLHTTPSamplerGui.java index d8e2f83d1eb..f68eecf06e8 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/gui/GraphQLHTTPSamplerGui.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/gui/GraphQLHTTPSamplerGui.java @@ -41,8 +41,20 @@ public void assignDefaultValues(TestElement element) { super.assignDefaultValues(element); HTTPSamplerBaseSchema schema = HTTPSamplerBaseSchema.INSTANCE; element.set(schema.getMethod(), HTTPConstants.POST); - element.set(schema.getUseBrowserCompatibleMultipart(), false); - element.set(schema.getUseMultipartPost(), false); + element.set(schema.getPostBodyRaw(), true); + disableMultipart(element); + } + + @Override + public void modifyTestElement(TestElement sampler) { + super.modifyTestElement(sampler); + disableMultipart(sampler); + } + + private static void disableMultipart(TestElement sampler) { + HTTPSamplerBaseSchema schema = HTTPSamplerBaseSchema.INSTANCE; + sampler.set(schema.getUseBrowserCompatibleMultipart(), false); + sampler.set(schema.getUseMultipartPost(), false); } public GraphQLHTTPSamplerGui() { diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java index ca7234f8717..f5151b91d86 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java @@ -175,7 +175,8 @@ public void modifyTestElement(TestElement sampler) { } else { samplerBase.removeProperty(httpSchema.getIpSourceType()); } - samplerBase.set(httpSchema.getImplementation(), String.valueOf(httpImplementation.getSelectedItem())); + String selectedImplementation = String.valueOf(httpImplementation.getSelectedItem()); + samplerBase.set(httpSchema.getImplementation(), StringUtils.defaultIfBlank(selectedImplementation, null)); } } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/AuthPanel.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/AuthPanel.java index 28b44156d23..7a8daa666ea 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/AuthPanel.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/AuthPanel.java @@ -107,7 +107,8 @@ public AuthPanel() { public TestElement createTestElement() { AuthManager authMan = tableModel.manager; configureTestElement(authMan); - authMan.setClearEachIteration(clearEachIteration.isSelected()); + authMan.setClearEachIteration(false); + authMan.setControlledByThread(false); return (TestElement) authMan.clone(); } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/DNSCachePanel.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/DNSCachePanel.java index 3d97369041f..afa4bcae387 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/DNSCachePanel.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/DNSCachePanel.java @@ -140,10 +140,14 @@ public void modifyTestElement(TestElement dnsRes) { configureTestElement(dnsRes); if (dnsRes instanceof DNSCacheManager) { DNSCacheManager dnsCacheManager = (DNSCacheManager) dnsRes; + // Init servers list + dnsCacheManager.getServers(); for (int i = 0; i < dnsServersTableModel.getRowCount(); i++) { String server = (String) dnsServersTableModel.getRowData(i)[0]; dnsCacheManager.addServer(server); } + // Init hosts list + dnsCacheManager.getHosts(); for (int i = 0; i < dnsHostsTableModel.getRowCount(); i++) { String host = (String) dnsHostsTableModel.getRowData(i)[0]; String addresses = (String) dnsHostsTableModel.getRowData(i)[1]; @@ -188,10 +192,19 @@ private void populateHostsTable(DNSCacheManager resolver) { } @Override - public TestElement createTestElement() { - DNSCacheManager dnsCacheManager = new DNSCacheManager(); - modifyTestElement(dnsCacheManager); - return dnsCacheManager; + public TestElement makeTestElement() { + return new DNSCacheManager(); + } + + @Override + public void assignDefaultValues(TestElement element) { + super.assignDefaultValues(element); + DNSCacheManager manager = (DNSCacheManager) element; + // It sets empty list of servers and hosts + manager.getServers(); + manager.getHosts(); + manager.setClearEachIteration(true); + manager.setCustomResolver(false); } @Override diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/DefaultSamplerCreator.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/DefaultSamplerCreator.java index aa2fd9516da..e06ebda7ebc 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/DefaultSamplerCreator.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/DefaultSamplerCreator.java @@ -17,6 +17,8 @@ package org.apache.jmeter.protocol.http.proxy; +import static org.apache.commons.lang3.StringUtils.defaultIfEmpty; + import java.io.File; import java.io.IOException; import java.io.StringReader; @@ -174,9 +176,9 @@ private static void detectAndModifySamplerOnGraphQLRequest(final HTTPSamplerBase if (params != null) { sampler.setProperty(TestElement.GUI_CLASS, GraphQLHTTPSamplerGui.class.getName()); - sampler.setProperty(GraphQLUrlConfigGui.OPERATION_NAME, params.getOperationName()); - sampler.setProperty(GraphQLUrlConfigGui.QUERY, params.getQuery()); - sampler.setProperty(GraphQLUrlConfigGui.VARIABLES, params.getVariables()); + sampler.setProperty(GraphQLUrlConfigGui.OPERATION_NAME, defaultIfEmpty(params.getOperationName(), null)); + sampler.setProperty(GraphQLUrlConfigGui.QUERY, defaultIfEmpty(params.getQuery(), null)); + sampler.setProperty(GraphQLUrlConfigGui.VARIABLES, defaultIfEmpty(params.getVariables(), null)); } } diff --git a/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerPrintDslTest.kt b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerPrintDslTest.kt index 08882188224..589cb0308e3 100644 --- a/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerPrintDslTest.kt +++ b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerPrintDslTest.kt @@ -110,6 +110,7 @@ class HttpSamplerPrintDslTest : JMeterTestCase() { it[method] = "GET" it[followRedirects] = true it[useKeepalive] = true + it[postBodyRaw] = false } } @@ -139,6 +140,7 @@ class HttpSamplerPrintDslTest : JMeterTestCase() { it[method] = "GET" it[followRedirects] = true it[useKeepalive] = true + it[postBodyRaw] = false } } }.keys.first() as TestElement