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));
}
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);
}
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));
}
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;
}
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;
}
Aggregations