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());
}
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());
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations