View | Details | Raw Unified | Return to bug 64928
Collapse All | Expand All

(-)a/src/components/src/main/java/org/apache/jmeter/timers/ConstantThroughputTimerBeanInfo.java (+18 lines)
Lines 18-31 Link Here
18
package org.apache.jmeter.timers;
18
package org.apache.jmeter.timers;
19
19
20
import java.beans.PropertyDescriptor;
20
import java.beans.PropertyDescriptor;
21
import java.util.function.Function;
21
22
22
import org.apache.jmeter.testbeans.BeanInfoSupport;
23
import org.apache.jmeter.testbeans.BeanInfoSupport;
24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
23
26
24
/**
27
/**
25
 * BeanInfo for the ConstantThroughputTimer.
28
 * BeanInfo for the ConstantThroughputTimer.
26
 */
29
 */
27
public class ConstantThroughputTimerBeanInfo extends BeanInfoSupport {
30
public class ConstantThroughputTimerBeanInfo extends BeanInfoSupport {
28
31
32
    private static Logger log = LoggerFactory.getLogger(ConstantThroughputTimerBeanInfo.class);
33
29
    public ConstantThroughputTimerBeanInfo() {
34
    public ConstantThroughputTimerBeanInfo() {
30
        super(ConstantThroughputTimer.class);
35
        super(ConstantThroughputTimer.class);
31
36
Lines 36-45 public class ConstantThroughputTimerBeanInfo extends BeanInfoSupport { Link Here
36
        PropertyDescriptor p = property("throughput"); //$NON-NLS-1$
41
        PropertyDescriptor p = property("throughput"); //$NON-NLS-1$
37
        p.setValue(NOT_UNDEFINED, Boolean.TRUE);
42
        p.setValue(NOT_UNDEFINED, Boolean.TRUE);
38
        p.setValue(DEFAULT, 0.0);
43
        p.setValue(DEFAULT, 0.0);
44
        p.setValue(VALIDATOR, (Function<Object, Boolean>) ConstantThroughputTimerBeanInfo::validateThroughput);
39
45
40
        p = property("calcMode", ConstantThroughputTimer.Mode.class); //$NON-NLS-1$
46
        p = property("calcMode", ConstantThroughputTimer.Mode.class); //$NON-NLS-1$
41
        p.setValue(DEFAULT, ConstantThroughputTimer.Mode.ThisThreadOnly.ordinal());
47
        p.setValue(DEFAULT, ConstantThroughputTimer.Mode.ThisThreadOnly.ordinal());
42
        p.setValue(NOT_UNDEFINED, Boolean.TRUE); // must be defined
48
        p.setValue(NOT_UNDEFINED, Boolean.TRUE); // must be defined
43
    }
49
    }
44
50
51
    private static boolean validateThroughput(Object o) {
52
        try {
53
            double value = Double.parseDouble(o.toString());
54
            if (value < 0) {
55
                log.warn("Number must not be less than zero: [{}]", value);
56
            }
57
        } catch (NumberFormatException e) {
58
            log.warn("No valid number: [{}]", o);
59
        }
60
        return false;
61
    }
62
45
}
63
}
(-)a/src/core/src/main/java/org/apache/jmeter/testbeans/BeanInfoSupport.java (+3 lines)
Lines 91-96 public abstract class BeanInfoSupport extends SimpleBeanInfo { Link Here
91
    /** TextEditor property */
91
    /** TextEditor property */
92
    public static final String TEXT_LANGUAGE = GenericTestBeanCustomizer.TEXT_LANGUAGE;
92
    public static final String TEXT_LANGUAGE = GenericTestBeanCustomizer.TEXT_LANGUAGE;
93
93
94
    /** An optional validator, that is a Function<Object, Boolean> **/
95
    public static final String VALIDATOR = GenericTestBeanCustomizer.VALIDATOR;
96
94
    /** The BeanInfo for our class as obtained by the introspector. */
97
    /** The BeanInfo for our class as obtained by the introspector. */
95
    private final BeanInfo rootBeanInfo;
98
    private final BeanInfo rootBeanInfo;
96
99
(-)a/src/core/src/main/java/org/apache/jmeter/testbeans/TestBeanHelper.java (+13 lines)
Lines 25-30 import java.lang.reflect.InvocationTargetException; Link Here
25
import java.lang.reflect.Method;
25
import java.lang.reflect.Method;
26
import java.util.ArrayList;
26
import java.util.ArrayList;
27
import java.util.Collection;
27
import java.util.Collection;
28
import java.util.function.Function;
28
29
29
import org.apache.jmeter.testbeans.gui.GenericTestBeanCustomizer;
30
import org.apache.jmeter.testbeans.gui.GenericTestBeanCustomizer;
30
import org.apache.jmeter.testbeans.gui.TableEditor;
31
import org.apache.jmeter.testbeans.gui.TableEditor;
Lines 83-88 public class TestBeanHelper { Link Here
83
                Class<?> type = desc.getPropertyType();
84
                Class<?> type = desc.getPropertyType();
84
                Object value = unwrapProperty(desc, jprop, type);
85
                Object value = unwrapProperty(desc, jprop, type);
85
86
87
                validateObjectValue(desc, jprop, value);
86
                if (log.isDebugEnabled()) {
88
                if (log.isDebugEnabled()) {
87
                    log.debug("Setting {}={}", jprop.getName(), value);
89
                    log.debug("Setting {}={}", jprop.getName(), value);
88
                }
90
                }
Lines 105-110 public class TestBeanHelper { Link Here
105
        }
107
        }
106
    }
108
    }
