01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.jmeter.control;
20:
21: import org.apache.jmeter.junit.JMeterTestCase;
22: import org.apache.jmeter.junit.stubs.TestSampler;
23: import org.apache.jmeter.testelement.TestElement;
24:
25: public class TestLoopController extends JMeterTestCase {
26: public TestLoopController(String name) {
27: super (name);
28: }
29:
30: public void testProcessing() throws Exception {
31: GenericController controller = new GenericController();
32: GenericController sub_1 = new GenericController();
33: sub_1.addTestElement(new TestSampler("one"));
34: sub_1.addTestElement(new TestSampler("two"));
35: controller.addTestElement(sub_1);
36: controller.addTestElement(new TestSampler("three"));
37: LoopController sub_2 = new LoopController();
38: sub_2.setLoops(3);
39: GenericController sub_3 = new GenericController();
40: sub_2.addTestElement(new TestSampler("four"));
41: sub_3.addTestElement(new TestSampler("five"));
42: sub_3.addTestElement(new TestSampler("six"));
43: sub_2.addTestElement(sub_3);
44: sub_2.addTestElement(new TestSampler("seven"));
45: controller.addTestElement(sub_2);
46: String[] order = new String[] { "one", "two", "three", "four",
47: "five", "six", "seven", "four", "five", "six", "seven",
48: "four", "five", "six", "seven" };
49: int counter = 15;
50: controller.setRunningVersion(true);
51: sub_1.setRunningVersion(true);
52: sub_2.setRunningVersion(true);
53: sub_3.setRunningVersion(true);
54: controller.initialize();
55: for (int i = 0; i < 2; i++) {
56: assertEquals(15, counter);
57: counter = 0;
58: TestElement sampler = null;
59: while ((sampler = controller.next()) != null) {
60: assertEquals(order[counter++], sampler
61: .getPropertyAsString(TestElement.NAME));
62: }
63: }
64: }
65:
66: public void testLoopZeroTimes() throws Exception {
67: LoopController loop = new LoopController();
68: loop.setLoops(0);
69: loop.addTestElement(new TestSampler("never run"));
70: loop.initialize();
71: assertNull(loop.next());
72: }
73:
74: public void testInfiniteLoop() throws Exception {
75: LoopController loop = new LoopController();
76: loop.setLoops(-1);
77: loop.addTestElement(new TestSampler("never run"));
78: loop.setRunningVersion(true);
79: loop.initialize();
80: for (int i = 0; i < 42; i++) {
81: assertNotNull(loop.next());
82: }
83: }
84: }
|