Search in sources :

Example 81 with JMeterProperty

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

the class AbstractTestElement method addProperty.

/**
     * Add property to test element
     * @param property {@link JMeterProperty} to add to current Test Element
     * @param clone clone property
     */
protected void addProperty(JMeterProperty property, boolean clone) {
    JMeterProperty propertyToPut = property;
    if (clone) {
        propertyToPut = property.clone();
    }
    if (isRunningVersion()) {
        setTemporary(propertyToPut);
    } else {
        clearTemporary(property);
    }
    JMeterProperty prop = getProperty(property.getName());
    if (prop instanceof NullProperty || (prop instanceof StringProperty && prop.getStringValue().isEmpty())) {
        propMap.put(property.getName(), propertyToPut);
    } else {
        prop.mergeIn(propertyToPut);
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) NullProperty(org.apache.jmeter.testelement.property.NullProperty) StringProperty(org.apache.jmeter.testelement.property.StringProperty)

Example 82 with JMeterProperty

use of org.apache.jmeter.testelement.property.JMeterProperty 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 83 with JMeterProperty

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

the class MultiPropertyConverter method marshal.

/** {@inheritDoc} */
@Override
public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingContext context) {
    MultiProperty prop = (MultiProperty) arg0;
    writer.addAttribute(ConversionHelp.ATT_NAME, ConversionHelp.encode(prop.getName()));
    for (JMeterProperty jMeterProperty : prop) {
        writeItem(jMeterProperty, context, writer);
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) MultiProperty(org.apache.jmeter.testelement.property.MultiProperty)

Example 84 with JMeterProperty

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

the class HC4CookieHandler method getCookiesForUrl.

/**
     * Get array of valid HttpClient cookies for the URL
     *
     * @param cookiesCP property with all available cookies
     * @param url the target URL
     * @param allowVariableCookie flag whether cookies may contain jmeter variables
     * @return array of HttpClient cookies
     *
     */
List<org.apache.http.cookie.Cookie> getCookiesForUrl(CollectionProperty cookiesCP, URL url, boolean allowVariableCookie) {
    List<org.apache.http.cookie.Cookie> cookies = new ArrayList<>();
    for (JMeterProperty jMeterProperty : cookiesCP) {
        Cookie jmcookie = (Cookie) jMeterProperty.getObjectValue();
        // Set to running version, to allow function evaluation for the cookie values (bug 28715)
        if (allowVariableCookie) {
            jmcookie.setRunningVersion(true);
        }
        cookies.add(makeCookie(jmcookie));
        if (allowVariableCookie) {
            jmcookie.setRunningVersion(false);
        }
    }
    String host = url.getHost();
    String protocol = url.getProtocol();
    int port = HTTPSamplerBase.getDefaultPort(protocol, url.getPort());
    String path = url.getPath();
    boolean secure = HTTPSamplerBase.isSecure(protocol);
    CookieOrigin cookieOrigin = new CookieOrigin(host, port, path, secure);
    List<org.apache.http.cookie.Cookie> cookiesValid = new ArrayList<>();
    for (org.apache.http.cookie.Cookie cookie : cookies) {
        if (cookieSpec.match(cookie, cookieOrigin)) {
            cookiesValid.add(cookie);
        }
    }
    return cookiesValid;
}
Also used : ClientCookie(org.apache.http.cookie.ClientCookie) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) ArrayList(java.util.ArrayList) CookieOrigin(org.apache.http.cookie.CookieOrigin)

Example 85 with JMeterProperty

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

the class HeaderManager method replace.

@Override
public int replace(String regex, String replaceBy, boolean caseSensitive) throws Exception {
    final CollectionProperty hdrs = getHeaders();
    int totalReplaced = 0;
    for (int i = 0; i < hdrs.size(); i++) {
        final JMeterProperty hdr = hdrs.get(i);
        Header head = (Header) hdr.getObjectValue();
        String value = head.getValue();
        if (!StringUtils.isEmpty(value)) {
            Object[] result = JOrphanUtils.replaceAllWithRegex(value, regex, replaceBy, caseSensitive);
            // check if there is anything to replace
            int nbReplaced = ((Integer) result[1]).intValue();
            if (nbReplaced > 0) {
                String replacedText = (String) result[0];
                head.setValue(replacedText);
                totalReplaced += nbReplaced;
            }
        }
    }
    return totalReplaced;
}
Also used : CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty)

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