107
109
110
    private static void validateObjectValue(PropertyDescriptor desc, JMeterProperty jprop, Object value) {
111
        Object validator = desc.getValue(BeanInfoSupport.VALIDATOR);
112
        if (validator instanceof Function) {
113
            @SuppressWarnings("unchecked")
114
            Function<Object, Boolean> validatorFunction = (Function<Object, Boolean>) validator;
115
            if (!validatorFunction.apply(value)) {
116
                log.warn("Invalid value [{}] for property [{}]", value, jprop.getName());
117
            }
118
        }
119
    }
120
108
    private static Object unwrapProperty(PropertyDescriptor desc, JMeterProperty jprop, Class<?> type) {
121
    private static Object unwrapProperty(PropertyDescriptor desc, JMeterProperty jprop, Class<?> type) {
109
        Object value;
122
        Object value;
110
        if(jprop instanceof TestElementProperty)
123
        if(jprop instanceof TestElementProperty)
(-)a/src/core/src/main/java/org/apache/jmeter/testbeans/gui/GenericTestBeanCustomizer.java (-1 / +3 lines)
Lines 96-102 import org.slf4j.LoggerFactory; Link Here
96
 * </dl>
96
 * </dl>
97
 */
97
 */
98
public class GenericTestBeanCustomizer extends JPanel implements SharedCustomizer {
98
public class GenericTestBeanCustomizer extends JPanel implements SharedCustomizer {
99
    private static final long serialVersionUID = 241L;
99
    private static final long serialVersionUID = 242L;
100
100
101
    private static final Logger log = LoggerFactory.getLogger(GenericTestBeanCustomizer.class);
101
    private static final Logger log = LoggerFactory.getLogger(GenericTestBeanCustomizer.class);
102
102
Lines 160-165 public class GenericTestBeanCustomizer extends JPanel implements SharedCustomize Link Here
160
160
161
    public static final String DEFAULT_GROUP = "";
161
    public static final String DEFAULT_GROUP = "";
162
162
163
    public static final String VALIDATOR = "validator";
164
163
    @SuppressWarnings("unused") // TODO - use or remove
165
    @SuppressWarnings("unused") // TODO - use or remove
164
    private int scrollerCount = 0;
166
    private int scrollerCount = 0;
165
167

Return to bug 64928