Search in sources :

Example 16 with JMeterProperty

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

the class TestBeanHelper method prepare.

/**
     * Prepare the bean for work by populating the bean's properties from the
     * property value map.
     * <p>
     *
     * @param el the TestElement to be prepared
     */
public static void prepare(TestElement el) {
    if (!(el instanceof TestBean)) {
        return;
    }
    try {
        BeanInfo beanInfo = Introspector.getBeanInfo(el.getClass());
        PropertyDescriptor[] descs = beanInfo.getPropertyDescriptors();
        if (log.isDebugEnabled()) {
            log.debug("Preparing {}", el.getClass());
        }
        for (PropertyDescriptor desc : descs) {
            if (isDescriptorIgnored(desc)) {
                if (log.isDebugEnabled()) {
                    log.debug("Ignoring property '{}' in {}", desc.getName(), el.getClass().getCanonicalName());
                }
                continue;
            }
            // Obtain a value of the appropriate type for this property.
            JMeterProperty jprop = el.getProperty(desc.getName());
            Class<?> type = desc.getPropertyType();
            Object value = unwrapProperty(desc, jprop, type);
            if (log.isDebugEnabled()) {
                log.debug("Setting {}={}", jprop.getName(), value);
            }
            // Set the bean's property to the value we just obtained:
            if (value != null || !type.isPrimitive()) // We can't assign null to primitive types.
            {
                Method writeMethod = desc.getWriteMethod();
                if (writeMethod != null) {
                    invokeOrBailOut(el, writeMethod, new Object[] { value });
                }
            }
        }
    } catch (IntrospectionException e) {
        log.error("Couldn't set properties for {}", el.getClass(), e);
    } catch (UnsatisfiedLinkError ule) {
        // Can occur running headless on Jenkins
        log.error("Couldn't set properties for {}", el.getClass());
        throw ule;
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException) Method(java.lang.reflect.Method)

Example 17 with JMeterProperty

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

the class TestBeanGUI method setPropertyInElement.

/**
     * @param element
     * @param name
     */
private void setPropertyInElement(TestElement element, String name, Object value) {
    JMeterProperty jprop = AbstractProperty.createProperty(value);
    jprop.setName(name);
    element.setProperty(jprop);
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty)

Example 18 with JMeterProperty

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

the class TestElementConverter method unmarshal.

/** {@inheritDoc} */
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    String classAttribute = reader.getAttribute(ConversionHelp.ATT_CLASS);
    Class<?> type;
    if (classAttribute == null) {
        type = mapper().realClass(reader.getNodeName());
    } else {
        type = mapper().realClass(classAttribute);
    }
    // Update the test class name if necessary (Bug 52466)
    String inputName = type.getName();
    String targetName = inputName;
    String guiClassName = SaveService.aliasToClass(reader.getAttribute(ConversionHelp.ATT_TE_GUICLASS));
    targetName = NameUpdater.getCurrentTestName(inputName, guiClassName);
    if (!targetName.equals(inputName)) {
        // remap the class name
        type = mapper().realClass(targetName);
    }
    // needed by property converters  (Bug 52466)
    context.put(SaveService.TEST_CLASS_NAME, targetName);
    try {
        TestElement el = (TestElement) type.newInstance();
        // No need to check version, just process the attributes if present
        ConversionHelp.restoreSpecialProperties(el, reader);
        // Slight hack - we need to ensure the TestClass is not reset by the previous call
        el.setProperty(TestElement.TEST_CLASS, targetName);
        while (reader.hasMoreChildren()) {
            reader.moveDown();
            JMeterProperty prop = (JMeterProperty) readItem(reader, context, el);
            if (prop != null) {
                // could be null if it has been deleted via NameUpdater
                el.setProperty(prop);
            }
            reader.moveUp();
        }
        return el;
    } catch (InstantiationException | IllegalAccessException e) {
        log.error("TestElement not instantiable: {}", type, e);
        return null;
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) TestElement(org.apache.jmeter.testelement.TestElement)

Example 19 with JMeterProperty

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

the class BackendListenerGui method actionPerformed.

/**
     * Handle action events for this component. This method currently handles
     * events for the classname combo box.
     *
     * @param event
     *            the ActionEvent to be handled
     */
@Override
public void actionPerformed(ActionEvent event) {
    if (event.getSource() == classnameCombo) {
        String className = ((String) classnameCombo.getSelectedItem()).trim();
        try {
            BackendListenerClient client = (BackendListenerClient) Class.forName(className, true, Thread.currentThread().getContextClassLoader()).newInstance();
            Arguments currArgs = new Arguments();
            argsPanel.modifyTestElement(currArgs);
            Map<String, String> currArgsMap = currArgs.getArgumentsAsMap();
            Arguments newArgs = new Arguments();
            Arguments testParams = null;
            try {
                testParams = client.getDefaultParameters();
            } catch (AbstractMethodError e) {
                log.warn("BackendListenerClient doesn't implement " + "getDefaultParameters.  Default parameters won't " + "be shown.  Please update your client class: {}", className);
            }
            if (testParams != null) {
                for (JMeterProperty jMeterProperty : testParams.getArguments()) {
                    Argument arg = (Argument) jMeterProperty.getObjectValue();
                    String name = arg.getName();
                    String value = arg.getValue();
                    // values that they did in the original test.
                    if (currArgsMap.containsKey(name)) {
                        String newVal = currArgsMap.get(name);
                        if (newVal != null && newVal.length() > 0) {
                            value = newVal;
                        }
                    }
                    newArgs.addArgument(name, value);
                }
            }
            argsPanel.configure(newArgs);
        } catch (Exception e) {
            log.error("Error getting argument list for {}", className, e);
        }
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Argument(org.apache.jmeter.config.Argument) Arguments(org.apache.jmeter.config.Arguments)

Example 20 with JMeterProperty

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

the class UrlConfigGui method computePostBody.

/**
     * Compute body data from arguments
     * @param arguments {@link Arguments}
     * @param crlfToLF whether to convert CRLF to LF
     * @return {@link String}
     */
private static String computePostBody(Arguments arguments, boolean crlfToLF) {
    StringBuilder postBody = new StringBuilder();
    for (JMeterProperty argument : arguments) {
        HTTPArgument arg = (HTTPArgument) argument.getObjectValue();
        String value = arg.getValue();
        if (crlfToLF) {
            // See modifyTestElement
            value = value.replaceAll("\r\n", "\n");
        }
        postBody.append(value);
    }
    return postBody.toString();
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) HTTPArgument(org.apache.jmeter.protocol.http.util.HTTPArgument)

Aggregations

JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)87 StringProperty (org.apache.jmeter.testelement.property.StringProperty)23 Test (org.junit.Test)23 PropertyIterator (org.apache.jmeter.testelement.property.PropertyIterator)13 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)12 Argument (org.apache.jmeter.config.Argument)11 ArrayList (java.util.ArrayList)9 HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)8 File (java.io.File)7 Arguments (org.apache.jmeter.config.Arguments)7 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)6 TestElement (org.apache.jmeter.testelement.TestElement)6 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)5 URL (java.net.URL)4 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 HashMap (java.util.HashMap)3 Sampler (org.apache.jmeter.samplers.Sampler)3 TestPlan (org.apache.jmeter.testelement.TestPlan)3 NullProperty (org.apache.jmeter.testelement.property.NullProperty)3