Search in sources :

Example 1 with NumberProperty

use of org.apache.jmeter.testelement.property.NumberProperty in project jmeter by apache.

the class ValueReplacer method replaceValues.

/**
 * Replaces a {@link StringProperty} containing functions with their Function properties equivalent.
 * <p>For example:
 * <code>${__time()}_${__threadNum()}_${__machineName()}</code> will become a
 * {@link org.apache.jmeter.testelement.property.FunctionProperty} of
 * a {@link CompoundVariable} containing three functions
 * @param iter the {@link PropertyIterator} over all properties, in which the values should be replaced
 * @param transform the {@link ValueTransformer}, that should do transformation
 * @return a new {@link Collection} with all the transformed {@link JMeterProperty}s
 * @throws InvalidVariableException when <code>transform</code> throws an {@link InvalidVariableException} while transforming a value
 */
private Collection<JMeterProperty> replaceValues(PropertyIterator iter, ValueTransformer transform) throws InvalidVariableException {
    List<JMeterProperty> props = new ArrayList<>();
    while (iter.hasNext()) {
        JMeterProperty val = iter.next();
        if (log.isDebugEnabled()) {
            log.debug("About to replace in property of type: {}: {}", val.getClass(), val);
        }
        if (val instanceof StringProperty) {
            // Must not convert TestElement.gui_class etc
            if (!val.getName().equals(TestElement.GUI_CLASS) && !val.getName().equals(TestElement.TEST_CLASS)) {
                val = transform.transformValue(val);
                log.debug("Replacement result: {}", val);
            }
        } else if (val instanceof NumberProperty) {
            val = transform.transformValue(val);
            log.debug("Replacement result: {}", val);
        } else if (val instanceof MultiProperty) {
            MultiProperty multiVal = (MultiProperty) val;
            Collection<JMeterProperty> newValues = replaceValues(multiVal.iterator(), transform);
            multiVal.clear();
            for (JMeterProperty jmp : newValues) {
                multiVal.addProperty(jmp);
            }
            log.debug("Replacement result: {}", multiVal);
        } else {
            log.debug("Won't replace {}", val);
        }
        props.add(val);
    }
    return props;
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) ArrayList(java.util.ArrayList) StringProperty(org.apache.jmeter.testelement.property.StringProperty) MultiProperty(org.apache.jmeter.testelement.property.MultiProperty) NumberProperty(org.apache.jmeter.testelement.property.NumberProperty)

Example 2 with NumberProperty

use of org.apache.jmeter.testelement.property.NumberProperty in project jmeter by apache.

the class TestNumberProperty method testCompareToMinMax.

@Test
public void testCompareToMinMax() {
    NumberProperty n1 = new DoubleProperty("n1", Double.MIN_VALUE);
    NumberProperty n2 = new DoubleProperty("n2", Double.MAX_VALUE);
    assertTrue(n1.compareTo(n2) < 0);
}
Also used : DoubleProperty(org.apache.jmeter.testelement.property.DoubleProperty) NumberProperty(org.apache.jmeter.testelement.property.NumberProperty) Test(org.junit.jupiter.api.Test)

Example 3 with NumberProperty

use of org.apache.jmeter.testelement.property.NumberProperty in project jmeter by apache.

the class TestNumberProperty method testDZeroCompareToDZero.

@Test
public void testDZeroCompareToDZero() {
    NumberProperty n1 = new DoubleProperty("n1", 0.0);
    NumberProperty n2 = new DoubleProperty("n2", 0.0);
    assertEquals(0, n1.compareTo(n2));
}
Also used : DoubleProperty(org.apache.jmeter.testelement.property.DoubleProperty) NumberProperty(org.apache.jmeter.testelement.property.NumberProperty) Test(org.junit.jupiter.api.Test)

Example 4 with NumberProperty

use of org.apache.jmeter.testelement.property.NumberProperty in project jmeter by apache.

the class TestNumberProperty method testIZeroCompareToDZero.

@Test
public void testIZeroCompareToDZero() {
    NumberProperty n1 = new IntegerProperty("n1", 0);
    NumberProperty n2 = new DoubleProperty("n2", 0.0);
    assertEquals(0, n1.compareTo(n2));
}
Also used : IntegerProperty(org.apache.jmeter.testelement.property.IntegerProperty) DoubleProperty(org.apache.jmeter.testelement.property.DoubleProperty) NumberProperty(org.apache.jmeter.testelement.property.NumberProperty) Test(org.junit.jupiter.api.Test)

Example 5 with NumberProperty

use of org.apache.jmeter.testelement.property.NumberProperty in project jmeter by apache.

the class TestNumberProperty method testCompareToNegative.

@Test
public void testCompareToNegative() {
    NumberProperty n1 = new DoubleProperty("n1", -1.0);
    NumberProperty n2 = new DoubleProperty("n2", 0.0);
    assertTrue(n1.compareTo(n2) < 0);
}
Also used : DoubleProperty(org.apache.jmeter.testelement.property.DoubleProperty) NumberProperty(org.apache.jmeter.testelement.property.NumberProperty) Test(org.junit.jupiter.api.Test)

Aggregations

NumberProperty (org.apache.jmeter.testelement.property.NumberProperty)6 DoubleProperty (org.apache.jmeter.testelement.property.DoubleProperty)5 Test (org.junit.jupiter.api.Test)5 ArrayList (java.util.ArrayList)1 IntegerProperty (org.apache.jmeter.testelement.property.IntegerProperty)1 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)1 MultiProperty (org.apache.jmeter.testelement.property.MultiProperty)1 StringProperty (org.apache.jmeter.testelement.property.StringProperty)1