use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.
the class TestLoopController method testBug54467.
@Test
public void testBug54467() throws Exception {
JMeterContext jmctx = JMeterContextService.getContext();
LoopController loop = new LoopController();
Map<String, String> variables = new HashMap<>();
ReplaceStringWithFunctions transformer = new ReplaceStringWithFunctions(new CompoundVariable(), variables);
jmctx.setVariables(new JMeterVariables());
StringProperty prop = new StringProperty(LoopController.LOOPS, "${__Random(1,12,)}");
JMeterProperty newProp = transformer.transformValue(prop);
newProp.setRunningVersion(true);
loop.setProperty(newProp);
loop.addTestElement(new TestSampler("random run"));
loop.setRunningVersion(true);
loop.initialize();
int loops = loop.getLoops();
for (int i = 0; i < loops; i++) {
Sampler s = loop.next();
assertNotNull(s);
}
assertNull(loop.next());
}
use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.
the class TestSwitchController method testFunction.
/*
* N.B. Requires ApacheJMeter_functions.jar to be on the classpath,
* otherwise the function cannot be resolved.
*/
@Test
public void testFunction() throws Exception {
JMeterContext jmctx = JMeterContextService.getContext();
Map<String, String> variables = new HashMap<>();
ReplaceStringWithFunctions transformer = new ReplaceStringWithFunctions(new CompoundVariable(), variables);
jmctx.setVariables(new JMeterVariables());
JMeterVariables jmvars = jmctx.getVariables();
jmvars.put("VAR", "100");
StringProperty prop = new StringProperty(SwitchController.SWITCH_VALUE, "${__counter(TRUE,VAR)}");
JMeterProperty newProp = transformer.transformValue(prop);
newProp.setRunningVersion(true);
GenericController controller = new GenericController();
SwitchController switch_cont = new SwitchController();
switch_cont.setProperty(newProp);
controller.addTestElement(new TestSampler("before"));
controller.addTestElement(switch_cont);
switch_cont.addTestElement(new TestSampler("0"));
switch_cont.addTestElement(new TestSampler("1"));
switch_cont.addTestElement(new TestSampler("2"));
switch_cont.addTestElement(new TestSampler("3"));
controller.addTestElement(new TestSampler("after"));
controller.initialize();
assertEquals("100", jmvars.get("VAR"));
for (int i = 1; i <= 3; i++) {
assertEquals("Loop " + i, "before", nextName(controller));
assertEquals("Loop " + i, "" + i, nextName(controller));
assertEquals("Loop " + i, "" + i, jmvars.get("VAR"));
assertEquals("Loop " + i, "after", nextName(controller));
assertNull(nextName(controller));
}
int i = 4;
assertEquals("Loop " + i, "before", nextName(controller));
assertEquals("Loop " + i, "0", nextName(controller));
assertEquals("Loop " + i, "" + i, jmvars.get("VAR"));
assertEquals("Loop " + i, "after", nextName(controller));
assertNull(nextName(controller));
assertEquals("4", jmvars.get("VAR"));
}
use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.
the class PackageTest method setupXPath.
private XPath setupXPath(String file, String expr) throws Exception {
Collection<CompoundVariable> parms = new LinkedList<>();
parms.add(new CompoundVariable(file));
parms.add(new CompoundVariable(expr));
XPath xp = new XPath();
xp.setParameters(parms);
return xp;
}
use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.
the class SplitFunctionTest method splitParams.
// Create the SplitFile function and set its parameters.
private static SplitFunction splitParams(String p1, String p2, String p3) throws Exception {
SplitFunction split = new SplitFunction();
Collection<CompoundVariable> parms = new LinkedList<>();
parms.add(new CompoundVariable(p1));
if (p2 != null) {
parms.add(new CompoundVariable(p2));
}
if (p3 != null) {
parms.add(new CompoundVariable(p3));
}
split.setParameters(parms);
return split;
}
use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.
the class SumFunctionTest method checkSumNoVar.
// Perform a sum and check the results
private void checkSumNoVar(AbstractFunction func, String value, String[] addends) throws Exception {
Collection<CompoundVariable> parms = new LinkedList<>();
for (String addend : addends) {
parms.add(new CompoundVariable(addend));
}
func.setParameters(parms);
assertEquals(value, func.execute(null, null));
}
Aggregations