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 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());
}
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());
}
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);
}
if (request.isDetectGraphQLRequest()) {
detectAndModifySamplerOnGraphQLRequest(sampler, request);
}
}
Aggregations