Search in sources :

Example 61 with Arguments

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

the class TestURLRewritingModifier method testGrabSessionIdURLinJSON.

@Test
public void testGrabSessionIdURLinJSON() throws Exception {
    String html = "<a href=\"#\" onclick=\"$(\'frame\').src=\'/index?param1=bla&sessionid=xyzxyzxyz\\'";
    response = new SampleResult();
    response.setResponseData(html, null);
    mod.setArgumentName("sessionid");
    HTTPSamplerBase sampler = createSampler();
    sampler.addArgument("sessionid", "xyzxyzxyz");
    context.setCurrentSampler(sampler);
    context.setPreviousResult(response);
    mod.process();
    Arguments args = sampler.getArguments();
    assertEquals("xyzxyzxyz", ((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.Test)

Example 62 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.Test)

Example 63 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)

Example 64 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);
    }
}
Also used : Arguments(org.apache.jmeter.config.Arguments)

Example 65 with Arguments

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

the class BackendListener method sampleOccurred.

/* (non-Javadoc)
     * @see org.apache.jmeter.samplers.SampleListener#sampleOccurred(org.apache.jmeter.samplers.SampleEvent)
     */
@Override
public void sampleOccurred(SampleEvent event) {
    Arguments args = getArguments();
    BackendListenerContext context = new BackendListenerContext(args);
    SampleResult sr = listenerClientData.client.createSampleResult(context, event.getResult());
    if (sr == null) {
        if (log.isDebugEnabled()) {
            log.debug("{} => Dropping SampleResult: {}", getName(), event.getResult());
        }
        return;
    }
    try {
        if (!listenerClientData.queue.offer(sr)) {
            // we failed to add the element first time
            listenerClientData.queueWaits.add(1L);
            long t1 = System.nanoTime();
            listenerClientData.queue.put(sr);
            long t2 = System.nanoTime();
            listenerClientData.queueWaitTime.add(t2 - t1);
        }
    } catch (Exception err) {
        log.error("sampleOccurred, failed to queue the sample", err);
    }
}
Also used : Arguments(org.apache.jmeter.config.Arguments) SampleResult(org.apache.jmeter.samplers.SampleResult)

Aggregations

Arguments (org.apache.jmeter.config.Arguments)75 Test (org.junit.Test)27 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)18 SampleResult (org.apache.jmeter.samplers.SampleResult)15 Argument (org.apache.jmeter.config.Argument)13 HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)9 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)7 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)5 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)5 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)3 TestElement (org.apache.jmeter.testelement.TestElement)3 TestPlan (org.apache.jmeter.testelement.TestPlan)3 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)3 File (java.io.File)2 Iterator (java.util.Iterator)2 InvalidVariableException (org.apache.jmeter.functions.InvalidVariableException)2 HTTPFileArgs (org.apache.jmeter.protocol.http.util.HTTPFileArgs)2 ResultCollector (org.apache.jmeter.reporters.ResultCollector)2 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)2 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)2