Search in sources :

Example 86 with Arguments

use of org.apache.jmeter.config.Arguments in project jmeter by apache.

the class TestURLRewritingModifier method testCache.

@Test
public void testCache() throws Exception {
    String[] html = new String[] { "<input name=\"sid\" value=\"myId\">", // No entry; check it is still present
    "<html></html>" };
    URLRewritingModifier newMod = new URLRewritingModifier();
    newMod.setShouldCache(true);
    newMod.setThreadContext(context);
    newMod.setArgumentName("sid");
    newMod.setPathExtension(false);
    for (int i = 0; i < html.length; i++) {
        response = new SampleResult();
        response.setResponseData(html[i], null);
        HTTPSamplerBase sampler = createSampler();
        context.setCurrentSampler(sampler);
        context.setPreviousResult(response);
        newMod.process();
        Arguments args = sampler.getArguments();
        assertEquals("For case i=" + i, "myId", ((Argument) args.getArguments().get(0).getObjectValue()).getValue());
    }
}
Also used : Arguments(org.apache.jmeter.config.Arguments) SampleResult(org.apache.jmeter.samplers.SampleResult) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) Test(org.junit.jupiter.api.Test)

Example 87 with Arguments

use of org.apache.jmeter.config.Arguments in project jmeter by apache.

the class TestURLRewritingModifier method testGrabSessionIdEndedInTab.

@Test
public void testGrabSessionIdEndedInTab() throws Exception {
    String html = "href='index.html?session_id=jfdkjdkfjddkfdfjkdjfdf\t";
    response = new SampleResult();
    response.setResponseData(html, null);
    mod.setArgumentName("session_id");
    HTTPSamplerBase sampler = createSampler();
    context.setCurrentSampler(sampler);
    context.setPreviousResult(response);
    mod.process();
    Arguments args = sampler.getArguments();
    assertEquals("jfdkjdkfjddkfdfjkdjfdf", ((Argument) args.getArguments().get(0).getObjectValue()).getValue());
}
Also used : Arguments(org.apache.jmeter.config.Arguments) SampleResult(org.apache.jmeter.samplers.SampleResult) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) Test(org.junit.jupiter.api.Test)

Example 88 with Arguments

use of org.apache.jmeter.config.Arguments in project jmeter by apache.

the class TestURLRewritingModifier method testGrabSessionId7.

@Test
public void testGrabSessionId7() throws Exception {
    String html = "location: http://server.com/index.html" + "?session_id=bonjour+monsieur";
    response = new SampleResult();
    response.setResponseData(html, null);
    mod.setArgumentName("session_id");
    mod.setEncode(true);
    HTTPSamplerBase sampler = createSampler();
    sampler.addArgument("session_id", "adfasdfdsafasdfasd");
    context.setCurrentSampler(sampler);
    context.setPreviousResult(response);
    mod.process();
    Arguments args = sampler.getArguments();
    assertEquals("bonjour+monsieur", ((Argument) args.getArguments().get(0).getObjectValue()).getValue());
    assertEquals("http://server.com/index.html?" + "session_id=bonjour%2Bmonsieur", sampler.toString());
}
Also used : Arguments(org.apache.jmeter.config.Arguments) SampleResult(org.apache.jmeter.samplers.SampleResult) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) Test(org.junit.jupiter.api.Test)

Example 89 with Arguments

use of org.apache.jmeter.config.Arguments in project jmeter by apache.

the class ProxyControl method replaceValues.

/**
 * Scan all test elements passed in for values matching the value of any of
 * the variables in any of the variable-holding elements in the collection.
 *
 * @param sampler   A TestElement to replace values on
 * @param configs   More TestElements to replace values on
 * @param variables Collection of Arguments to use to do the replacement, ordered
 *                  by ascending priority.
 */
private void replaceValues(TestElement sampler, TestElement[] configs, Collection<Arguments> variables) {
    // Build the replacer from all the variables in the collection:
    ValueReplacer replacer = new ValueReplacer();
    for (Arguments variable : variables) {
        final Map<String, String> map = variable.getArgumentsAsMap();
        // Drop any empty values (Bug 45199)
        map.values().removeIf(""::equals);
        replacer.addVariables(map);
    }
    try {
        boolean cachedRegexpMatch = regexMatch;
        replacer.reverseReplace(sampler, cachedRegexpMatch);
        for (TestElement config : configs) {
            if (config != null) {
                replacer.reverseReplace(config, cachedRegexpMatch);
            }
        }
    } catch (InvalidVariableException e) {
        log.warn("Invalid variables included for replacement into recorded sample", e);
    }
}
Also used : InvalidVariableException(org.apache.jmeter.functions.InvalidVariableException) Arguments(org.apache.jmeter.config.Arguments) ValueReplacer(org.apache.jmeter.engine.util.ValueReplacer) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) NonTestElement(org.apache.jmeter.testelement.NonTestElement)

Example 90 with Arguments

use of org.apache.jmeter.config.Arguments in project jmeter by apache.

the class DefaultSamplerCreator method populateSampler.

/**
 * @see org.apache.jmeter.protocol.http.proxy.SamplerCreator#populateSampler(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase,
 *      org.apache.jmeter.protocol.http.proxy.HttpRequestHdr, java.util.Map,
 *      java.util.Map)
 */
@Override
public final void populateSampler(HTTPSamplerBase sampler, HttpRequestHdr request, Map<String, String> pageEncodings, Map<String, String> formEncodings) throws Exception {
    computeFromHeader(sampler, request, pageEncodings, formEncodings);
    computeFromPostBody(sampler, request);
    if (log.isDebugEnabled()) {
        log.debug("sampler path = {}", sampler.getPath());
    }
    Arguments arguments = sampler.getArguments();
    if (arguments.getArgumentCount() == 1 && arguments.getArgument(0).getName().length() == 0) {
        sampler.setPostBodyRaw(true);
    }
    if (request.isDetectGraphQLRequest()) {
        detectAndModifySamplerOnGraphQLRequest(sampler, request);
    }
}
Also used : Arguments(org.apache.jmeter.config.Arguments)

Aggregations

Arguments (org.apache.jmeter.config.Arguments)102 Test (org.junit.jupiter.api.Test)32 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)18 SampleResult (org.apache.jmeter.samplers.SampleResult)17 Argument (org.apache.jmeter.config.Argument)15 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)11 HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)10 Test (org.junit.Test)10 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)7 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)6 TestElement (org.apache.jmeter.testelement.TestElement)6 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)5 HTTPFileArgs (org.apache.jmeter.protocol.http.util.HTTPFileArgs)4 IOException (java.io.IOException)3 URL (java.net.URL)3 Iterator (java.util.Iterator)3 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)3 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)3