use of org.apache.jmeter.config.Argument in project jmeter by apache.
the class AnchorModifier method process.
/**
* Modifies an Entry object based on HTML response text.
*/
@Override
public void process() {
JMeterContext context = getThreadContext();
Sampler sam = context.getCurrentSampler();
SampleResult res = context.getPreviousResult();
HTTPSamplerBase sampler;
HTTPSampleResult result;
if (!(sam instanceof HTTPSamplerBase) || !(res instanceof HTTPSampleResult)) {
log.info("Can't apply HTML Link Parser when the previous" + " sampler run is not an HTTP Request.");
return;
} else {
sampler = (HTTPSamplerBase) sam;
result = (HTTPSampleResult) res;
}
List<HTTPSamplerBase> potentialLinks = new ArrayList<>();
String responseText = result.getResponseDataAsString();
// $NON-NLS-1$
int index = responseText.indexOf('<');
if (index == -1) {
index = 0;
}
if (log.isDebugEnabled()) {
log.debug("Check for matches against: " + sampler.toString());
}
Document html = (Document) HtmlParsingUtils.getDOM(responseText.substring(index));
addAnchorUrls(html, result, sampler, potentialLinks);
addFormUrls(html, result, sampler, potentialLinks);
addFramesetUrls(html, result, sampler, potentialLinks);
if (!potentialLinks.isEmpty()) {
HTTPSamplerBase url = potentialLinks.get(ThreadLocalRandom.current().nextInt(potentialLinks.size()));
if (log.isDebugEnabled()) {
log.debug("Selected: " + url.toString());
}
sampler.setDomain(url.getDomain());
sampler.setPath(url.getPath());
if (url.getMethod().equals(HTTPConstants.POST)) {
for (JMeterProperty jMeterProperty : sampler.getArguments()) {
Argument arg = (Argument) jMeterProperty.getObjectValue();
modifyArgument(arg, url.getArguments());
}
} else {
sampler.setArguments(url.getArguments());
// config.parseArguments(url.getQueryString());
}
sampler.setProtocol(url.getProtocol());
} else {
log.debug("No matches found");
}
}
use of org.apache.jmeter.config.Argument in project jmeter by apache.
the class RegExUserParameters method process.
@Override
public void process() {
if (log.isDebugEnabled()) {
//$NON-NLS-1$
log.debug(Thread.currentThread().getName() + " Running up named: " + getName());
}
Sampler entry = getThreadContext().getCurrentSampler();
if (!(entry instanceof HTTPSamplerBase)) {
return;
}
Map<String, String> paramMap = buildParamsMap();
if (paramMap == null || paramMap.isEmpty()) {
log.info("RegExUserParameters element:" + getName() + " => Referenced RegExp was not found, no parameter will be changed");
return;
}
HTTPSamplerBase sampler = (HTTPSamplerBase) entry;
for (JMeterProperty jMeterProperty : sampler.getArguments()) {
Argument arg = (Argument) jMeterProperty.getObjectValue();
String oldValue = arg.getValue();
// if parameter name exists in http request
// then change its value with value obtained with regular expression
String val = paramMap.get(arg.getName());
if (val != null) {
arg.setValue(val);
}
if (log.isDebugEnabled()) {
log.debug("RegExUserParameters element:" + getName() + " => changed parameter: " + arg.getName() + " = " + arg.getValue() + ", was:" + oldValue);
}
}
}
use of org.apache.jmeter.config.Argument in project jmeter by apache.
the class TestTreeCloner method testCloning.
@Test
public void testCloning() throws Exception {
ListedHashTree original = new ListedHashTree();
GenericController controller = new GenericController();
controller.setName("controller");
Arguments args = new Arguments();
args.setName("args");
TestPlan plan = new TestPlan();
plan.addParameter("server", "jakarta");
original.add(controller, args);
original.add(plan);
ResultCollector listener = new ResultCollector();
listener.setName("Collector");
original.add(controller, listener);
TreeCloner cloner = new TreeCloner();
original.traverse(cloner);
ListedHashTree newTree = cloner.getClonedTree();
assertTrue(original != newTree);
assertEquals(original.size(), newTree.size());
assertEquals(original.getTree(original.getArray()[0]).size(), newTree.getTree(newTree.getArray()[0]).size());
assertTrue(original.getArray()[0] != newTree.getArray()[0]);
assertEquals(((GenericController) original.getArray()[0]).getName(), ((GenericController) newTree.getArray()[0]).getName());
assertSame(original.getTree(original.getArray()[0]).getArray()[1], newTree.getTree(newTree.getArray()[0]).getArray()[1]);
TestPlan clonedTestPlan = (TestPlan) newTree.getArray()[1];
clonedTestPlan.setRunningVersion(true);
clonedTestPlan.recoverRunningVersion();
assertTrue(!plan.getUserDefinedVariablesAsProperty().isRunningVersion());
assertTrue(clonedTestPlan.getUserDefinedVariablesAsProperty().isRunningVersion());
Arguments vars = (Arguments) plan.getUserDefinedVariablesAsProperty().getObjectValue();
PropertyIterator iter = ((CollectionProperty) vars.getProperty(Arguments.ARGUMENTS)).iterator();
while (iter.hasNext()) {
JMeterProperty argProp = iter.next();
assertTrue(!argProp.isRunningVersion());
assertTrue(argProp.getObjectValue() instanceof Argument);
Argument arg = (Argument) argProp.getObjectValue();
arg.setValue("yahoo");
assertEquals("yahoo", arg.getValue());
}
vars = (Arguments) clonedTestPlan.getUserDefinedVariablesAsProperty().getObjectValue();
iter = vars.propertyIterator();
while (iter.hasNext()) {
assertTrue(iter.next().isRunningVersion());
}
}
use of org.apache.jmeter.config.Argument in project jmeter by apache.
the class TestArgumentsPanel method testArgumentCreation.
/**
* Test that adding an argument to the table results in an appropriate
* TestElement being created.
*
* @throws Exception
* if an exception occurred during the test
*/
@Test
public void testArgumentCreation() throws Exception {
ArgumentsPanel gui = new ArgumentsPanel();
gui.tableModel.addRow(new Argument());
gui.tableModel.setValueAt("howdy", 0, 0);
gui.tableModel.addRow(new Argument());
gui.tableModel.setValueAt("doody", 0, 1);
assertEquals("=", ((Argument) ((Arguments) gui.createTestElement()).getArguments().get(0).getObjectValue()).getMetaData());
}
use of org.apache.jmeter.config.Argument in project jmeter by apache.
the class TestHTTPSamplers method testParseArguments2.
// Parse arguments all at once
@Test
public void testParseArguments2() {
HTTPSamplerBase sampler = new HTTPNullSampler();
Arguments args;
Argument arg;
args = sampler.getArguments();
assertEquals(0, args.getArgumentCount());
assertEquals(0, sampler.getHTTPFileCount());
sampler.parseArguments("&name1&name2=&name3=value3");
args = sampler.getArguments();
assertEquals(3, args.getArgumentCount());
assertEquals(0, sampler.getHTTPFileCount());
arg = args.getArgument(0);
assertEquals("name1", arg.getName());
assertEquals("", arg.getMetaData());
assertEquals("", arg.getValue());
assertEquals(0, sampler.getHTTPFileCount());
arg = args.getArgument(1);
assertEquals("name2", arg.getName());
assertEquals("=", arg.getMetaData());
assertEquals("", arg.getValue());
assertEquals(0, sampler.getHTTPFileCount());
arg = args.getArgument(2);
assertEquals("name3", arg.getName());
assertEquals("=", arg.getMetaData());
assertEquals("value3", arg.getValue());
assertEquals(0, sampler.getHTTPFileCount());
}
Aggregations