From 78b94dd56679171519181ca432d39e2da200124e Mon Sep 17 00:00:00 2001 From: pochopsp Date: Tue, 11 Jun 2024 23:55:33 +0200 Subject: [PATCH 01/10] feat: Add checkbox to enable/disable params in HTTP Sampler Added a new "isEnabledFromGui" property in HTTPArgument used to determine whether to include the argument in the request or not. This property is set by the user for each HTTP parameter by clicking on the "Enable" column put on the very left of each parameter row. Fixes https://github.com/apache/jmeter/issues/5466 --- bin/testfiles/TEST_HTTP.jmx | 12 ++++++++ bin/testfiles/load_bug_list.jmx | 30 +++++++++++++++++++ .../jmeter/resources/messages.properties | 1 + .../jmeter/resources/messages_de.properties | 1 + .../jmeter/resources/messages_es.properties | 1 + .../jmeter/resources/messages_fr.properties | 1 + .../jmeter/resources/messages_ja.properties | 1 + .../jmeter/resources/messages_ko.properties | 1 + .../jmeter/resources/messages_pl.properties | 1 + .../resources/messages_pt_BR.properties | 1 + .../jmeter/resources/messages_tr.properties | 1 + .../resources/messages_zh_CN.properties | 1 + .../resources/messages_zh_TW.properties | 1 + .../http/config/gui/UrlConfigGui.java | 3 ++ .../protocol/http/gui/HTTPArgumentsPanel.java | 13 ++++++-- .../protocol/http/sampler/HTTPHC4Impl.java | 9 ++++++ .../http/sampler/HTTPSamplerBase.java | 3 ++ .../protocol/http/sampler/PutWriter.java | 3 ++ .../protocol/http/util/HTTPArgument.java | 11 ++++++- .../protocol/http/util/HTTPArgumentSchema.kt | 3 ++ 20 files changed, 94 insertions(+), 4 deletions(-) diff --git a/bin/testfiles/TEST_HTTP.jmx b/bin/testfiles/TEST_HTTP.jmx index da93b79e0a8..574867cadb2 100644 --- a/bin/testfiles/TEST_HTTP.jmx +++ b/bin/testfiles/TEST_HTTP.jmx @@ -159,6 +159,7 @@ mirrorServer.start(); false + true value1 = true @@ -219,6 +220,7 @@ mirrorServer.start(); false + true Get with body = @@ -532,6 +534,7 @@ mirrorServer.start(); false + true Method has body = @@ -599,6 +602,7 @@ mirrorServer.start(); false + true We have a body = @@ -740,6 +744,7 @@ mirrorServer.start(); false + true value1 = true @@ -792,6 +797,7 @@ mirrorServer.start(); false + true value1 = true @@ -859,6 +865,7 @@ mirrorServer.start(); false + true value1 = true @@ -866,6 +873,7 @@ mirrorServer.start(); false + true value2 = true @@ -948,6 +956,7 @@ if(prev.getSamplerData().indexOf(textToCheck) < 0) { false + true Veni vidi vici = @@ -1327,6 +1336,7 @@ if(prev.getSamplerData().indexOf(textToCheck) < 0) { false + true Body of Put = @@ -1410,6 +1420,7 @@ if(prev.getSamplerData().indexOf(textToCheck) < 0) { false + true value1 = true @@ -1491,6 +1502,7 @@ if(prev.getSamplerData().indexOf(textToCheck) < 0) { false + true value1 = true diff --git a/bin/testfiles/load_bug_list.jmx b/bin/testfiles/load_bug_list.jmx index e0dc7dd55c6..ee0a73ecbf1 100644 --- a/bin/testfiles/load_bug_list.jmx +++ b/bin/testfiles/load_bug_list.jmx @@ -10,6 +10,7 @@ true bug_status false + true = @@ -17,6 +18,7 @@ true bug_status false + true = @@ -24,6 +26,7 @@ true bug_status false + true = @@ -31,6 +34,7 @@ true email1 false + true = @@ -38,6 +42,7 @@ true emailtype1 false + true = @@ -45,6 +50,7 @@ true emailassigned_to1 false + true = @@ -52,6 +58,7 @@ true email2 false + true = @@ -59,6 +66,7 @@ true emailtype2 false + true = @@ -66,6 +74,7 @@ true emailreporter2 false + true = @@ -73,6 +82,7 @@ true bugidtype false + true = @@ -80,6 +90,7 @@ true bug_id false + true = @@ -87,6 +98,7 @@ true changedin false + true = @@ -94,6 +106,7 @@ true votes false + true = @@ -101,6 +114,7 @@ true chfieldfrom false + true = @@ -108,6 +122,7 @@ true chfieldto false + true = @@ -115,6 +130,7 @@ true chfieldvalue false + true = @@ -122,6 +138,7 @@ true product false + true = @@ -129,6 +146,7 @@ true short_desc false + true = @@ -136,6 +154,7 @@ true short_desc_type false + true = @@ -143,6 +162,7 @@ true long_desc false + true = @@ -150,6 +170,7 @@ true long_desc_type false + true = @@ -157,6 +178,7 @@ true bug_file_loc false + true = @@ -164,6 +186,7 @@ true bug_file_loc_type false + true = @@ -171,42 +194,49 @@ true keywords false + true = anywords keywords_type false + true = noop field0-0-0 false + true = noop type0-0-0 false + true = value0-0-0 false + true = doit cmdtype false + true = Reuse same sort as last time order true + true diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages.properties index 23721c4b4c9..34fd5628891 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages.properties @@ -319,6 +319,7 @@ editable_checkbox.use_expression=Use Expression email_results_title=Email Results en=English enable=Enable +enabled_from_gui=Enable encode=URL Encode encode?=URL Encode? encoded_value=URL Encoded Value diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_de.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_de.properties index f7ebe01ce32..557568c978f 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_de.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_de.properties @@ -153,6 +153,7 @@ edit=Bearbeiten email_results_title=Ergebnisse per eMail verschicken en=Englisch enable=Aktivieren +enabled_from_gui=Aktivieren encode?=Encodieren? encoded_value=URL-Encodierter Wert entry_dn=Ausgangs DN diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_es.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_es.properties index 47642121ba1..1ba7393732b 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_es.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_es.properties @@ -183,6 +183,7 @@ edit=Editar email_results_title=Resultados del Email en=Inglés enable=Habilitar +enabled_from_gui=Habilitar encode?=¿Codificar? encoded_value=Valor de URL Codificada entry_dn=Introduzca DN diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_fr.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_fr.properties index ed0f7be54d1..d2ac577bac1 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_fr.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_fr.properties @@ -314,6 +314,7 @@ editable_checkbox.use_expression=Utiliser l'expression email_results_title=Résultat d'email en=Anglais enable=Activer +enabled_from_gui=Activer encode=URL Encoder encode?=URL Encoder encoded_value=Valeur de l'URL encodée diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_ja.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_ja.properties index 2af6236635c..92db3e820a6 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_ja.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_ja.properties @@ -110,6 +110,7 @@ edit=編集 email_results_title=結果をメールで送信 en=英語 enable=有効 +enabled_from_gui=有効 encoded_value=URLエンコード値 entry_dn=エントリDN error_loading_help=ヘルプページロード中のエラー diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_ko.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_ko.properties index 4d337f1d160..b08b071c006 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_ko.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_ko.properties @@ -317,6 +317,7 @@ edit=편집 email_results_title=결과들을 전자우편으로 보내기 en=영어 enable=활성화 +enabled_from_gui=활성화 encode=URL 인코드 encode?=URL 인코드? encoded_value=URL 인코딩된 값 diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_pl.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_pl.properties index 8f4118ef871..41890b8d0dc 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_pl.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_pl.properties @@ -150,6 +150,7 @@ duration=Czas trwania (sekund) edit=Edytuj en=Angielski enable=Włącz +enabled_from_gui=Włącz error_loading_help=Wystąpił błąd przy próbie wyświetlenia strony z pomocą error_occurred=Wystąpił błąd error_title=Błąd diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_pt_BR.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_pt_BR.properties index 25df3162657..0e5cf366244 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_pt_BR.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_pt_BR.properties @@ -175,6 +175,7 @@ edit=Editar email_results_title=Enviar Resultados por Email en=Inglês enable=Habilitar +enabled_from_gui=Habilitar encode?=Codificar? encoded_value=Valor da URL Codificada entry_dn=Entrada DN diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_tr.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_tr.properties index 556b934cdb3..99e2ee08c66 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_tr.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_tr.properties @@ -162,6 +162,7 @@ edit=Düzenle email_results_title=E-posta Sonuçları en=İngilizce enable=Etkinleştir +enabled_from_gui=Etkinleştir encode?=Kodlama? encoded_value=URL Kodlanmış Değer entry_dn=Giriş DN'i diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_CN.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_CN.properties index 26cff3b953f..86a04da811e 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_CN.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_CN.properties @@ -303,6 +303,7 @@ edit=编辑 email_results_title=电子邮件结果 en=英语 enable=启用 +enabled_from_gui=启用 encode=URL编码 encode?=编码? encoded_value=URL编码后的值 diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_TW.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_TW.properties index a1681b42a3e..c03041fe9e5 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_TW.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_TW.properties @@ -135,6 +135,7 @@ edit=編輯 email_results_title=電郵結果 en=英文 enable=啟動 +enabled_from_gui=啟動 encode?=編碼? encoded_value=URL 編碼值 entry_dn=進入 DN 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 bb0ce92879e..f1760b6f8bf 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 @@ -263,6 +263,9 @@ private static String computePostBody(Arguments arguments, boolean crlfToLF) { StringBuilder postBody = new StringBuilder(); for (JMeterProperty argument : arguments) { HTTPArgument arg = (HTTPArgument) argument.getObjectValue(); + if (!arg.isEnabledFromGui()) { + continue; // Skip parameters if they've been disabled from GUI using the checkbox + } String value = arg.getValue(); if (crlfToLF) { value = value.replaceAll("\r\n", "\n"); // See modifyTestElement diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/HTTPArgumentsPanel.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/HTTPArgumentsPanel.java index 1f4af2befa2..03d3eea68f2 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/HTTPArgumentsPanel.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/HTTPArgumentsPanel.java @@ -39,12 +39,15 @@ /** * A GUI panel allowing the user to enter HTTP Parameters. * These have names and values, as well as check-boxes to determine whether or not to - * include the "=" sign in the output and whether or not to encode the output. + * include the "=" sign in the output and whether or not to encode the output and + * whether or not to enable them. */ public class HTTPArgumentsPanel extends ArgumentsPanel { private static final long serialVersionUID = 240L; + private static final String ENABLED_FROM_GUI = "enabled_from_gui"; //$NON-NLS-1$ + private static final String ENCODE_OR_NOT = "encode?"; //$NON-NLS-1$ private static final String INCLUDE_EQUALS = "include_equals"; //$NON-NLS-1$ @@ -60,21 +63,23 @@ public class HTTPArgumentsPanel extends ArgumentsPanel { @Override protected void initializeTableModel() { tableModel = new ObjectTableModel(new String[] { - ArgumentsPanel.COLUMN_RESOURCE_NAMES_0, ArgumentsPanel.COLUMN_RESOURCE_NAMES_1, ENCODE_OR_NOT, CONTENT_TYPE, INCLUDE_EQUALS }, + ENABLED_FROM_GUI, ArgumentsPanel.COLUMN_RESOURCE_NAMES_0, ArgumentsPanel.COLUMN_RESOURCE_NAMES_1, ENCODE_OR_NOT, CONTENT_TYPE, INCLUDE_EQUALS }, HTTPArgument.class, new Functor[] { + new Functor("isEnabledFromGui"), //$NON-NLS-1$ new Functor("getName"), //$NON-NLS-1$ new Functor("getValue"), //$NON-NLS-1$ new Functor("isAlwaysEncoded"), //$NON-NLS-1$ new Functor("getContentType"), //$NON-NLS-1$ new Functor("isUseEquals") }, //$NON-NLS-1$ new Functor[] { + new Functor("setEnabledFromGui"), //$NON-NLS-1$ new Functor("setName"), //$NON-NLS-1$ new Functor("setValue"), //$NON-NLS-1$ new Functor("setAlwaysEncoded"), //$NON-NLS-1$ new Functor("setContentType"), new Functor("setUseEquals")}, //$NON-NLS-1$ - new Class[] {String.class, String.class, Boolean.class, String.class, Boolean.class }); + new Class[] {Boolean.class, String.class, String.class, Boolean.class, String.class, Boolean.class }); } public static boolean testFunctors(){ @@ -85,6 +90,7 @@ public static boolean testFunctors(){ @Override protected void sizeColumns(JTable table) { + GuiUtils.fixSize(table.getColumn(ENABLED_FROM_GUI), table); GuiUtils.fixSize(table.getColumn(INCLUDE_EQUALS), table); GuiUtils.fixSize(table.getColumn(ENCODE_OR_NOT), table); } @@ -92,6 +98,7 @@ protected void sizeColumns(JTable table) { @Override protected HTTPArgument makeNewArgument() { HTTPArgument arg = new HTTPArgument("", ""); + arg.setEnabledFromGui(true); arg.setAlwaysEncoded(false); arg.setUseEquals(true); return arg; diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java index bc4478eecb3..37e13d4fde4 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java @@ -1577,6 +1577,9 @@ protected String setupHttpEntityEnclosingRequestData(HttpEntityEnclosingRequestB if (arg.isSkippable(parameterName)) { continue; } + if (!arg.isEnabledFromGui()) { + continue; // Skip parameters if they've been disabled from GUI using the checkbox + } ContentType contentType; if (arg.getContentType().indexOf(';') >= 0) { // assume, that the content type contains charset info @@ -1655,6 +1658,9 @@ else if(ADD_CONTENT_TYPE_TO_POST_IF_MISSING) { StringBuilder postBody = new StringBuilder(); for (JMeterProperty jMeterProperty : getArguments()) { HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue(); + if (!arg.isEnabledFromGui()) { + continue; // Skip parameters if they've been disabled from GUI using the checkbox + } postBody.append(arg.getEncodedValue(contentEncoding)); } // Let StringEntity perform the encoding @@ -1807,6 +1813,9 @@ private UrlEncodedFormEntity createUrlEncodedFormEntity(final String urlContentE if (arg.isSkippable(parameterName)) { continue; } + if (!arg.isEnabledFromGui()) { + continue; // Skip parameters if they've been disabled from GUI using the checkbox + } String parameterValue = arg.getValue(); if (!arg.isAlwaysEncoded()) { // The value is already encoded by the user diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java index 3b3b37d0141..cdbbd52a98d 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java @@ -1189,6 +1189,9 @@ public String getQueryString(final String contentEncoding) { if (encodedName.isEmpty()) { continue; // Skip parameters with a blank name (allows use of optional variables in parameter lists) } + if(!item.isEnabledFromGui()){ + continue; // Skip parameters if they've been disabled from GUI using the checkbox + } if (!first) { buf.append(QRY_SEP); } else { diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PutWriter.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PutWriter.java index d6f5c87cd59..2b2bb8f670b 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PutWriter.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PutWriter.java @@ -86,6 +86,9 @@ else if(sampler.getSendParameterValuesAsPostBody()) { StringBuilder putBodyBuffer = new StringBuilder(); for (JMeterProperty jMeterProperty : sampler.getArguments()) { HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue(); + if (!arg.isEnabledFromGui()) { + continue; // Skip parameters if they've been disabled from GUI using the checkbox + } putBodyBuffer.append(arg.getEncodedValue(contentEncoding)); } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java index 3353589b1f8..5e2eb3ef354 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java @@ -70,6 +70,14 @@ public HTTPArgumentSchema getSchema() { return new PropertiesAccessor<>(this, getSchema()); } + public void setEnabledFromGui(boolean enabledFromGui) { + set(getSchema().getEnabledFromGui(), enabledFromGui); + } + + public boolean isEnabledFromGui() { + return get(getSchema().getEnabledFromGui()); + } + public void setUseEquals(boolean ue) { if (ue) { setMetaData("="); @@ -134,7 +142,7 @@ public HTTPArgument(String name, String value, boolean alreadyEncoded) { } /** - * Construct a new HTTPArgument instance; alwaysEncoded is set to true. + * Construct a new HTTPArgument instance; enabledFromGui and alwaysEncoded are set to true. * * @param name the name of the parameter * @param value the value of the parameter @@ -142,6 +150,7 @@ public HTTPArgument(String name, String value, boolean alreadyEncoded) { * @param contentEncoding the encoding used for the parameter value */ public HTTPArgument(String name, String value, boolean alreadyEncoded, String contentEncoding) { + setEnabledFromGui(true); setAlwaysEncoded(true); if (alreadyEncoded) { try { diff --git a/src/protocol/http/src/main/kotlin/org/apache/jmeter/protocol/http/util/HTTPArgumentSchema.kt b/src/protocol/http/src/main/kotlin/org/apache/jmeter/protocol/http/util/HTTPArgumentSchema.kt index 0c2cec15ed3..3710af665a9 100644 --- a/src/protocol/http/src/main/kotlin/org/apache/jmeter/protocol/http/util/HTTPArgumentSchema.kt +++ b/src/protocol/http/src/main/kotlin/org/apache/jmeter/protocol/http/util/HTTPArgumentSchema.kt @@ -30,6 +30,9 @@ import org.apiguardian.api.API public abstract class HTTPArgumentSchema : ArgumentSchema() { public companion object INSTANCE : HTTPArgumentSchema() + public val enabledFromGui: BooleanPropertyDescriptor + by boolean("HTTPArgument.enabled_from_gui") + public val alwaysEncode: BooleanPropertyDescriptor by boolean("HTTPArgument.always_encode") From 49ba9cb301a1ea0f4ee5d8b77bf38b2aa8dc50fa Mon Sep 17 00:00:00 2001 From: pochopsp Date: Sun, 16 Jun 2024 23:50:15 +0200 Subject: [PATCH 02/10] Add missing enabled_from_gui to HTTPArgument in test files --- bin/testfiles/GuiTest231.jmx | 2 ++ bin/testfiles/GuiTest231_original.jmx | 2 ++ bin/testfiles/Modification Manager.jmx | 2 ++ bin/testfiles/SavedGuiTest231.jmx | 2 ++ 4 files changed, 8 insertions(+) diff --git a/bin/testfiles/GuiTest231.jmx b/bin/testfiles/GuiTest231.jmx index 7f847e05141..25e189758cf 100644 --- a/bin/testfiles/GuiTest231.jmx +++ b/bin/testfiles/GuiTest231.jmx @@ -145,6 +145,7 @@ false + true Value = true @@ -395,6 +396,7 @@ false + true Value = true diff --git a/bin/testfiles/GuiTest231_original.jmx b/bin/testfiles/GuiTest231_original.jmx index 8e0b0b4abe1..370d80a05b7 100644 --- a/bin/testfiles/GuiTest231_original.jmx +++ b/bin/testfiles/GuiTest231_original.jmx @@ -145,6 +145,7 @@ false + true Value = true @@ -410,6 +411,7 @@ false + true Value = true diff --git a/bin/testfiles/Modification Manager.jmx b/bin/testfiles/Modification Manager.jmx index 9228ab5ed6e..1ba17a4a323 100644 --- a/bin/testfiles/Modification Manager.jmx +++ b/bin/testfiles/Modification Manager.jmx @@ -24,6 +24,7 @@ true request.job_id true + true request.job_id .* @@ -33,6 +34,7 @@ true request.action1 true + true request.action1 opjobadmin.action.inspect diff --git a/bin/testfiles/SavedGuiTest231.jmx b/bin/testfiles/SavedGuiTest231.jmx index 50bbed3082c..76c5841a166 100644 --- a/bin/testfiles/SavedGuiTest231.jmx +++ b/bin/testfiles/SavedGuiTest231.jmx @@ -145,6 +145,7 @@ false + true Value = true @@ -395,6 +396,7 @@ false + true Value = true From aee2a6503832dcfc68ab69d9437822ba95ff5372 Mon Sep 17 00:00:00 2001 From: pochopsp Date: Fri, 8 Nov 2024 22:18:24 +0100 Subject: [PATCH 03/10] Use TestElementSchema.enabled instead of new HTTPArgumentSchema.enabledFromGui --- bin/testfiles/TEST_HTTP.jmx | 13 +------- bin/testfiles/load_bug_list.jmx | 30 ------------------- .../jmeter/resources/messages.properties | 1 - .../jmeter/resources/messages_de.properties | 1 - .../jmeter/resources/messages_es.properties | 1 - .../jmeter/resources/messages_fr.properties | 1 - .../jmeter/resources/messages_ja.properties | 1 - .../jmeter/resources/messages_ko.properties | 1 - .../jmeter/resources/messages_pl.properties | 1 - .../resources/messages_pt_BR.properties | 1 - .../jmeter/resources/messages_tr.properties | 1 - .../resources/messages_zh_CN.properties | 1 - .../resources/messages_zh_TW.properties | 1 - .../http/config/gui/UrlConfigGui.java | 2 +- .../protocol/http/gui/HTTPArgumentsPanel.java | 11 ++++--- .../protocol/http/sampler/HTTPHC4Impl.java | 6 ++-- .../http/sampler/HTTPSamplerBase.java | 2 +- .../protocol/http/sampler/PutWriter.java | 2 +- .../protocol/http/util/HTTPArgument.java | 12 ++------ .../protocol/http/util/HTTPArgumentSchema.kt | 3 -- 20 files changed, 14 insertions(+), 78 deletions(-) diff --git a/bin/testfiles/TEST_HTTP.jmx b/bin/testfiles/TEST_HTTP.jmx index 574867cadb2..1f1a3006d97 100644 --- a/bin/testfiles/TEST_HTTP.jmx +++ b/bin/testfiles/TEST_HTTP.jmx @@ -159,7 +159,7 @@ mirrorServer.start(); false - true + true value1 = true @@ -220,7 +220,6 @@ mirrorServer.start(); false - true Get with body = @@ -534,7 +533,6 @@ mirrorServer.start(); false - true Method has body = @@ -602,7 +600,6 @@ mirrorServer.start(); false - true We have a body = @@ -744,7 +741,6 @@ mirrorServer.start(); false - true value1 = true @@ -797,7 +793,6 @@ mirrorServer.start(); false - true value1 = true @@ -865,7 +860,6 @@ mirrorServer.start(); false - true value1 = true @@ -873,7 +867,6 @@ mirrorServer.start(); false - true value2 = true @@ -956,7 +949,6 @@ if(prev.getSamplerData().indexOf(textToCheck) < 0) { false - true Veni vidi vici = @@ -1336,7 +1328,6 @@ if(prev.getSamplerData().indexOf(textToCheck) < 0) { false - true Body of Put = @@ -1420,7 +1411,6 @@ if(prev.getSamplerData().indexOf(textToCheck) < 0) { false - true value1 = true @@ -1502,7 +1492,6 @@ if(prev.getSamplerData().indexOf(textToCheck) < 0) { false - true value1 = true diff --git a/bin/testfiles/load_bug_list.jmx b/bin/testfiles/load_bug_list.jmx index ee0a73ecbf1..e0dc7dd55c6 100644 --- a/bin/testfiles/load_bug_list.jmx +++ b/bin/testfiles/load_bug_list.jmx @@ -10,7 +10,6 @@ true bug_status false - true = @@ -18,7 +17,6 @@ true bug_status false - true = @@ -26,7 +24,6 @@ true bug_status false - true = @@ -34,7 +31,6 @@ true email1 false - true = @@ -42,7 +38,6 @@ true emailtype1 false - true = @@ -50,7 +45,6 @@ true emailassigned_to1 false - true = @@ -58,7 +52,6 @@ true email2 false - true = @@ -66,7 +59,6 @@ true emailtype2 false - true = @@ -74,7 +66,6 @@ true emailreporter2 false - true = @@ -82,7 +73,6 @@ true bugidtype false - true = @@ -90,7 +80,6 @@ true bug_id false - true = @@ -98,7 +87,6 @@ true changedin false - true = @@ -106,7 +94,6 @@ true votes false - true = @@ -114,7 +101,6 @@ true chfieldfrom false - true = @@ -122,7 +108,6 @@ true chfieldto false - true = @@ -130,7 +115,6 @@ true chfieldvalue false - true = @@ -138,7 +122,6 @@ true product false - true = @@ -146,7 +129,6 @@ true short_desc false - true = @@ -154,7 +136,6 @@ true short_desc_type false - true = @@ -162,7 +143,6 @@ true long_desc false - true = @@ -170,7 +150,6 @@ true long_desc_type false - true = @@ -178,7 +157,6 @@ true bug_file_loc false - true = @@ -186,7 +164,6 @@ true bug_file_loc_type false - true = @@ -194,49 +171,42 @@ true keywords false - true = anywords keywords_type false - true = noop field0-0-0 false - true = noop type0-0-0 false - true = value0-0-0 false - true = doit cmdtype false - true = Reuse same sort as last time order true - true diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages.properties index 34fd5628891..23721c4b4c9 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages.properties @@ -319,7 +319,6 @@ editable_checkbox.use_expression=Use Expression email_results_title=Email Results en=English enable=Enable -enabled_from_gui=Enable encode=URL Encode encode?=URL Encode? encoded_value=URL Encoded Value diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_de.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_de.properties index 557568c978f..f7ebe01ce32 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_de.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_de.properties @@ -153,7 +153,6 @@ edit=Bearbeiten email_results_title=Ergebnisse per eMail verschicken en=Englisch enable=Aktivieren -enabled_from_gui=Aktivieren encode?=Encodieren? encoded_value=URL-Encodierter Wert entry_dn=Ausgangs DN diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_es.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_es.properties index 1ba7393732b..47642121ba1 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_es.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_es.properties @@ -183,7 +183,6 @@ edit=Editar email_results_title=Resultados del Email en=Inglés enable=Habilitar -enabled_from_gui=Habilitar encode?=¿Codificar? encoded_value=Valor de URL Codificada entry_dn=Introduzca DN diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_fr.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_fr.properties index d2ac577bac1..ed0f7be54d1 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_fr.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_fr.properties @@ -314,7 +314,6 @@ editable_checkbox.use_expression=Utiliser l'expression email_results_title=Résultat d'email en=Anglais enable=Activer -enabled_from_gui=Activer encode=URL Encoder encode?=URL Encoder encoded_value=Valeur de l'URL encodée diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_ja.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_ja.properties index 92db3e820a6..2af6236635c 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_ja.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_ja.properties @@ -110,7 +110,6 @@ edit=編集 email_results_title=結果をメールで送信 en=英語 enable=有効 -enabled_from_gui=有効 encoded_value=URLエンコード値 entry_dn=エントリDN error_loading_help=ヘルプページロード中のエラー diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_ko.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_ko.properties index b08b071c006..4d337f1d160 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_ko.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_ko.properties @@ -317,7 +317,6 @@ edit=편집 email_results_title=결과들을 전자우편으로 보내기 en=영어 enable=활성화 -enabled_from_gui=활성화 encode=URL 인코드 encode?=URL 인코드? encoded_value=URL 인코딩된 값 diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_pl.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_pl.properties index 41890b8d0dc..8f4118ef871 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_pl.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_pl.properties @@ -150,7 +150,6 @@ duration=Czas trwania (sekund) edit=Edytuj en=Angielski enable=Włącz -enabled_from_gui=Włącz error_loading_help=Wystąpił błąd przy próbie wyświetlenia strony z pomocą error_occurred=Wystąpił błąd error_title=Błąd diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_pt_BR.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_pt_BR.properties index 0e5cf366244..25df3162657 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_pt_BR.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_pt_BR.properties @@ -175,7 +175,6 @@ edit=Editar email_results_title=Enviar Resultados por Email en=Inglês enable=Habilitar -enabled_from_gui=Habilitar encode?=Codificar? encoded_value=Valor da URL Codificada entry_dn=Entrada DN diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_tr.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_tr.properties index 99e2ee08c66..556b934cdb3 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_tr.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_tr.properties @@ -162,7 +162,6 @@ edit=Düzenle email_results_title=E-posta Sonuçları en=İngilizce enable=Etkinleştir -enabled_from_gui=Etkinleştir encode?=Kodlama? encoded_value=URL Kodlanmış Değer entry_dn=Giriş DN'i diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_CN.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_CN.properties index 86a04da811e..26cff3b953f 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_CN.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_CN.properties @@ -303,7 +303,6 @@ edit=编辑 email_results_title=电子邮件结果 en=英语 enable=启用 -enabled_from_gui=启用 encode=URL编码 encode?=编码? encoded_value=URL编码后的值 diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_TW.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_TW.properties index c03041fe9e5..a1681b42a3e 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_TW.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_zh_TW.properties @@ -135,7 +135,6 @@ edit=編輯 email_results_title=電郵結果 en=英文 enable=啟動 -enabled_from_gui=啟動 encode?=編碼? encoded_value=URL 編碼值 entry_dn=進入 DN 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 f1760b6f8bf..316a31022f3 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 @@ -263,7 +263,7 @@ private static String computePostBody(Arguments arguments, boolean crlfToLF) { StringBuilder postBody = new StringBuilder(); for (JMeterProperty argument : arguments) { HTTPArgument arg = (HTTPArgument) argument.getObjectValue(); - if (!arg.isEnabledFromGui()) { + if (!arg.isEnabled()) { continue; // Skip parameters if they've been disabled from GUI using the checkbox } String value = arg.getValue(); diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/HTTPArgumentsPanel.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/HTTPArgumentsPanel.java index 03d3eea68f2..02c68ee973f 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/HTTPArgumentsPanel.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/HTTPArgumentsPanel.java @@ -46,7 +46,7 @@ public class HTTPArgumentsPanel extends ArgumentsPanel { private static final long serialVersionUID = 240L; - private static final String ENABLED_FROM_GUI = "enabled_from_gui"; //$NON-NLS-1$ + private static final String ENABLE = "enable"; //$NON-NLS-1$ private static final String ENCODE_OR_NOT = "encode?"; //$NON-NLS-1$ @@ -63,17 +63,17 @@ public class HTTPArgumentsPanel extends ArgumentsPanel { @Override protected void initializeTableModel() { tableModel = new ObjectTableModel(new String[] { - ENABLED_FROM_GUI, ArgumentsPanel.COLUMN_RESOURCE_NAMES_0, ArgumentsPanel.COLUMN_RESOURCE_NAMES_1, ENCODE_OR_NOT, CONTENT_TYPE, INCLUDE_EQUALS }, + ENABLE, ArgumentsPanel.COLUMN_RESOURCE_NAMES_0, ArgumentsPanel.COLUMN_RESOURCE_NAMES_1, ENCODE_OR_NOT, CONTENT_TYPE, INCLUDE_EQUALS }, HTTPArgument.class, new Functor[] { - new Functor("isEnabledFromGui"), //$NON-NLS-1$ + new Functor("isEnabled"), //$NON-NLS-1$ new Functor("getName"), //$NON-NLS-1$ new Functor("getValue"), //$NON-NLS-1$ new Functor("isAlwaysEncoded"), //$NON-NLS-1$ new Functor("getContentType"), //$NON-NLS-1$ new Functor("isUseEquals") }, //$NON-NLS-1$ new Functor[] { - new Functor("setEnabledFromGui"), //$NON-NLS-1$ + new Functor("setEnabled"), //$NON-NLS-1$ new Functor("setName"), //$NON-NLS-1$ new Functor("setValue"), //$NON-NLS-1$ new Functor("setAlwaysEncoded"), //$NON-NLS-1$ @@ -90,7 +90,7 @@ public static boolean testFunctors(){ @Override protected void sizeColumns(JTable table) { - GuiUtils.fixSize(table.getColumn(ENABLED_FROM_GUI), table); + GuiUtils.fixSize(table.getColumn(ENABLE), table); GuiUtils.fixSize(table.getColumn(INCLUDE_EQUALS), table); GuiUtils.fixSize(table.getColumn(ENCODE_OR_NOT), table); } @@ -98,7 +98,6 @@ protected void sizeColumns(JTable table) { @Override protected HTTPArgument makeNewArgument() { HTTPArgument arg = new HTTPArgument("", ""); - arg.setEnabledFromGui(true); arg.setAlwaysEncoded(false); arg.setUseEquals(true); return arg; diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java index 37e13d4fde4..c042ed6f801 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java @@ -1577,7 +1577,7 @@ protected String setupHttpEntityEnclosingRequestData(HttpEntityEnclosingRequestB if (arg.isSkippable(parameterName)) { continue; } - if (!arg.isEnabledFromGui()) { + if (!arg.isEnabled()) { continue; // Skip parameters if they've been disabled from GUI using the checkbox } ContentType contentType; @@ -1658,7 +1658,7 @@ else if(ADD_CONTENT_TYPE_TO_POST_IF_MISSING) { StringBuilder postBody = new StringBuilder(); for (JMeterProperty jMeterProperty : getArguments()) { HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue(); - if (!arg.isEnabledFromGui()) { + if (!arg.isEnabled()) { continue; // Skip parameters if they've been disabled from GUI using the checkbox } postBody.append(arg.getEncodedValue(contentEncoding)); @@ -1813,7 +1813,7 @@ private UrlEncodedFormEntity createUrlEncodedFormEntity(final String urlContentE if (arg.isSkippable(parameterName)) { continue; } - if (!arg.isEnabledFromGui()) { + if (!arg.isEnabled()) { continue; // Skip parameters if they've been disabled from GUI using the checkbox } String parameterValue = arg.getValue(); diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java index cdbbd52a98d..91ed064a1f9 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java @@ -1189,7 +1189,7 @@ public String getQueryString(final String contentEncoding) { if (encodedName.isEmpty()) { continue; // Skip parameters with a blank name (allows use of optional variables in parameter lists) } - if(!item.isEnabledFromGui()){ + if(!item.isEnabled()){ continue; // Skip parameters if they've been disabled from GUI using the checkbox } if (!first) { diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PutWriter.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PutWriter.java index 2b2bb8f670b..6419919b01f 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PutWriter.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PutWriter.java @@ -86,7 +86,7 @@ else if(sampler.getSendParameterValuesAsPostBody()) { StringBuilder putBodyBuffer = new StringBuilder(); for (JMeterProperty jMeterProperty : sampler.getArguments()) { HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue(); - if (!arg.isEnabledFromGui()) { + if (!arg.isEnabled()) { continue; // Skip parameters if they've been disabled from GUI using the checkbox } putBodyBuffer.append(arg.getEncodedValue(contentEncoding)); diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java index 5e2eb3ef354..e73f40a0494 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java @@ -70,14 +70,6 @@ public HTTPArgumentSchema getSchema() { return new PropertiesAccessor<>(this, getSchema()); } - public void setEnabledFromGui(boolean enabledFromGui) { - set(getSchema().getEnabledFromGui(), enabledFromGui); - } - - public boolean isEnabledFromGui() { - return get(getSchema().getEnabledFromGui()); - } - public void setUseEquals(boolean ue) { if (ue) { setMetaData("="); @@ -142,7 +134,7 @@ public HTTPArgument(String name, String value, boolean alreadyEncoded) { } /** - * Construct a new HTTPArgument instance; enabledFromGui and alwaysEncoded are set to true. + * Construct a new HTTPArgument instance; enabled and alwaysEncoded set to true. * * @param name the name of the parameter * @param value the value of the parameter @@ -150,7 +142,7 @@ public HTTPArgument(String name, String value, boolean alreadyEncoded) { * @param contentEncoding the encoding used for the parameter value */ public HTTPArgument(String name, String value, boolean alreadyEncoded, String contentEncoding) { - setEnabledFromGui(true); + setEnabled(true); setAlwaysEncoded(true); if (alreadyEncoded) { try { diff --git a/src/protocol/http/src/main/kotlin/org/apache/jmeter/protocol/http/util/HTTPArgumentSchema.kt b/src/protocol/http/src/main/kotlin/org/apache/jmeter/protocol/http/util/HTTPArgumentSchema.kt index 3710af665a9..0c2cec15ed3 100644 --- a/src/protocol/http/src/main/kotlin/org/apache/jmeter/protocol/http/util/HTTPArgumentSchema.kt +++ b/src/protocol/http/src/main/kotlin/org/apache/jmeter/protocol/http/util/HTTPArgumentSchema.kt @@ -30,9 +30,6 @@ import org.apiguardian.api.API public abstract class HTTPArgumentSchema : ArgumentSchema() { public companion object INSTANCE : HTTPArgumentSchema() - public val enabledFromGui: BooleanPropertyDescriptor - by boolean("HTTPArgument.enabled_from_gui") - public val alwaysEncode: BooleanPropertyDescriptor by boolean("HTTPArgument.always_encode") From b0e5a9784df570104fa88a20469fe03a05c9e8bf Mon Sep 17 00:00:00 2001 From: pochopsp Date: Fri, 8 Nov 2024 22:19:24 +0100 Subject: [PATCH 04/10] Revert "Add missing enabled_from_gui to HTTPArgument in test files" This reverts commit 45c45e7ba858f4615c0fb8d20af195be7dc1d60c. --- bin/testfiles/GuiTest231.jmx | 2 -- bin/testfiles/GuiTest231_original.jmx | 2 -- bin/testfiles/Modification Manager.jmx | 2 -- bin/testfiles/SavedGuiTest231.jmx | 2 -- 4 files changed, 8 deletions(-) diff --git a/bin/testfiles/GuiTest231.jmx b/bin/testfiles/GuiTest231.jmx index 25e189758cf..7f847e05141 100644 --- a/bin/testfiles/GuiTest231.jmx +++ b/bin/testfiles/GuiTest231.jmx @@ -145,7 +145,6 @@ false - true Value = true @@ -396,7 +395,6 @@ false - true Value = true diff --git a/bin/testfiles/GuiTest231_original.jmx b/bin/testfiles/GuiTest231_original.jmx index 370d80a05b7..8e0b0b4abe1 100644 --- a/bin/testfiles/GuiTest231_original.jmx +++ b/bin/testfiles/GuiTest231_original.jmx @@ -145,7 +145,6 @@ false - true Value = true @@ -411,7 +410,6 @@ false - true Value = true diff --git a/bin/testfiles/Modification Manager.jmx b/bin/testfiles/Modification Manager.jmx index 1ba17a4a323..9228ab5ed6e 100644 --- a/bin/testfiles/Modification Manager.jmx +++ b/bin/testfiles/Modification Manager.jmx @@ -24,7 +24,6 @@ true request.job_id true - true request.job_id .* @@ -34,7 +33,6 @@ true request.action1 true - true request.action1 opjobadmin.action.inspect diff --git a/bin/testfiles/SavedGuiTest231.jmx b/bin/testfiles/SavedGuiTest231.jmx index 76c5841a166..50bbed3082c 100644 --- a/bin/testfiles/SavedGuiTest231.jmx +++ b/bin/testfiles/SavedGuiTest231.jmx @@ -145,7 +145,6 @@ false - true Value = true @@ -396,7 +395,6 @@ false - true Value = true From 346c71da07e883e4319968ff14988a5652597c74 Mon Sep 17 00:00:00 2001 From: pochopsp Date: Fri, 8 Nov 2024 22:23:44 +0100 Subject: [PATCH 05/10] Remove unnecessary boolProp TestElement.enabled from TEST_HTTP.jmx --- bin/testfiles/TEST_HTTP.jmx | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/testfiles/TEST_HTTP.jmx b/bin/testfiles/TEST_HTTP.jmx index 1f1a3006d97..da93b79e0a8 100644 --- a/bin/testfiles/TEST_HTTP.jmx +++ b/bin/testfiles/TEST_HTTP.jmx @@ -159,7 +159,6 @@ mirrorServer.start(); false - true value1 = true From 67a1e2b668712cfb996f5e3e072b506e00a0c315 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Tue, 14 Jan 2025 16:18:31 +0300 Subject: [PATCH 06/10] refactor: factor out getEnabledArguments to avoid "isEnabled" check all over the place --- .../org/apache/jmeter/config/Arguments.java | 16 +++++++++++++++- .../http/config/gui/UrlConfigGui.java | 5 +---- .../protocol/http/sampler/AjpSampler.java | 2 +- .../protocol/http/sampler/HTTPHC4Impl.java | 19 ++++--------------- .../http/sampler/HTTPSamplerBase.java | 14 +++++--------- .../protocol/http/sampler/PostWriter.java | 4 ++-- .../protocol/http/sampler/PutWriter.java | 5 +---- .../protocol/http/util/HTTPArgument.java | 3 +-- 8 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/core/src/main/java/org/apache/jmeter/config/Arguments.java b/src/core/src/main/java/org/apache/jmeter/config/Arguments.java index e6a060dd7fb..7f2127c48e1 100644 --- a/src/core/src/main/java/org/apache/jmeter/config/Arguments.java +++ b/src/core/src/main/java/org/apache/jmeter/config/Arguments.java @@ -23,11 +23,13 @@ import java.util.List; import java.util.Map; +import org.apache.commons.collections4.iterators.FilterIterator; import org.apache.jmeter.testelement.property.CollectionProperty; import org.apache.jmeter.testelement.property.JMeterProperty; import org.apache.jmeter.testelement.property.PropertyIterator; import org.apache.jmeter.testelement.property.TestElementProperty; import org.apache.jmeter.testelement.schema.PropertiesAccessor; +import org.apiguardian.api.API; /** * A set of Argument objects. @@ -100,7 +102,7 @@ public Map getArgumentsAsMap() { // that this element's values prevail over defaults provided by // configuration // elements: - if (!argMap.containsKey(arg.getName())) { + if (!argMap.containsKey(arg.getName()) && arg.isEnabled()) { argMap.put(arg.getName(), arg.getValue()); } } @@ -173,6 +175,18 @@ public PropertyIterator iterator() { return getArguments().iterator(); } + /** + * Returns the list of enabled arguments. + * @return the list of enabled arguments + */ + @API(since = "5.6", status = API.Status.EXPERIMENTAL) + public Iterable getEnabledArguments() { + return () -> new FilterIterator<>(iterator(), property -> { + Object value = property.getObjectValue(); + return value instanceof Argument && ((Argument) value).isEnabled(); + }); + } + /** * Create a string representation of the arguments. * 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 316a31022f3..ece7f2168cc 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 @@ -261,11 +261,8 @@ private static String computePostBody(Arguments arguments) { */ private static String computePostBody(Arguments arguments, boolean crlfToLF) { StringBuilder postBody = new StringBuilder(); - for (JMeterProperty argument : arguments) { + for (JMeterProperty argument : arguments.getEnabledArguments()) { HTTPArgument arg = (HTTPArgument) argument.getObjectValue(); - if (!arg.isEnabled()) { - continue; // Skip parameters if they've been disabled from GUI using the checkbox - } String value = arg.getValue(); if (crlfToLF) { value = value.replaceAll("\r\n", "\n"); // See modifyTestElement diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/AjpSampler.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/AjpSampler.java index d705ae726cb..2a5fe624bc7 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/AjpSampler.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/AjpSampler.java @@ -279,7 +279,7 @@ private String setConnectionHeaders(URL url, String host, String method) setString(HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED); StringBuilder sb = new StringBuilder(); boolean first = true; - for (JMeterProperty arg : getArguments()) { + for (JMeterProperty arg : getArguments().getEnabledArguments()) { if (first) { first = false; } else { diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java index c042ed6f801..e12800b8abe 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java @@ -159,7 +159,6 @@ import org.apache.jmeter.services.FileServer; import org.apache.jmeter.testelement.property.CollectionProperty; import org.apache.jmeter.testelement.property.JMeterProperty; -import org.apache.jmeter.testelement.property.PropertyIterator; import org.apache.jmeter.threads.JMeterContextService; import org.apache.jmeter.threads.JMeterVariables; import org.apache.jmeter.util.JMeterUtils; @@ -1571,15 +1570,12 @@ protected String setupHttpEntityEnclosingRequestData(HttpEntityEnclosingRequestB } // Create the parts // Add any parameters - for (JMeterProperty jMeterProperty : getArguments()) { + for (JMeterProperty jMeterProperty : getArguments().getEnabledArguments()) { HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue(); String parameterName = arg.getName(); if (arg.isSkippable(parameterName)) { continue; } - if (!arg.isEnabled()) { - continue; // Skip parameters if they've been disabled from GUI using the checkbox - } ContentType contentType; if (arg.getContentType().indexOf(';') >= 0) { // assume, that the content type contains charset info @@ -1656,11 +1652,8 @@ else if(ADD_CONTENT_TYPE_TO_POST_IF_MISSING) { // Just append all the parameter values, and use that as the post body StringBuilder postBody = new StringBuilder(); - for (JMeterProperty jMeterProperty : getArguments()) { + for (JMeterProperty jMeterProperty : getArguments().getEnabledArguments()) { HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue(); - if (!arg.isEnabled()) { - continue; // Skip parameters if they've been disabled from GUI using the checkbox - } postBody.append(arg.getEncodedValue(contentEncoding)); } // Let StringEntity perform the encoding @@ -1802,10 +1795,9 @@ else if(getSendParameterValuesAsPostBody()) { private UrlEncodedFormEntity createUrlEncodedFormEntity(final String urlContentEncoding) throws UnsupportedEncodingException { // It is a normal request, with parameter names and values // Add the parameters - PropertyIterator args = getArguments().iterator(); List nvps = new ArrayList<>(); - while (args.hasNext()) { - HTTPArgument arg = (HTTPArgument) args.next().getObjectValue(); + for (JMeterProperty jMeterProperty: getArguments().getEnabledArguments()) { + HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue(); // The HTTPClient always urlencodes both name and value, // so if the argument is already encoded, we have to decode // it before adding it to the post request @@ -1813,9 +1805,6 @@ private UrlEncodedFormEntity createUrlEncodedFormEntity(final String urlContentE if (arg.isSkippable(parameterName)) { continue; } - if (!arg.isEnabled()) { - continue; // Skip parameters if they've been disabled from GUI using the checkbox - } String parameterValue = arg.getValue(); if (!arg.isAlwaysEncoded()) { // The value is already encoded by the user diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java index 91ed064a1f9..7f45aedeedb 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java @@ -81,7 +81,6 @@ import org.apache.jmeter.testelement.ThreadListener; import org.apache.jmeter.testelement.property.CollectionProperty; import org.apache.jmeter.testelement.property.JMeterProperty; -import org.apache.jmeter.testelement.property.PropertyIterator; import org.apache.jmeter.testelement.schema.PropertiesAccessor; import org.apache.jmeter.testelement.schema.PropertyDescriptor; import org.apache.jmeter.threads.JMeterContext; @@ -409,7 +408,7 @@ public boolean getSendParameterValuesAsPostBody() { return true; } else { boolean hasArguments = false; - for (JMeterProperty jMeterProperty : getArguments()) { + for (JMeterProperty jMeterProperty : getArguments().getEnabledArguments()) { hasArguments = true; HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue(); if (arg.getName() != null && !arg.getName().isEmpty()) { @@ -1155,9 +1154,10 @@ public String getQueryString() { */ public String getQueryString(final String contentEncoding) { - CollectionProperty arguments = getArguments().getArguments(); + Arguments args = getArguments(); + Iterator iter = args.getEnabledArguments().iterator(); // Optimisation : avoid building useless objects if empty arguments - if(arguments.isEmpty()) { + if (!iter.hasNext()) { return ""; } String lContentEncoding = contentEncoding; @@ -1167,8 +1167,7 @@ public String getQueryString(final String contentEncoding) { lContentEncoding = EncoderCache.URL_ARGUMENT_ENCODING; } - StringBuilder buf = new StringBuilder(arguments.size() * 15); - PropertyIterator iter = arguments.iterator(); + StringBuilder buf = new StringBuilder(args.getArgumentCount() * 15); boolean first = true; while (iter.hasNext()) { HTTPArgument item = null; @@ -1189,9 +1188,6 @@ public String getQueryString(final String contentEncoding) { if (encodedName.isEmpty()) { continue; // Skip parameters with a blank name (allows use of optional variables in parameter lists) } - if(!item.isEnabled()){ - continue; // Skip parameters if they've been disabled from GUI using the checkbox - } if (!first) { buf.append(QRY_SEP); } else { diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PostWriter.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PostWriter.java index 60d01217525..447a65f1073 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PostWriter.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PostWriter.java @@ -190,7 +190,7 @@ public void setHeaders(URLConnection connection, HTTPSamplerBase sampler) throws ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputStreamWriter osw = new OutputStreamWriter(bos, contentEncoding); // Add any parameters - for (JMeterProperty jMeterProperty : sampler.getArguments()) { + for (JMeterProperty jMeterProperty : sampler.getArguments().getEnabledArguments()) { HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue(); String parameterName = arg.getName(); if (arg.isSkippable(parameterName)) { @@ -299,7 +299,7 @@ public void setHeaders(URLConnection connection, HTTPSamplerBase sampler) throws // Just append all the parameter values, and use that as the post body StringBuilder postBodyBuffer = new StringBuilder(); - for (JMeterProperty jMeterProperty : sampler.getArguments()) { + for (JMeterProperty jMeterProperty : sampler.getArguments().getEnabledArguments()) { HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue(); postBodyBuffer.append(arg.getEncodedValue(contentEncoding)); } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PutWriter.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PutWriter.java index 6419919b01f..66a79b6b4e7 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PutWriter.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PutWriter.java @@ -84,11 +84,8 @@ else if(sampler.getSendParameterValuesAsPostBody()) { // Just append all the parameter values, and use that as the put body StringBuilder putBodyBuffer = new StringBuilder(); - for (JMeterProperty jMeterProperty : sampler.getArguments()) { + for (JMeterProperty jMeterProperty : sampler.getArguments().getEnabledArguments()) { HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue(); - if (!arg.isEnabled()) { - continue; // Skip parameters if they've been disabled from GUI using the checkbox - } putBodyBuffer.append(arg.getEncodedValue(contentEncoding)); } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java index e73f40a0494..3353589b1f8 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java @@ -134,7 +134,7 @@ public HTTPArgument(String name, String value, boolean alreadyEncoded) { } /** - * Construct a new HTTPArgument instance; enabled and alwaysEncoded set to true. + * Construct a new HTTPArgument instance; alwaysEncoded is set to true. * * @param name the name of the parameter * @param value the value of the parameter @@ -142,7 +142,6 @@ public HTTPArgument(String name, String value, boolean alreadyEncoded) { * @param contentEncoding the encoding used for the parameter value */ public HTTPArgument(String name, String value, boolean alreadyEncoded, String contentEncoding) { - setEnabled(true); setAlwaysEncoded(true); if (alreadyEncoded) { try { From e42953a4e5bc72163f759b97812a71172d08e69a Mon Sep 17 00:00:00 2001 From: pochopsp Date: Mon, 6 Oct 2025 01:10:00 +0200 Subject: [PATCH 07/10] Add tests for HttpSampler with enabled and disabled arguments --- .../HttpSamplerDisableArgumentsTest.kt | 175 ++++++++++++++++++ .../protocol/http/sampler/HttpSamplerTest.kt | 35 ---- .../http/sampler/HttpSamplerTestingUtils.kt | 56 ++++++ 3 files changed, 231 insertions(+), 35 deletions(-) create mode 100644 src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerDisableArgumentsTest.kt create mode 100644 src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerTestingUtils.kt diff --git a/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerDisableArgumentsTest.kt b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerDisableArgumentsTest.kt new file mode 100644 index 00000000000..4c2fe103b34 --- /dev/null +++ b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerDisableArgumentsTest.kt @@ -0,0 +1,175 @@ +/* + * 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.protocol.http.sampler + +import com.github.tomakehurst.wiremock.client.WireMock.aMultipart +import com.github.tomakehurst.wiremock.client.WireMock.aResponse +import com.github.tomakehurst.wiremock.client.WireMock.equalTo +import com.github.tomakehurst.wiremock.client.WireMock.get +import com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor +import com.github.tomakehurst.wiremock.client.WireMock.post +import com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor +import com.github.tomakehurst.wiremock.client.WireMock.put +import com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor +import com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo +import com.github.tomakehurst.wiremock.junit5.WireMockTest +import org.apache.jmeter.junit.JMeterTestCase +import org.apache.jmeter.test.assertions.executePlanAndCollectEvents +import org.apache.jmeter.treebuilder.TreeBuilder +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.ValueSource +import kotlin.time.Duration.Companion.seconds + +@WireMockTest +class HttpSamplerDisableArgumentsTest : JMeterTestCase() { + + fun TreeBuilder.httpGet(body: HTTPSamplerProxy.() -> Unit) { + org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy::class { + name = "Test disabled params" + method = "GET" + domain = "localhost" + path = "/test" + body() + } + } + + fun TreeBuilder.httpPut(body: HTTPSamplerProxy.() -> Unit) { + org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy::class { + name = "Test disabled params" + method = "PUT" + domain = "localhost" + path = "/test" + body() + } + } + + fun TreeBuilder.httpPost(body: HTTPSamplerProxy.() -> Unit) { + org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy::class { + name = "Test disabled params" + method = "POST" + domain = "localhost" + path = "/test" + doMultipart = true + body() + } + } + + @ParameterizedTest + @ValueSource(strings = ["Java", "HttpClient4"]) + fun `GET disable param1 should send enabled param2`(httpImplementation: String, server: WireMockRuntimeInfo) { + server.wireMock.register( + get("/test").willReturn(aResponse().withStatus(200)) + ) + + executePlanAndCollectEvents(10.seconds) { + oneRequest { + httpGet { + implementation = httpImplementation + port = server.httpPort + addArgument("param1", "value1") + arguments.getArgument(0).isEnabled = false + addArgument("param2", "value2") + } + } + } + + server.wireMock.verifyThat( + 1, + getRequestedFor(urlEqualTo("/test?param2=value2")) + ) + } + + @ParameterizedTest + @ValueSource(strings = ["Java", "HttpClient4"]) + fun `PUT disable param2 should send enabled param1 and param3`(httpImplementation: String, server: WireMockRuntimeInfo) { + server.wireMock.register( + put("/test").willReturn(aResponse().withStatus(200)) + ) + + executePlanAndCollectEvents(1000.seconds) { + oneRequest { + httpPut { + implementation = httpImplementation + port = server.httpPort + postBodyRaw = true + addArgument("param1", "value1") + addArgument("param2", "value2") + arguments.getArgument(1).isEnabled = false + addArgument("param3", "value3") + } + } + } + + server.wireMock.verifyThat( + 1, + putRequestedFor(urlEqualTo("/test")) + .withRequestBody(equalTo("value1value3")) + ) + } + + @ParameterizedTest + @ValueSource(strings = ["Java", "HttpClient4"]) + fun `POST disable default and non-default param should send the only enabled non-default param`(httpImplementation: String, server: WireMockRuntimeInfo) { + server.wireMock.register( + post("/test").willReturn(aResponse().withStatus(200)) + ) + + executePlanAndCollectEvents(10.seconds) { + oneRequest { + httpPost { + org.apache.jmeter.config.ConfigTestElement::class { + addArgument("param0", "value0") + arguments.getArgument(0).isEnabled = false + props { + // guiClass is needed for org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.applies + it[guiClass] = "org.apache.jmeter.protocol.http.config.gui.HttpDefaultsGui" + } + } + implementation = httpImplementation + port = server.httpPort + addArgument("param1", "value1") + arguments.getArgument(1).isEnabled = false + addArgument("param2", "value2") + } + } + } + + server.wireMock.verifyThat( + 1, + postRequestedFor(urlEqualTo("/test")) + .withRequestBodyPart( + aMultipart("param2").withBody(equalTo("value2")).build() + ) + .withRequestBody( + httpImplementation, + """ + -----------------------------7d159c1302d0y0 + Content-Disposition: form-data; name="param2" + Content-Type: text/plain; charset=UTF-8 + Content-Transfer-Encoding: 8bit + + value2 + -----------------------------7d159c1302d0y0-- + + """.trimIndent() + ) + ) + } + +} diff --git a/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerTest.kt b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerTest.kt index fb82fe4adf6..57a9f6fd50a 100644 --- a/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerTest.kt +++ b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerTest.kt @@ -21,19 +21,15 @@ import com.github.tomakehurst.wiremock.client.WireMock.aMultipart import com.github.tomakehurst.wiremock.client.WireMock.aResponse import com.github.tomakehurst.wiremock.client.WireMock.containing import com.github.tomakehurst.wiremock.client.WireMock.equalTo -import com.github.tomakehurst.wiremock.client.WireMock.matching import com.github.tomakehurst.wiremock.client.WireMock.post import com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor import com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo import com.github.tomakehurst.wiremock.junit5.WireMockTest -import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder -import org.apache.jmeter.control.LoopController import org.apache.jmeter.junit.JMeterTestCase import org.apache.jmeter.protocol.http.control.Header import org.apache.jmeter.protocol.http.util.HTTPFileArg import org.apache.jmeter.test.assertions.executePlanAndCollectEvents -import org.apache.jmeter.threads.ThreadGroup import org.apache.jmeter.treebuilder.TreeBuilder import org.junit.jupiter.api.Assumptions.assumeTrue import org.junit.jupiter.api.io.TempDir @@ -51,19 +47,6 @@ class HttpSamplerTest : JMeterTestCase() { @TempDir lateinit var dir: Path - fun TreeBuilder.oneRequest(body: ThreadGroup.() -> Unit) { - ThreadGroup::class { - numThreads = 1 - rampUp = 0 - setSamplerController( - LoopController().apply { - loops = 1 - } - ) - body() - } - } - fun TreeBuilder.httpPost(body: HTTPSamplerProxy.() -> Unit) { org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy::class { name = "Upload file" @@ -137,24 +120,6 @@ class HttpSamplerTest : JMeterTestCase() { ) } - fun RequestPatternBuilder.withRequestBody( - httpImplementation: String, - body: String - ) = apply { - // normalize line endings to CRLF - val normalizedBody = body.replace("\r\n", "\n").replace("\n", "\r\n") - withRequestBody( - if (httpImplementation == "Java") { - equalTo(normalizedBody) - } else { - matching( - normalizedBody - .replace(PostWriter.BOUNDARY, "[^ \\n\\r]{1,69}?") - ) - } - ) - } - @ParameterizedTest @ValueSource(strings = ["Java", "HttpClient4"]) fun `one parameter`(httpImplementation: String, server: WireMockRuntimeInfo) { diff --git a/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerTestingUtils.kt b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerTestingUtils.kt new file mode 100644 index 00000000000..8c5e4b809dc --- /dev/null +++ b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerTestingUtils.kt @@ -0,0 +1,56 @@ +/* + * 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.protocol.http.sampler + +import com.github.tomakehurst.wiremock.client.WireMock.equalTo +import com.github.tomakehurst.wiremock.client.WireMock.matching +import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder +import org.apache.jmeter.control.LoopController +import org.apache.jmeter.threads.ThreadGroup +import org.apache.jmeter.treebuilder.TreeBuilder + +fun TreeBuilder.oneRequest(body: ThreadGroup.() -> Unit) { + ThreadGroup::class { + numThreads = 1 + rampUp = 0 + setSamplerController( + LoopController().apply { + loops = 1 + } + ) + body() + } +} + +fun RequestPatternBuilder.withRequestBody( + httpImplementation: String, + body: String +) = apply { + // normalize line endings to CRLF + val normalizedBody = body.replace("\r\n", "\n").replace("\n", "\r\n") + withRequestBody( + if (httpImplementation == "Java") { + equalTo(normalizedBody) + } else { + matching( + normalizedBody + .replace(PostWriter.BOUNDARY, "[^ \\n\\r]{1,69}?") + ) + } + ) +} From af1049867ff59fc01478fbfa9f7b0abe00f227dd Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Mon, 6 Oct 2025 11:55:29 +0300 Subject: [PATCH 08/10] test: move TreeBuilder.oneRequest to core testFixtures --- .../treebuilder/TreeBuilderExtensions.kt | 34 ++++++++++++++++ .../timers/ConstantThroughputTimerKtTest.kt | 17 +------- .../HttpSamplerDisableArgumentsTest.kt | 40 ++++++------------- .../protocol/http/sampler/HttpSamplerTest.kt | 3 +- .../http/sampler/HttpSamplerTestingUtils.kt | 16 -------- 5 files changed, 50 insertions(+), 60 deletions(-) create mode 100644 src/core/src/testFixtures/kotlin/org/apache/jmeter/treebuilder/TreeBuilderExtensions.kt diff --git a/src/core/src/testFixtures/kotlin/org/apache/jmeter/treebuilder/TreeBuilderExtensions.kt b/src/core/src/testFixtures/kotlin/org/apache/jmeter/treebuilder/TreeBuilderExtensions.kt new file mode 100644 index 00000000000..650456f4f1b --- /dev/null +++ b/src/core/src/testFixtures/kotlin/org/apache/jmeter/treebuilder/TreeBuilderExtensions.kt @@ -0,0 +1,34 @@ +/* + * 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.treebuilder + +import org.apache.jmeter.control.LoopController +import org.apache.jmeter.threads.ThreadGroup + +fun TreeBuilder.oneRequest(body: ThreadGroup.() -> Unit) { + ThreadGroup::class { + numThreads = 1 + rampUp = 0 + setSamplerController( + LoopController().apply { + loops = 1 + } + ) + body() + } +} diff --git a/src/functions/src/test/kotlin/org/apache/jmeter/timers/ConstantThroughputTimerKtTest.kt b/src/functions/src/test/kotlin/org/apache/jmeter/timers/ConstantThroughputTimerKtTest.kt index 1a1dc805aeb..bcbc6cf0458 100644 --- a/src/functions/src/test/kotlin/org/apache/jmeter/timers/ConstantThroughputTimerKtTest.kt +++ b/src/functions/src/test/kotlin/org/apache/jmeter/timers/ConstantThroughputTimerKtTest.kt @@ -17,30 +17,15 @@ package org.apache.jmeter.timers -import org.apache.jmeter.control.LoopController import org.apache.jmeter.junit.JMeterTestCase import org.apache.jmeter.sampler.DebugSampler import org.apache.jmeter.test.assertions.executePlanAndCollectEvents -import org.apache.jmeter.threads.ThreadGroup -import org.apache.jmeter.treebuilder.TreeBuilder +import org.apache.jmeter.treebuilder.oneRequest import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import kotlin.time.Duration.Companion.seconds class ConstantThroughputTimerKtTest : JMeterTestCase() { - fun TreeBuilder.oneRequest(body: ThreadGroup.() -> Unit) { - ThreadGroup::class { - numThreads = 1 - rampUp = 0 - setSamplerController( - LoopController().apply { - loops = 1 - } - ) - body() - } - } - @Test fun `throughput as variable`() { val events = executePlanAndCollectEvents(5.seconds) { diff --git a/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerDisableArgumentsTest.kt b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerDisableArgumentsTest.kt index 4c2fe103b34..0af5dbfd943 100644 --- a/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerDisableArgumentsTest.kt +++ b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerDisableArgumentsTest.kt @@ -29,8 +29,10 @@ import com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor import com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo import com.github.tomakehurst.wiremock.junit5.WireMockTest +import org.apache.jmeter.config.ConfigTestElement import org.apache.jmeter.junit.JMeterTestCase import org.apache.jmeter.test.assertions.executePlanAndCollectEvents +import org.apache.jmeter.treebuilder.oneRequest import org.apache.jmeter.treebuilder.TreeBuilder import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource @@ -39,8 +41,8 @@ import kotlin.time.Duration.Companion.seconds @WireMockTest class HttpSamplerDisableArgumentsTest : JMeterTestCase() { - fun TreeBuilder.httpGet(body: HTTPSamplerProxy.() -> Unit) { - org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy::class { + fun TreeBuilder.httpRequest(body: HTTPSamplerProxy.() -> Unit) { + HTTPSamplerProxy::class { name = "Test disabled params" method = "GET" domain = "localhost" @@ -49,27 +51,6 @@ class HttpSamplerDisableArgumentsTest : JMeterTestCase() { } } - fun TreeBuilder.httpPut(body: HTTPSamplerProxy.() -> Unit) { - org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy::class { - name = "Test disabled params" - method = "PUT" - domain = "localhost" - path = "/test" - body() - } - } - - fun TreeBuilder.httpPost(body: HTTPSamplerProxy.() -> Unit) { - org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy::class { - name = "Test disabled params" - method = "POST" - domain = "localhost" - path = "/test" - doMultipart = true - body() - } - } - @ParameterizedTest @ValueSource(strings = ["Java", "HttpClient4"]) fun `GET disable param1 should send enabled param2`(httpImplementation: String, server: WireMockRuntimeInfo) { @@ -79,7 +60,8 @@ class HttpSamplerDisableArgumentsTest : JMeterTestCase() { executePlanAndCollectEvents(10.seconds) { oneRequest { - httpGet { + httpRequest { + method = "GET" implementation = httpImplementation port = server.httpPort addArgument("param1", "value1") @@ -104,7 +86,8 @@ class HttpSamplerDisableArgumentsTest : JMeterTestCase() { executePlanAndCollectEvents(1000.seconds) { oneRequest { - httpPut { + httpRequest { + method = "PUT" implementation = httpImplementation port = server.httpPort postBodyRaw = true @@ -132,15 +115,18 @@ class HttpSamplerDisableArgumentsTest : JMeterTestCase() { executePlanAndCollectEvents(10.seconds) { oneRequest { - httpPost { - org.apache.jmeter.config.ConfigTestElement::class { + httpRequest { + ConfigTestElement::class { addArgument("param0", "value0") arguments.getArgument(0).isEnabled = false + addArgument("param4", "value4") props { // guiClass is needed for org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.applies it[guiClass] = "org.apache.jmeter.protocol.http.config.gui.HttpDefaultsGui" } } + method = "POST" + doMultipart = true implementation = httpImplementation port = server.httpPort addArgument("param1", "value1") diff --git a/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerTest.kt b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerTest.kt index 57a9f6fd50a..180bbb42b6a 100644 --- a/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerTest.kt +++ b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerTest.kt @@ -31,6 +31,7 @@ import org.apache.jmeter.protocol.http.control.Header import org.apache.jmeter.protocol.http.util.HTTPFileArg import org.apache.jmeter.test.assertions.executePlanAndCollectEvents import org.apache.jmeter.treebuilder.TreeBuilder +import org.apache.jmeter.treebuilder.oneRequest import org.junit.jupiter.api.Assumptions.assumeTrue import org.junit.jupiter.api.io.TempDir import org.junit.jupiter.params.ParameterizedTest @@ -48,7 +49,7 @@ class HttpSamplerTest : JMeterTestCase() { lateinit var dir: Path fun TreeBuilder.httpPost(body: HTTPSamplerProxy.() -> Unit) { - org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy::class { + HTTPSamplerProxy::class { name = "Upload file" method = "POST" domain = "localhost" diff --git a/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerTestingUtils.kt b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerTestingUtils.kt index 8c5e4b809dc..bc9c8500d80 100644 --- a/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerTestingUtils.kt +++ b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerTestingUtils.kt @@ -20,22 +20,6 @@ package org.apache.jmeter.protocol.http.sampler import com.github.tomakehurst.wiremock.client.WireMock.equalTo import com.github.tomakehurst.wiremock.client.WireMock.matching import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder -import org.apache.jmeter.control.LoopController -import org.apache.jmeter.threads.ThreadGroup -import org.apache.jmeter.treebuilder.TreeBuilder - -fun TreeBuilder.oneRequest(body: ThreadGroup.() -> Unit) { - ThreadGroup::class { - numThreads = 1 - rampUp = 0 - setSamplerController( - LoopController().apply { - loops = 1 - } - ) - body() - } -} fun RequestPatternBuilder.withRequestBody( httpImplementation: String, From 285e913878cd73cbe916abe2206948c250ab0824 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Mon, 6 Oct 2025 12:53:16 +0300 Subject: [PATCH 09/10] chore: rework httpRequestDefaults --- .../HttpSamplerDisableArgumentsTest.kt | 39 +++++++++----- .../control/HttpRequestDefaultsExtensions.kt | 53 +++++++++++++++++++ 2 files changed, 80 insertions(+), 12 deletions(-) create mode 100644 src/protocol/http/src/testFixtures/kotlin/org/apache/jmeter/protocol/http/control/HttpRequestDefaultsExtensions.kt diff --git a/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerDisableArgumentsTest.kt b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerDisableArgumentsTest.kt index 0af5dbfd943..f853eed98e1 100644 --- a/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerDisableArgumentsTest.kt +++ b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerDisableArgumentsTest.kt @@ -29,11 +29,14 @@ import com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor import com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo import com.github.tomakehurst.wiremock.junit5.WireMockTest -import org.apache.jmeter.config.ConfigTestElement +import org.apache.jmeter.config.Argument import org.apache.jmeter.junit.JMeterTestCase +import org.apache.jmeter.protocol.http.control.arguments +import org.apache.jmeter.protocol.http.control.httpRequestDefaults +import org.apache.jmeter.protocol.http.util.HTTPArgument import org.apache.jmeter.test.assertions.executePlanAndCollectEvents -import org.apache.jmeter.treebuilder.oneRequest import org.apache.jmeter.treebuilder.TreeBuilder +import org.apache.jmeter.treebuilder.oneRequest import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource import kotlin.time.Duration.Companion.seconds @@ -115,22 +118,25 @@ class HttpSamplerDisableArgumentsTest : JMeterTestCase() { executePlanAndCollectEvents(10.seconds) { oneRequest { - httpRequest { - ConfigTestElement::class { - addArgument("param0", "value0") - arguments.getArgument(0).isEnabled = false - addArgument("param4", "value4") - props { - // guiClass is needed for org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.applies - it[guiClass] = "org.apache.jmeter.protocol.http.config.gui.HttpDefaultsGui" - } + httpRequestDefaults { + arguments { + addArgument( + HTTPArgument("param0", "value0").apply { + isEnabled = false + } + ) + addArgument( + HTTPArgument("param4", "value4") + ) } + } + httpRequest { method = "POST" doMultipart = true implementation = httpImplementation port = server.httpPort addArgument("param1", "value1") - arguments.getArgument(1).isEnabled = false + arguments.getArgument(0).isEnabled = false addArgument("param2", "value2") } } @@ -142,6 +148,9 @@ class HttpSamplerDisableArgumentsTest : JMeterTestCase() { .withRequestBodyPart( aMultipart("param2").withBody(equalTo("value2")).build() ) + .withRequestBodyPart( + aMultipart("param4").withBody(equalTo("value4")).build() + ) .withRequestBody( httpImplementation, """ @@ -151,6 +160,12 @@ class HttpSamplerDisableArgumentsTest : JMeterTestCase() { Content-Transfer-Encoding: 8bit value2 + -----------------------------7d159c1302d0y0 + Content-Disposition: form-data; name="param4" + Content-Type: text/plain; charset=UTF-8 + Content-Transfer-Encoding: 8bit + + value4 -----------------------------7d159c1302d0y0-- """.trimIndent() diff --git a/src/protocol/http/src/testFixtures/kotlin/org/apache/jmeter/protocol/http/control/HttpRequestDefaultsExtensions.kt b/src/protocol/http/src/testFixtures/kotlin/org/apache/jmeter/protocol/http/control/HttpRequestDefaultsExtensions.kt new file mode 100644 index 00000000000..b64fa9563ec --- /dev/null +++ b/src/protocol/http/src/testFixtures/kotlin/org/apache/jmeter/protocol/http/control/HttpRequestDefaultsExtensions.kt @@ -0,0 +1,53 @@ +/* + * 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.protocol.http.control + +import org.apache.jmeter.config.Arguments +import org.apache.jmeter.config.ConfigTestElement +import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBaseSchema +import org.apache.jmeter.testelement.property.TestElementProperty +import org.apache.jmeter.treebuilder.Action +import org.apache.jmeter.treebuilder.TreeBuilder + +fun TreeBuilder.httpRequestDefaults(configure: Action = Action {}) { + ConfigTestElement::class { + props { + it[name] = "HTTP Request Defaults" + it[guiClass] = "org.apache.jmeter.protocol.http.config.gui.HttpDefaultsGui" + } + setProperty( + TestElementProperty( + HTTPSamplerBaseSchema.arguments.name, + Arguments().apply { + props { + it[guiClass] = "org.apache.jmeter.protocol.http.gui.HTTPArgumentsPanel" + it[testClass] = "org.apache.jmeter.config.Arguments" + } + } + ) + ) + configure(this) + } +} + +val ConfigTestElement.arguments: Arguments + get() = getProperty(HTTPSamplerBaseSchema.arguments.name) as Arguments + +fun ConfigTestElement.arguments(configure: Action = Action {}) { + configure((getProperty(HTTPSamplerBaseSchema.arguments.name) as TestElementProperty).element as Arguments) +} From 53b3dd95b88ae2ca4bf613800387da33f0952e50 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Mon, 6 Oct 2025 12:58:20 +0300 Subject: [PATCH 10/10] test: fix code style --- .../protocol/http/sampler/HttpSamplerDisableArgumentsTest.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerDisableArgumentsTest.kt b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerDisableArgumentsTest.kt index f853eed98e1..80c54d0f2ae 100644 --- a/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerDisableArgumentsTest.kt +++ b/src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerDisableArgumentsTest.kt @@ -29,7 +29,6 @@ import com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor import com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo import com.github.tomakehurst.wiremock.junit5.WireMockTest -import org.apache.jmeter.config.Argument import org.apache.jmeter.junit.JMeterTestCase import org.apache.jmeter.protocol.http.control.arguments import org.apache.jmeter.protocol.http.control.httpRequestDefaults @@ -172,5 +171,4 @@ class HttpSamplerDisableArgumentsTest : JMeterTestCase() { ) ) } - }