Search in sources :

Example 16 with PropertyIterator

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

the class HTTPHC4Impl method createUrlEncodedFormEntity.

/**
 * Create UrlEncodedFormEntity from parameters
 * @param contentEncoding Content encoding may be null or empty
 * @return {@link UrlEncodedFormEntity}
 * @throws UnsupportedEncodingException
 */
private UrlEncodedFormEntity createUrlEncodedFormEntity(final String contentEncoding) throws UnsupportedEncodingException {
    // It is a normal request, with parameter names and values
    // Add the parameters
    PropertyIterator args = getArguments().iterator();
    List<NameValuePair> nvps = new ArrayList<>();
    String urlContentEncoding = contentEncoding;
    if (urlContentEncoding == null || urlContentEncoding.length() == 0) {
        // Use the default encoding for urls
        urlContentEncoding = EncoderCache.URL_ARGUMENT_ENCODING;
    }
    while (args.hasNext()) {
        HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
        // The HTTPClient always urlencodes both name and value,
        // so if the argument is already encoded, we have to decode
        // it before adding it to the post request
        String parameterName = arg.getName();
        if (arg.isSkippable(parameterName)) {
            continue;
        }
        String parameterValue = arg.getValue();
        if (!arg.isAlwaysEncoded()) {
            // The value is already encoded by the user
            // Must decode the value now, so that when the
            // httpclient encodes it, we end up with the same value
            // as the user had entered.
            parameterName = URLDecoder.decode(parameterName, urlContentEncoding);
            parameterValue = URLDecoder.decode(parameterValue, urlContentEncoding);
        }
        // Add the parameter, httpclient will urlencode it
        nvps.add(new BasicNameValuePair(parameterName, parameterValue));
    }
    return new UrlEncodedFormEntity(nvps, urlContentEncoding);
}
Also used : NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HTTPArgument(org.apache.jmeter.protocol.http.util.HTTPArgument) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator) ArrayList(java.util.ArrayList) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity)

Example 17 with PropertyIterator

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

the class ProxyControl method removeValuesFromSampler.

/**
 * Remove from the sampler all values which match the one provided by the
 * first configuration in the given collection which provides a value for
 * that property.
 *
 * @param sampler        Sampler to remove values from.
 * @param configurations ConfigTestElements in descending priority.
 */
private void removeValuesFromSampler(HTTPSamplerBase sampler, Collection<ConfigTestElement> configurations) {
    PropertyIterator props = sampler.propertyIterator();
    while (props.hasNext()) {
        JMeterProperty prop = props.next();
        String name = prop.getName();
        String value = prop.getStringValue();
        // There's a few properties which are excluded from this processing:
        if (name.equals(TestElement.ENABLED) || name.equals(TestElement.GUI_CLASS) || name.equals(TestElement.NAME) || name.equals(TestElement.TEST_CLASS)) {
            // go on with next property.
            continue;
        }
        for (ConfigTestElement config : configurations) {
            String configValue = config.getPropertyAsString(name);
            if (configValue != null && configValue.length() > 0) {
                if (configValue.equals(value)) {
                    // $NON-NLS-1$
                    sampler.setProperty(name, "");
                }
                // this property -- don't look at lower-priority configs
                break;
            }
        }
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement)

Example 18 with PropertyIterator

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

the class HTTPFileArgs method toString.

/**
 * Create a string representation of the files.
 *
 * @return the string representation of the files
 */
@Override
public String toString() {
    StringBuilder str = new StringBuilder();
    PropertyIterator iter = getHTTPFileArgsCollection().iterator();
    while (iter.hasNext()) {
        HTTPFileArg file = (HTTPFileArg) iter.next().getObjectValue();
        str.append(file.toString());
        if (iter.hasNext()) {
            // $NON-NLS-1$
            str.append("\n");
        }
    }
    return str.toString();
}
Also used : PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator)

Example 19 with PropertyIterator

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

the class TestHTTPFileArgs method testRemoving.

@Test
public void testRemoving() throws Exception {
    HTTPFileArgs files = new HTTPFileArgs();
    assertEquals(0, files.getHTTPFileArgCount());
    files.addHTTPFileArg("hede");
    assertEquals(1, files.getHTTPFileArgCount());
    files.clear();
    assertEquals(0, files.getHTTPFileArgCount());
    files.addHTTPFileArg("file1");
    files.addHTTPFileArg("file2");
    files.addHTTPFileArg("file3");
    HTTPFileArg file = new HTTPFileArg("file4");
    files.addHTTPFileArg(file);
    files.addHTTPFileArg("file5");
    files.addHTTPFileArg("file6");
    assertEquals(6, files.getHTTPFileArgCount());
    files.removeHTTPFileArg("file3");
    assertEquals(5, files.getHTTPFileArgCount());
    PropertyIterator iter = files.iterator();
    assertEquals("file1", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
    assertEquals("file2", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
    assertEquals("file4", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
    assertEquals("file5", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
    assertEquals("file6", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
    files.removeHTTPFileArg(file);
    assertEquals(4, files.getHTTPFileArgCount());
    iter = files.iterator();
    assertEquals("file1", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
    assertEquals("file2", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
    assertEquals("file5", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
    assertEquals("file6", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
    files.removeHTTPFileArg(new HTTPFileArg("file5"));
    assertEquals(3, files.getHTTPFileArgCount());
    iter = files.iterator();
    assertEquals("file1", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
    assertEquals("file2", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
    assertEquals("file6", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
    files.removeHTTPFileArg(1);
    assertEquals(2, files.getHTTPFileArgCount());
    iter = files.iterator();
    assertEquals("file1", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
    assertEquals("file6", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
    files.removeAllHTTPFileArgs();
    assertEquals(0, files.getHTTPFileArgCount());
}
Also used : PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator) Test(org.junit.jupiter.api.Test)

Example 20 with PropertyIterator

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

the class JMSProperties method toString.

/**
 * Create a string representation of the JmsProperties.
 *
 * @return the string representation of the JmsProperties
 */
@Override
public String toString() {
    StringBuilder str = new StringBuilder();
    PropertyIterator iter = getProperties().iterator();
    while (iter.hasNext()) {
        JMSProperty arg = (JMSProperty) iter.next().getObjectValue();
        str.append(arg.toString());
        if (iter.hasNext()) {
            // $NON-NLS-1$
            str.append(",");
        }
    }
    return str.toString();
}
Also used : 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