WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit a4830d4

Browse files
committed
WIP: add HTTPSampler.responseProcessing enum instead of useMd5 boolean
1 parent 5407250 commit a4830d4

File tree

27 files changed

+1005
-286
lines changed

27 files changed

+1005
-286
lines changed

src/components/src/main/java/org/apache/jmeter/config/CSVDataSet.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.apache.jmeter.threads.JMeterContext;
3333
import org.apache.jmeter.threads.JMeterVariables;
3434
import org.apache.jmeter.util.JMeterUtils;
35-
import org.apache.jorphan.util.EnumUtils;
35+
import org.apache.jorphan.gui.LocalizableEnum;
3636
import org.apache.jorphan.util.JMeterStopThreadException;
3737
import org.apache.jorphan.util.JOrphanUtils;
3838
import org.apache.jorphan.util.StringUtilities;
@@ -70,20 +70,20 @@
7070
public class CSVDataSet extends ConfigTestElement
7171
implements TestBean, LoopIterationListener, NoConfigMerge {
7272

73-
public enum ShareMode {
73+
public enum ShareMode implements LocalizableEnum {
7474
ALL("shareMode.all"),
7575
GROUP("shareMode.group"),
7676
THREAD("shareMode.thread");
7777

78-
private final String value;
78+
private final String propertyName;
7979

80-
ShareMode(String value) {
81-
this.value = value;
80+
ShareMode(String propertyName) {
81+
this.propertyName = propertyName;
8282
}
8383

8484
@Override
85-
public String toString() {
86-
return value;
85+
public String getResourceKey() {
86+
return propertyName;
8787
}
8888
}
8989

src/components/src/main/java/org/apache/jmeter/timers/ConstantThroughputTimer.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.apache.jmeter.threads.JMeterContextService;
3333
import org.apache.jmeter.util.JMeterUtils;
3434
import org.apache.jorphan.collections.IdentityKey;
35+
import org.apache.jorphan.gui.LocalizableEnum;
3536
import org.apache.jorphan.util.EnumUtils;
3637
import org.apiguardian.api.API;
3738

@@ -71,7 +72,7 @@ private static class ThroughputInfo{
7172
/**
7273
* This enum defines the calculation modes used by the ConstantThroughputTimer.
7374
*/
74-
public enum Mode {
75+
public enum Mode implements LocalizableEnum {
7576
ThisThreadOnly("calcMode.1"), // NOSONAR Keep naming for compatibility
7677
AllActiveThreads("calcMode.2"), // NOSONAR Keep naming for compatibility
7778
AllActiveThreadsInCurrentThreadGroup("calcMode.3"), // NOSONAR Keep naming for compatibility
@@ -89,6 +90,11 @@ public enum Mode {
8990
public String toString() {
9091
return propertyName;
9192
}
93+
94+
@Override
95+
public String getResourceKey() {
96+
return propertyName;
97+
}
9298
}
9399

94100
/**
@@ -163,7 +169,7 @@ public Mode getMode() {
163169
@Deprecated
164170
@SuppressWarnings("EnumOrdinal")
165171
public void setCalcMode(int mode) {
166-
setMode(EnumUtils.values(Mode.class).get(mode));
172+
setMode(EnumUtils.getEnumValues(Mode.class).get(mode));
167173
}
168174

169175
@SuppressWarnings("EnumOrdinal")

src/core/src/main/java/org/apache/jmeter/samplers/SampleResult.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,13 +1681,13 @@ public void setTestLogicalAction(TestLogicalAction testLogicalAction) {
16811681
}
16821682

16831683
/**
1684-
* Sets the response data and its compression encoding.
1684+
* Sets the response data and its contentEncoding.
16851685
* @param data The response data
1686-
* @param encoding The content encoding (e.g. gzip, deflate)
1686+
* @param contentEncoding The content contentEncoding (e.g. gzip, deflate)
16871687
*/
1688-
public void setResponseData(byte[] data, String encoding) {
1688+
public void setResponseData(byte[] data, String contentEncoding) {
16891689
responseData = data == null ? EMPTY_BA : data;
1690-
contentEncoding = encoding;
1690+
this.contentEncoding = contentEncoding;
16911691
responseDataAsString = null;
16921692
}
16931693
}

src/core/src/main/java/org/apache/jmeter/testbeans/gui/EnumEditor.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import javax.swing.JList;
3232

3333
import org.apache.jmeter.gui.ClearGui;
34+
import org.apache.jorphan.gui.LocalizableEnum;
3435
import org.apache.jorphan.util.EnumUtils;
3536

3637
/**
@@ -41,34 +42,32 @@
4142
* The provided GUI is a combo box with an option for each value in the enum.
4243
* <p>
4344
*/
44-
class EnumEditor extends PropertyEditorSupport implements ClearGui {
45+
class EnumEditor<T extends Enum<?> & LocalizableEnum> extends PropertyEditorSupport implements ClearGui {
46+
private final JComboBox<T> combo;
4547

46-
private final JComboBox<Enum<?>> combo;
48+
private final T defaultValue;
4749

48-
private final Enum<?> defaultValue;
49-
50-
public EnumEditor(final PropertyDescriptor descriptor, final Class<? extends Enum<?>> enumClazz, final ResourceBundle rb) {
51-
DefaultComboBoxModel<Enum<?>> model = new DefaultComboBoxModel<>();
50+
public EnumEditor(final PropertyDescriptor descriptor, final Class<T> enumClass, final ResourceBundle rb) {
51+
DefaultComboBoxModel<T> model = new DefaultComboBoxModel<>();
5252
combo = new JComboBox<>(model);
5353
combo.setEditable(false);
5454
combo.setRenderer(
5555
new DefaultListCellRenderer() {
5656
@Override
5757
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
5858
JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
59-
Enum<?> enumValue = (Enum<?>) value;
60-
label.setText(rb.getString(EnumUtils.getStringValue(enumValue)));
59+
label.setText(rb.getString(enumClass.cast(value).getResourceKey()));
6160
return label;
6261
}
6362
}
6463
);
65-
List<? extends Enum<?>> values = EnumUtils.values(enumClazz);
66-
for(Enum<?> e : values) {
64+
List<T> values = EnumUtils.getEnumValues(enumClass);
65+
for (T e : values) {
6766
model.addElement(e);
6867
}
6968
Object def = descriptor.getValue(GenericTestBeanCustomizer.DEFAULT);
7069
if (def instanceof Enum<?> enumValue) {
71-
defaultValue = enumValue;
70+
defaultValue = enumClass.cast(enumValue);
7271
} else if (def instanceof Integer index) {
7372
defaultValue = values.get(index);
7473
} else {
@@ -99,25 +98,24 @@ public void setValue(Object value) {
9998
} else if (value instanceof Integer integer) {
10099
combo.setSelectedIndex(integer);
101100
} else if (value instanceof String string) {
102-
ComboBoxModel<Enum<?>> model = combo.getModel();
103-
for (int i = 0; i < model.getSize(); i++) {
104-
Enum<?> element = model.getElementAt(i);
105-
if (EnumUtils.getStringValue(element).equals(string)) {
106-
combo.setSelectedItem(element);
107-
return;
108-
}
109-
}
101+
setAsText(string);
110102
}
111103
}
112104

113105
@Override
114106
public void setAsText(String value) {
115-
throw new UnsupportedOperationException("Not supported yet. Use enum value rather than text, got " + value);
107+
ComboBoxModel<T> model = combo.getModel();
108+
for (int i = 0; i < model.getSize(); i++) {
109+
T element = model.getElementAt(i);
110+
if (value.equals(element.getResourceKey())) {
111+
combo.setSelectedItem(element);
112+
return;
113+
}
114+
}
116115
}
117116

118117
@Override
119118
public void clearGui() {
120119
combo.setSelectedItem(defaultValue);
121120
}
122-
123121
}

src/core/src/main/java/org/apache/jmeter/testbeans/gui/GenericTestBeanCustomizer.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@
4343
import javax.swing.JScrollPane;
4444
import javax.swing.SwingConstants;
4545

46-
import org.apache.jmeter.JMeter;
4746
import org.apache.jmeter.gui.ClearGui;
4847
import org.apache.jmeter.testbeans.TestBeanHelper;
4948
import org.apache.jmeter.testelement.property.IntegerProperty;
5049
import org.apache.jmeter.testelement.property.JMeterProperty;
5150
import org.apache.jmeter.testelement.property.LongProperty;
5251
import org.apache.jmeter.testelement.property.StringProperty;
5352
import org.apache.jmeter.util.JMeterUtils;
53+
import org.apache.jorphan.gui.LocalizableEnum;
5454
import org.apache.jorphan.util.EnumUtils;
5555
import org.apiguardian.api.API;
5656
import org.jspecify.annotations.Nullable;
@@ -338,9 +338,9 @@ public GenericTestBeanCustomizer(){
338338
* @return a StringProperty containing the normalized enum value, or null if the property is invalid or unrecognized
339339
*/
340340
@API(status = API.Status.INTERNAL, since = "6.0.0")
341-
public static <T extends Enum<?>> @Nullable JMeterProperty normalizeEnumProperty(
341+
public static <T extends Enum<?> & LocalizableEnum> @Nullable JMeterProperty normalizeEnumProperty(
342342
Class<?> klass, Class<T> enumKlass, JMeterProperty property) {
343-
List<T> values = EnumUtils.values(enumKlass);
343+
List<T> values = EnumUtils.getEnumValues(enumKlass);
344344
T value;
345345
if (property instanceof IntegerProperty intProperty) {
346346
int index = intProperty.getIntValue();
@@ -362,26 +362,26 @@ public GenericTestBeanCustomizer(){
362362
return null;
363363
}
364364
value = normalizeEnumStringValue(stringValue, klass, enumKlass);
365-
if (stringValue.equals(EnumUtils.getStringValue(value))) {
365+
if (stringValue.equals(value.getResourceKey())) {
366366
// If the input property was good enough, keep it
367367
return property;
368368
}
369369
} else {
370370
return null;
371371
}
372-
return new StringProperty(property.getName(), EnumUtils.getStringValue(value));
372+
return new StringProperty(property.getName(), value.getResourceKey());
373373
}
374374

375375
@API(status = API.Status.INTERNAL, since = "6.0.0")
376-
public static <T extends Enum<?>> T normalizeEnumStringValue(String value, Class<?> klass, Class<T> enumKlass) {
376+
public static <T extends Enum<?> & LocalizableEnum> T normalizeEnumStringValue(String value, Class<?> klass, Class<T> enumKlass) {
377377
T enumValue = EnumUtils.valueOf(enumKlass, value);
378378
if (enumValue != null) {
379379
return enumValue;
380380
}
381-
return normalizeEnumStringValue(value, klass, EnumUtils.values(enumKlass));
381+
return normalizeEnumStringValue(value, klass, EnumUtils.getEnumValues(enumKlass));
382382
}
383383

384-
private static <T extends Enum<?>> T normalizeEnumStringValue(String value, Class<?> klass, List<T> values) {
384+
private static <T extends Enum<?> & LocalizableEnum> T normalizeEnumStringValue(String value, Class<?> klass, List<T> values) {
385385
// Fallback: the value might be localized, thus check the current and root locales
386386
String bundleName = null;
387387
try {
@@ -408,9 +408,9 @@ private static <T extends Enum<?>> T normalizeEnumStringValue(String value, Clas
408408
return findEnumValue(value, rootBundle, values);
409409
}
410410

411-
private static <T extends Enum<?>> @Nullable T findEnumValue(String stringValue, ResourceBundle rb, List<T> values) {
411+
private static <T extends Enum<?> & LocalizableEnum> @Nullable T findEnumValue(String stringValue, ResourceBundle rb, List<T> values) {
412412
for (T enumValue : values) {
413-
if (stringValue.equals(rb.getObject(enumValue.toString()))) {
413+
if (stringValue.equals(rb.getObject(enumValue.getResourceKey()))) {
414414
log.debug("Converted {} to {} using Locale: {}", stringValue, enumValue, rb.getLocale());
415415
return enumValue;
416416
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.jmeter.gui
19+
20+
import org.apache.jmeter.testelement.TestElement
21+
import org.apache.jmeter.testelement.schema.StringPropertyDescriptor
22+
import org.apiguardian.api.API
23+
import javax.swing.JComboBox
24+
25+
/**
26+
* Simple binding for a string-based combo box to a test element property.
27+
*
28+
* This binding is for non-enum combo boxes where the combo box items are
29+
* plain strings that should be stored as-is in the property (e.g., httpImplementation).
30+
*
31+
* For enum-based combo boxes with localization, use [JEnumPropertyEditor] instead.
32+
*
33+
* Example usage:
34+
* ```java
35+
* private final JComboBox<String> implementation = new JComboBox<>(
36+
* new String[] {"httpclient4", "java", ""}
37+
* );
38+
*
39+
* bindingGroup.add(new JComboBoxStringBinding(
40+
* implementation,
41+
* schema.getImplementation()
42+
* ));
43+
* ```
44+
*
45+
* @property comboBox the JComboBox component to bind
46+
* @property property the string property descriptor
47+
* @since 6.0.0
48+
*/
49+
@API(status = API.Status.EXPERIMENTAL, since = "6.0.0")
50+
public class JComboBoxStringBinding(
51+
private val comboBox: JComboBox<String>,
52+
private val property: StringPropertyDescriptor<*>
53+
) : Binding {
54+
55+
/**
56+
* Updates the test element with the currently selected value from the combo box.
57+
*
58+
* If the selected value is null or blank and there's no default value,
59+
* the property is removed from the element.
60+
*/
61+
override fun updateElement(testElement: TestElement) {
62+
val selectedValue = comboBox.selectedItem as? String
63+
64+
if (selectedValue.isNullOrBlank() && property.defaultValue.isNullOrBlank()) {
65+
// Remove property if empty and no default
66+
testElement.removeProperty(property.name)
67+
} else {
68+
testElement.set(property, selectedValue ?: "")
69+
}
70+
}
71+
72+
/**
73+
* Updates the combo box selection based on the value stored in the test element.
74+
*
75+
* If the property value is not found in the combo box items, sets it anyway
76+
* (useful for editable combo boxes).
77+
*/
78+
override fun updateUi(testElement: TestElement) {
79+
val value = testElement[property] ?: property.defaultValue ?: ""
80+
comboBox.selectedItem = value
81+
}
82+
}

0 commit comments

Comments
 (0)