001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.control;
020:
021: import org.apache.jmeter.junit.JMeterTestCase;
022: import org.apache.jmeter.junit.stubs.TestSampler;
023: import org.apache.jmeter.testelement.TestElement;
024:
025: /**
026: * @author Michael Stover Created March 13, 2001
027: * @version $Revision: 493796 $ Last updated: $Date: 2007-01-07 18:31:05 +0000 (Sun, 07 Jan 2007) $
028: */
029: public class TestOnceOnlyController extends JMeterTestCase {
030: public TestOnceOnlyController(String name) {
031: super (name);
032: }
033:
034: public void testProcessing() throws Exception {
035: GenericController controller = new GenericController();
036: GenericController sub_1 = new OnceOnlyController();
037: sub_1.addTestElement(new TestSampler("one"));
038: sub_1.addTestElement(new TestSampler("two"));
039: controller.addTestElement(sub_1);
040: controller.addTestElement(new TestSampler("three"));
041: LoopController sub_2 = new LoopController();
042: sub_2.setLoops(3);
043: GenericController sub_3 = new GenericController();
044: sub_2.addTestElement(new TestSampler("four"));
045: sub_3.addTestElement(new TestSampler("five"));
046: sub_3.addTestElement(new TestSampler("six"));
047: sub_2.addTestElement(sub_3);
048: sub_2.addTestElement(new TestSampler("seven"));
049: controller.addTestElement(sub_2);
050: String[] interleaveOrder = new String[] { "one", "two" };
051: String[] order = new String[] { "", "", "three", "four",
052: "five", "six", "seven", "four", "five", "six", "seven",
053: "four", "five", "six", "seven" };
054: int counter = 15;
055: controller.setRunningVersion(true);
056: sub_1.setRunningVersion(true);
057: sub_2.setRunningVersion(true);
058: sub_3.setRunningVersion(true);
059: controller.initialize();
060: for (int i = 0; i < 4; i++) {
061: assertEquals(15, counter);
062: counter = 0;
063: if (i > 0) {
064: counter = 2;
065: }
066: TestElement sampler = null;
067: while ((sampler = controller.next()) != null) {
068: if (i == 0 && counter < 2) {
069: assertEquals(interleaveOrder[counter], sampler
070: .getPropertyAsString(TestElement.NAME));
071: } else {
072: assertEquals(order[counter], sampler
073: .getPropertyAsString(TestElement.NAME));
074: }
075: counter++;
076: }
077: }
078: }
079:
080: public void testProcessing2() throws Exception {
081: GenericController controller = new GenericController();
082: GenericController sub_1 = new OnceOnlyController();
083: sub_1.addTestElement(new TestSampler("one"));
084: sub_1.addTestElement(new TestSampler("two"));
085: controller.addTestElement(sub_1);
086: controller.addTestElement(new TestSampler("three"));
087: LoopController sub_2 = new LoopController();
088: sub_2.setLoops(3);
089: OnceOnlyController sub_3 = new OnceOnlyController();
090: sub_2.addTestElement(new TestSampler("four"));
091: sub_3.addTestElement(new TestSampler("five"));
092: sub_3.addTestElement(new TestSampler("six"));
093: sub_2.addTestElement(sub_3);
094: sub_2.addIterationListener(sub_3);
095: sub_2.addTestElement(new TestSampler("seven"));
096: controller.addTestElement(sub_2);
097: String[] interleaveOrder = new String[] { "one", "two" };
098: String[] order = new String[] { "", "", "three", "four",
099: "five", "six", "seven", "four", "seven", "four",
100: "seven" };
101: int counter = 11;
102: controller.setRunningVersion(true);
103: sub_1.setRunningVersion(true);
104: sub_2.setRunningVersion(true);
105: sub_3.setRunningVersion(true);
106: controller.initialize();
107: for (int i = 0; i < 4; i++) {
108: assertEquals(11, counter);
109: counter = 0;
110: if (i > 0) {
111: counter = 2;
112: }
113: TestElement sampler = null;
114: while ((sampler = controller.next()) != null) {
115: if (i == 0 && counter < 2) {
116: assertEquals(interleaveOrder[counter], sampler
117: .getPropertyAsString(TestElement.NAME));
118: } else {
119: assertEquals(order[counter], sampler
120: .getPropertyAsString(TestElement.NAME));
121: }
122: counter++;
123: }
124: }
125: }
126: }
|