Search in sources :

Example 31 with PropertyIterator

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

the class TestElementConverter method marshal.

/**
 * {@inheritDoc}
 */
@Override
public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingContext context) {
    TestElement el = (TestElement) arg0;
    ConversionHelp.saveSpecialProperties(el, writer);
    PropertyIterator iter = el.propertyIterator();
    while (iter.hasNext()) {
        JMeterProperty jmp = iter.next();
        // Skip special properties if required
        if (!ConversionHelp.isSpecialProperty(jmp.getName())) {
            // Don't save empty comments - except for the TestPlan (to maintain compatibility)
            if (!(TestElement.COMMENTS.equals(jmp.getName()) && jmp.getStringValue().length() == 0 && !el.getClass().equals(TestPlan.class))) {
                writeCompleteItem(jmp, context, writer);
            }
        }
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator) TestElement(org.apache.jmeter.testelement.TestElement)

Example 32 with PropertyIterator

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

the class HTTPSamplerBase method getQueryString.

/**
 * Gets the QueryString attribute of the UrlConfig object, using the
 * specified encoding to encode the parameter values put into the URL
 *
 * @param contentEncoding the encoding to use for encoding parameter values
 * @return the QueryString value
 */
public String getQueryString(final String contentEncoding) {
    CollectionProperty arguments = getArguments().getArguments();
    // Optimisation : avoid building useless objects if empty arguments
    if (arguments.isEmpty()) {
        return "";
    }
    String lContentEncoding = contentEncoding;
    // Check if the sampler has a specified content encoding
    if (JOrphanUtils.isBlank(lContentEncoding)) {
        // We use the encoding which should be used according to the HTTP spec, which is UTF-8
        lContentEncoding = EncoderCache.URL_ARGUMENT_ENCODING;
    }
    StringBuilder buf = new StringBuilder(arguments.size() * 15);
    PropertyIterator iter = arguments.iterator();
    boolean first = true;
    while (iter.hasNext()) {
        HTTPArgument item = null;
        /*
             * N.B. Revision 323346 introduced the ClassCast check, but then used iter.next()
             * to fetch the item to be cast, thus skipping the element that did not cast.
             * Reverted to work more like the original code, but with the check in place.
             * Added a warning message so can track whether it is necessary
             */
        Object objectValue = iter.next().getObjectValue();
        try {
            item = (HTTPArgument) objectValue;
        } catch (ClassCastException e) {
            // NOSONAR
            log.warn("Unexpected argument type: {} cannot be cast to HTTPArgument", objectValue.getClass().getName());
            item = new HTTPArgument((Argument) objectValue);
        }
        final String encodedName = item.getEncodedName();
        if (encodedName.isEmpty()) {
            // Skip parameters with a blank name (allows use of optional variables in parameter lists)
            continue;
        }
        if (!first) {
            buf.append(QRY_SEP);
        } else {
            first = false;
        }
        buf.append(encodedName);
        if (item.getMetaData() == null) {
            buf.append(ARG_VAL_SEP);
        } else {
            buf.append(item.getMetaData());
        }
        // Encode the parameter value in the specified content encoding
        try {
            buf.append(item.getEncodedValue(lContentEncoding));
        } catch (UnsupportedEncodingException e) {
            // NOSONAR
            log.warn("Unable to encode parameter in encoding {}, parameter value not included in query string", lContentEncoding);
        }
    }
    return buf.toString();
}
Also used : CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) HTTPArgument(org.apache.jmeter.protocol.http.util.HTTPArgument) PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 33 with PropertyIterator

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

the class FunctionHelper method buildFunctionCallString.

private String buildFunctionCallString(String functionName, Arguments args) {
    StringBuilder functionCall = new StringBuilder("${");
    functionCall.append(functionName);
    if (args.getArguments().size() > 0) {
        functionCall.append("(");
        PropertyIterator iter = args.iterator();
        boolean first = true;
        while (iter.hasNext()) {
            Argument arg = (Argument) iter.next().getObjectValue();
            if (!first) {
                functionCall.append(",");
            }
            functionCall.append(escapeCommata(arg.getValue()));
            first = false;
        }
        functionCall.append(")");
    }
    functionCall.append("}");
    return functionCall.toString();
}
Also used : Argument(org.apache.jmeter.config.Argument) PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator)

Example 34 with PropertyIterator

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

the class AbstractTestElement method mergeIn.

/**
 * Add to this the properties of element (by reference)
 * @param element {@link TestElement}
 */
protected void mergeIn(TestElement element) {
    PropertyIterator iter = element.propertyIterator();
    while (iter.hasNext()) {
        JMeterProperty prop = iter.next();
        addProperty(prop, false);
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator)

Example 35 with PropertyIterator

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

the class AbstractTestElement method logProperties.

/**
 * Log the properties of the test element
 *
 * @see TestElement#setProperty(JMeterProperty)
 */
protected void logProperties() {
    if (log.isDebugEnabled()) {
        PropertyIterator iter = propertyIterator();
        while (iter.hasNext()) {
            JMeterProperty prop = iter.next();
            log.debug("Property {} is temp? {} and is a {}", prop.getName(), isTemporary(prop), prop.getObjectValue());
        }
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator)

Aggregations

PropertyIterator (org.apache.jmeter.testelement.property.PropertyIterator)36 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)12 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)8 ArrayList (java.util.ArrayList)4 Argument (org.apache.jmeter.config.Argument)4 HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)3 Test (org.junit.jupiter.api.Test)3 BasicAttribute (javax.naming.directory.BasicAttribute)2 ModificationItem (javax.naming.directory.ModificationItem)2 NameValuePair (org.apache.http.NameValuePair)2 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)2 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)2 Customizer (java.beans.Customizer)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 Charset (java.nio.charset.Charset)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1