use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.
the class TestValueReplacer method testReverseReplacementXml.
@Test
public void testReverseReplacementXml() throws Exception {
ValueReplacer replacer = new ValueReplacer(variables);
assertTrue(variables.getUserDefinedVariables().containsKey("bounded_regex"));
assertTrue(variables.getUserDefinedVariables().containsKey("normal_regex"));
assertTrue(replacer.containsKey("bounded_regex"));
assertTrue(replacer.containsKey("normal_regex"));
TestElement element = new TestPlan();
element.setProperty(new StringProperty("domain", "<this><is>xml</this></is>"));
List<Object> argsin = new ArrayList<>();
argsin.add("<this><is>xml</this></is>");
argsin.add("And I say: Hello World.");
element.setProperty(new CollectionProperty("args", argsin));
replacer.reverseReplace(element, true);
@SuppressWarnings("unchecked") List<JMeterProperty> args = (List<JMeterProperty>) element.getProperty("args").getObjectValue();
assertEquals("${bounded_regex}", element.getPropertyAsString("domain"));
assertEquals("${bounded_regex}", args.get(0).getStringValue());
}
use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.
the class TestThroughputController method testByPercent100.
@Test
public void testByPercent100() throws Exception {
ThroughputController sub_1 = new ThroughputController();
sub_1.setStyle(ThroughputController.BYPERCENT);
sub_1.setPercentThroughput(100.0f);
sub_1.addTestElement(new TestSampler("one"));
sub_1.addTestElement(new TestSampler("two"));
LoopController controller = new LoopController();
controller.setLoops(150);
controller.addTestElement(new TestSampler("zero"));
controller.addTestElement(sub_1);
controller.addIterationListener(sub_1);
controller.addTestElement(new TestSampler("three"));
String[] order = new String[] { "zero", "one", "two", "three" };
int counter = 0;
controller.setRunningVersion(true);
sub_1.setRunningVersion(true);
sub_1.testStarted();
controller.initialize();
for (int i = 0; i < 3; i++) {
TestElement sampler = null;
while ((sampler = controller.next()) != null) {
assertEquals("Counter: " + counter + ", i: " + i, order[counter % order.length], sampler.getName());
counter++;
}
assertEquals(counter, 150 * order.length);
counter = 0;
}
sub_1.testEnded();
}
use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.
the class TestThroughputController method testByPercentZero.
@Test
public void testByPercentZero() throws Exception {
ThroughputController sub_1 = new ThroughputController();
sub_1.setStyle(ThroughputController.BYPERCENT);
sub_1.setPercentThroughput(0.0f);
sub_1.addTestElement(new TestSampler("one"));
sub_1.addTestElement(new TestSampler("two"));
LoopController controller = new LoopController();
controller.setLoops(150);
controller.addTestElement(new TestSampler("zero"));
controller.addTestElement(sub_1);
controller.addIterationListener(sub_1);
controller.addTestElement(new TestSampler("three"));
String[] order = new String[] { "zero", "three" };
int counter = 0;
controller.setRunningVersion(true);
sub_1.setRunningVersion(true);
sub_1.testStarted();
controller.initialize();
for (int i = 0; i < 3; i++) {
TestElement sampler = null;
while ((sampler = controller.next()) != null) {
assertEquals("Counter: " + counter + ", i: " + i, order[counter % order.length], sampler.getName());
counter++;
}
assertEquals(counter, 150 * order.length);
counter = 0;
}
sub_1.testEnded();
}
use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.
the class PropertyControlGui method createTestElement.
@Override
public TestElement createTestElement() {
TestElement el = new ConfigTestElement();
modifyTestElement(el);
return el;
}
use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.
the class JMeter method convertSubTree.
/**
* Remove disabled elements
* Replace the ReplaceableController with the target subtree
*
* @param tree The {@link HashTree} to convert
*/
public static void convertSubTree(HashTree tree) {
LinkedList<Object> copyList = new LinkedList<>(tree.list());
for (Object o : copyList) {
if (o instanceof TestElement) {
TestElement item = (TestElement) o;
if (item.isEnabled()) {
if (item instanceof ReplaceableController) {
ReplaceableController rc = ensureReplaceableControllerIsLoaded(item);
HashTree subTree = tree.getTree(item);
if (subTree != null) {
HashTree replacementTree = rc.getReplacementSubTree();
if (replacementTree != null) {
convertSubTree(replacementTree);
tree.replaceKey(item, rc);
tree.set(rc, replacementTree);
}
}
} else {
// not Replaceable Controller
convertSubTree(tree.getTree(item));
}
} else {
// Not enabled
tree.remove(item);
}
} else {
// Not a TestElement
JMeterTreeNode item = (JMeterTreeNode) o;
if (item.isEnabled()) {
// @see StandardJMeterEngine.run()
if (item.getUserObject() instanceof ReplaceableController) {
TestElement controllerAsItem = item.getTestElement();
ReplaceableController rc = ensureReplaceableControllerIsLoaded(controllerAsItem);
HashTree subTree = tree.getTree(item);
if (subTree != null) {
HashTree replacementTree = rc.getReplacementSubTree();
if (replacementTree != null) {
convertSubTree(replacementTree);
tree.replaceKey(item, rc);
tree.set(rc, replacementTree);
}
}
} else {
// Not a ReplaceableController
convertSubTree(tree.getTree(item));
TestElement testElement = item.getTestElement();
tree.replaceKey(item, testElement);
}
} else {
// Not enabled
tree.remove(item);
}
}
}
}
Aggregations