Search in sources :

Example 16 with StringProperty

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"));
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) StringProperty(org.apache.jmeter.testelement.property.StringProperty) Test(org.junit.Test)

Example 17 with StringProperty

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());
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) StringProperty(org.apache.jmeter.testelement.property.StringProperty) Test(org.junit.Test)

Example 18 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)

Example 19 with StringProperty

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());
}
Also used : StringProperty(org.apache.jmeter.testelement.property.StringProperty)

Example 20 with StringProperty

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()));
    }
}
Also used : TestElementProperty(org.apache.jmeter.testelement.property.TestElementProperty) BooleanProperty(org.apache.jmeter.testelement.property.BooleanProperty) StringProperty(org.apache.jmeter.testelement.property.StringProperty)

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