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: package org.apache.jmeter.control;
18:
19: import java.util.ArrayList;
20: import java.util.List;
21:
22: import org.apache.jmeter.junit.JMeterTestCase;
23: import org.apache.jmeter.junit.stubs.TestSampler;
24: import org.apache.jmeter.testelement.TestElement;
25:
26: /**
27: * A controller that runs its children each at most once, but in a random order.
28: *
29: * @author Mike Verdone
30: * @version $Revision: 493796 $ updated on $Date: 2007-01-07 18:31:05 +0000 (Sun, 07 Jan 2007) $
31: */
32: public class TestRandomOrderController extends JMeterTestCase {
33:
34: public TestRandomOrderController(String name) {
35: super (name);
36: }
37:
38: public void testRandomOrder() {
39: testLog.debug("Testing RandomOrderController");
40: RandomOrderController roc = new RandomOrderController();
41: roc.addTestElement(new TestSampler("zero"));
42: roc.addTestElement(new TestSampler("one"));
43: roc.addTestElement(new TestSampler("two"));
44: roc.addTestElement(new TestSampler("three"));
45: TestElement sampler = null;
46: List usedSamplers = new ArrayList();
47: roc.initialize();
48: while ((sampler = roc.next()) != null) {
49: String samplerName = sampler
50: .getPropertyAsString(TestSampler.NAME);
51: if (usedSamplers.contains(samplerName)) {
52: assertTrue("Duplicate sampler returned from next()",
53: false);
54: }
55: usedSamplers.add(samplerName);
56: }
57: assertTrue("All samplers were returned",
58: usedSamplers.size() == 4);
59: }
60:
61: public void testRandomOrderNoElements() {
62: RandomOrderController roc = new RandomOrderController();
63: roc.initialize();
64: assertTrue(roc.next() == null);
65: }
66:
67: public void testRandomOrderOneElement() {
68: RandomOrderController roc = new RandomOrderController();
69: roc.addTestElement(new TestSampler("zero"));
70: TestElement sampler = null;
71: List usedSamplers = new ArrayList();
72: roc.initialize();
73: while ((sampler = roc.next()) != null) {
74: String samplerName = sampler
75: .getPropertyAsString(TestSampler.NAME);
76: if (usedSamplers.contains(samplerName)) {
77: assertTrue("Duplicate sampler returned from next()",
78: false);
79: }
80: usedSamplers.add(samplerName);
81: }
82: assertTrue("All samplers were returned",
83: usedSamplers.size() == 1);
84: }
85: }
|