use of org.apache.jmeter.testelement.property.StringProperty in project jmeter by apache.
the class PackageTest method testFunctionParse1.
@Test
public void testFunctionParse1() throws Exception {
StringProperty prop = new StringProperty("date", "${__javaScript((new Date().getDate() / 100).toString()." + "substr(${__javaScript(1+1,d\\,ay)}\\,2),heute)}");
JMeterProperty newProp = transformer.transformValue(prop);
newProp.setRunningVersion(true);
assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName());
newProp.recoverRunningVersion(null);
assertTrue(Integer.parseInt(newProp.getStringValue()) > -1);
assertEquals("2", jmctx.getVariables().getObject("d,ay"));
}
use of org.apache.jmeter.testelement.property.StringProperty in project jmeter by apache.
the class PackageTest method testParseExample11.
// Escaped dollar commma and backslash with no variable reference
@Test
public void testParseExample11() throws Exception {
StringProperty prop = new StringProperty("html", "\\$a \\, \\\\ \\x \\ jakarta.apache.org");
JMeterProperty newProp = transformer.transformValue(prop);
newProp.setRunningVersion(true);
assertEquals("org.apache.jmeter.testelement.property.StringProperty", newProp.getClass().getName());
assertEquals("\\$a \\, \\\\ \\x \\ jakarta.apache.org", newProp.getStringValue());
}
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;
}
use of org.apache.jmeter.testelement.property.StringProperty in project jmeter by apache.
the class AbstractJMeterGuiComponent method configureTestElement.
/**
* This provides a convenience for extenders when they implement the
* {@link JMeterGUIComponent#modifyTestElement(TestElement)} method. This
* method will set the name, gui class, and test class for the created Test
* Element. It should be called by every extending class when
* creating/modifying Test Elements, as that will best assure consistent
* behavior.
*
* @param mc
* the TestElement being created.
*/
protected void configureTestElement(TestElement mc) {
mc.setName(getName());
mc.setProperty(new StringProperty(TestElement.GUI_CLASS, this.getClass().getName()));
mc.setProperty(new StringProperty(TestElement.TEST_CLASS, mc.getClass().getName()));
// This stores the state of the TestElement
log.debug("setting element to enabled: {}", enabled);
mc.setEnabled(enabled);
mc.setComment(getComment());
}
use of org.apache.jmeter.testelement.property.StringProperty in project jmeter by apache.
the class LdapConfigGui method modifyTestElement.
/**
* Modifies a given TestElement to mirror the data in the gui components.
*
* @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
*/
@Override
public void modifyTestElement(TestElement element) {
element.clear();
configureTestElement(element);
element.setProperty(LDAPSampler.SERVERNAME, servername.getText());
element.setProperty(LDAPSampler.PORT, port.getText());
element.setProperty(LDAPSampler.ROOTDN, rootdn.getText());
element.setProperty(new BooleanProperty(LDAPSampler.USER_DEFINED, userDefined.isSelected()));
if (addTest.isSelected()) {
element.setProperty(new StringProperty(LDAPSampler.TEST, LDAPSampler.ADD));
element.setProperty(new StringProperty(LDAPSampler.BASE_ENTRY_DN, add.getText()));
element.setProperty(new TestElementProperty(LDAPSampler.ARGUMENTS, tableAddPanel.createTestElement()));
}
if (modifyTest.isSelected()) {
element.setProperty(new StringProperty(LDAPSampler.TEST, LDAPSampler.MODIFY));
element.setProperty(new StringProperty(LDAPSampler.BASE_ENTRY_DN, modify.getText()));
element.setProperty(new TestElementProperty(LDAPSampler.ARGUMENTS, tableModifyPanel.createTestElement()));
}
if (deleteTest.isSelected()) {
element.setProperty(new StringProperty(LDAPSampler.TEST, LDAPSampler.DELETE));
element.setProperty(new StringProperty(LDAPSampler.DELETE, delete.getText()));
}
if (searchTest.isSelected()) {
element.setProperty(new StringProperty(LDAPSampler.TEST, LDAPSampler.SEARCHBASE));
element.setProperty(new StringProperty(LDAPSampler.SEARCHBASE, searchbase.getText()));
element.setProperty(new StringProperty(LDAPSampler.SEARCHFILTER, searchfilter.getText()));
}
}
Aggregations