Search in sources :

Example 1 with MultiProperty

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

the class MultiPropertyConverter method unmarshal.

/** {@inheritDoc} */
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    MultiProperty prop = (MultiProperty) createCollection(context.getRequiredType());
    prop.setName(ConversionHelp.decode(reader.getAttribute(ConversionHelp.ATT_NAME)));
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        JMeterProperty subProp = (JMeterProperty) readItem(reader, context, prop);
        if (subProp != null) {
            // could be null if it has been deleted via NameUpdater
            prop.addProperty(subProp);
        }
        reader.moveUp();
    }
    return prop;
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) MultiProperty(org.apache.jmeter.testelement.property.MultiProperty)

Example 2 with MultiProperty

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

the class TestBeanHelper method unwrapProperty.

private static Object unwrapProperty(PropertyDescriptor desc, JMeterProperty jprop, Class<?> type) {
    Object value;
    if (jprop instanceof TestElementProperty) {
        TestElement te = ((TestElementProperty) jprop).getElement();
        if (te instanceof TestBean) {
            prepare(te);
        }
        value = te;
    } else if (jprop instanceof MultiProperty) {
        value = unwrapCollection((MultiProperty) jprop, (String) desc.getValue(TableEditor.CLASSNAME));
    } else // value was not provided, and this is allowed
    if (jprop instanceof NullProperty && // use negative condition so missing (null) value is treated as FALSE
    !Boolean.TRUE.equals(desc.getValue(GenericTestBeanCustomizer.NOT_UNDEFINED))) {
        value = null;
    } else {
        value = Converter.convert(jprop.getStringValue(), type);
    }
    return value;
}
Also used : NullProperty(org.apache.jmeter.testelement.property.NullProperty) TestElementProperty(org.apache.jmeter.testelement.property.TestElementProperty) MultiProperty(org.apache.jmeter.testelement.property.MultiProperty) TestElement(org.apache.jmeter.testelement.TestElement)

Example 3 with MultiProperty

use of org.apache.jmeter.testelement.property.MultiProperty 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 LinkedList<>();
    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) StringProperty(org.apache.jmeter.testelement.property.StringProperty) MultiProperty(org.apache.jmeter.testelement.property.MultiProperty) LinkedList(java.util.LinkedList) NumberProperty(org.apache.jmeter.testelement.property.NumberProperty)

Example 4 with MultiProperty

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

the class MultiPropertyConverter method marshal.

/** {@inheritDoc} */
@Override
public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingContext context) {
    MultiProperty prop = (MultiProperty) arg0;
    writer.addAttribute(ConversionHelp.ATT_NAME, ConversionHelp.encode(prop.getName()));
    for (JMeterProperty jMeterProperty : prop) {
        writeItem(jMeterProperty, context, writer);
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) MultiProperty(org.apache.jmeter.testelement.property.MultiProperty)

Aggregations

MultiProperty (org.apache.jmeter.testelement.property.MultiProperty)4 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)3 LinkedList (java.util.LinkedList)1 TestElement (org.apache.jmeter.testelement.TestElement)1 NullProperty (org.apache.jmeter.testelement.property.NullProperty)1 NumberProperty (org.apache.jmeter.testelement.property.NumberProperty)1 StringProperty (org.apache.jmeter.testelement.property.StringProperty)1 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)1