Search in sources :

Example 36 with PropertyIterator

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

the class AnchorModifier method modifyArgument.

private void modifyArgument(Argument arg, Arguments args) {
    if (log.isDebugEnabled()) {
        log.debug("Modifying argument: " + arg);
    }
    List<Argument> possibleReplacements = new ArrayList<>();
    PropertyIterator iter = args.iterator();
    Argument replacementArg;
    while (iter.hasNext()) {
        replacementArg = (Argument) iter.next().getObjectValue();
        try {
            if (HtmlParsingUtils.isArgumentMatched(replacementArg, arg)) {
                possibleReplacements.add(replacementArg);
            }
        } catch (Exception ex) {
            log.error("Problem adding Argument", ex);
        }
    }
    if (!possibleReplacements.isEmpty()) {
        replacementArg = possibleReplacements.get(ThreadLocalRandom.current().nextInt(possibleReplacements.size()));
        arg.setName(replacementArg.getName());
        arg.setValue(replacementArg.getValue());
        if (log.isDebugEnabled()) {
            log.debug("Just set argument to values: " + arg.getName() + " = " + arg.getValue());
        }
        args.removeArgument(replacementArg);
    }
}
Also used : Argument(org.apache.jmeter.config.Argument) ArrayList(java.util.ArrayList) PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator) MalformedURLException(java.net.MalformedURLException)

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