Search in sources :

Example 1 with StringProperty

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

the class LoginConfigGui method modifyTestElement.

/* Implements JMeterGUIComponent.modifyTestElement(TestElement) */
@Override
public void modifyTestElement(TestElement element) {
    configureTestElement(element);
    element.setProperty(new StringProperty(ConfigTestElement.USERNAME, username.getText()));
    String passwordString = new String(password.getPassword());
    element.setProperty(new StringProperty(ConfigTestElement.PASSWORD, passwordString));
}
Also used : StringProperty(org.apache.jmeter.testelement.property.StringProperty)

Example 2 with StringProperty

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

the class ReplaceFunctionsWithStrings method transformValue.

@Override
public JMeterProperty transformValue(JMeterProperty prop) throws InvalidVariableException {
    PatternMatcher pm = JMeterUtils.getMatcher();
    PatternCompiler compiler = new Perl5Compiler();
    String input = prop.getStringValue();
    if (input == null) {
        return prop;
    }
    for (Entry<String, String> entry : getVariables().entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        if (regexMatch) {
            try {
                Pattern pattern = compiler.compile(constructPattern(value));
                input = Util.substitute(pm, pattern, new StringSubstitution(FUNCTION_REF_PREFIX + key + FUNCTION_REF_SUFFIX), input, Util.SUBSTITUTE_ALL);
            } catch (MalformedPatternException e) {
                log.warn("Malformed pattern: {}", value);
            }
        } else {
            input = StringUtilities.substitute(input, value, FUNCTION_REF_PREFIX + key + FUNCTION_REF_SUFFIX);
        }
    }
    return new StringProperty(prop.getName(), input);
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) Pattern(org.apache.oro.text.regex.Pattern) PatternCompiler(org.apache.oro.text.regex.PatternCompiler) StringProperty(org.apache.jmeter.testelement.property.StringProperty) StringSubstitution(org.apache.oro.text.regex.StringSubstitution) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) PatternMatcher(org.apache.oro.text.regex.PatternMatcher)

Example 3 with StringProperty

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

the class WhileController method setCondition.

/**
     * @param string
     *            the condition to save
     */
public void setCondition(String string) {
    log.debug("setCondition({})", string);
    setProperty(new StringProperty(CONDITION, string));
}
Also used : StringProperty(org.apache.jmeter.testelement.property.StringProperty)

Example 4 with StringProperty

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

the class StringPropertyConverter method unmarshal.

/** {@inheritDoc} */
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    final String name = ConversionHelp.getPropertyName(reader, context);
    if (name == null) {
        return null;
    }
    final String value = ConversionHelp.getPropertyValue(reader, context, name);
    StringProperty prop = new StringProperty(name, value);
    return prop;
}
Also used : StringProperty(org.apache.jmeter.testelement.property.StringProperty)

Example 5 with StringProperty

use of org.apache.jmeter.testelement.property.StringProperty 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)

Aggregations

StringProperty (org.apache.jmeter.testelement.property.StringProperty)47 Test (org.junit.Test)26 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)23 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)9 TestElement (org.apache.jmeter.testelement.TestElement)7 TestPlan (org.apache.jmeter.testelement.TestPlan)4 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)3 BeanInfo (java.beans.BeanInfo)2 IntrospectionException (java.beans.IntrospectionException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ResourceBundle (java.util.ResourceBundle)2 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)2 ReplaceStringWithFunctions (org.apache.jmeter.engine.util.ReplaceStringWithFunctions)2 TestSampler (org.apache.jmeter.junit.stubs.TestSampler)2 BooleanProperty (org.apache.jmeter.testelement.property.BooleanProperty)2 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)2 NullProperty (org.apache.jmeter.testelement.property.NullProperty)2 JMeterContext (org.apache.jmeter.threads.JMeterContext)2