Lines 19-25
Link Here
|
19 |
package org.apache.jmeter.control; |
19 |
package org.apache.jmeter.control; |
20 |
|
20 |
|
21 |
import org.apache.jmeter.junit.JMeterTestCase; |
21 |
import org.apache.jmeter.junit.JMeterTestCase; |
22 |
//import org.apache.jmeter.testelement.TestElement; |
22 |
import org.apache.jmeter.junit.stubs.TestSampler; |
|
|
23 |
import org.apache.jmeter.samplers.Sampler; |
23 |
|
24 |
|
24 |
public class TestIfController extends JMeterTestCase { |
25 |
public class TestIfController extends JMeterTestCase { |
25 |
public TestIfController(String name) { |
26 |
public TestIfController(String name) { |
Lines 71-74
Link Here
|
71 |
// + sampler.getName()); |
72 |
// + sampler.getName()); |
72 |
// } |
73 |
// } |
73 |
} |
74 |
} |
|
|
75 |
|
76 |
public void testProcessingTrue() throws Exception { |
77 |
LoopController controller = new LoopController(); |
78 |
controller.setLoops(2); |
79 |
controller.addTestElement(new TestSampler("Sample1")); |
80 |
IfController ifCont = new IfController("true==true"); |
81 |
ifCont.setEvaluateAll(true); |
82 |
ifCont.addTestElement(new TestSampler("Sample2")); |
83 |
TestSampler sample3 = new TestSampler("Sample3"); |
84 |
ifCont.addTestElement(sample3); |
85 |
controller.addTestElement(ifCont); |
86 |
|
87 |
String[] order = new String[] { "Sample1", "Sample2", "Sample3", |
88 |
"Sample1", "Sample2", "Sample3" }; |
89 |
int counter = 0; |
90 |
controller.setRunningVersion(true); |
91 |
ifCont.setRunningVersion(true); |
92 |
|
93 |
Sampler sampler = null; |
94 |
while ((sampler = controller.next()) != null) { |
95 |
sampler.sample(null); |
96 |
assertEquals(order[counter], sampler.getName()); |
97 |
counter++; |
98 |
} |
99 |
assertEquals(counter, 6); |
100 |
} |
101 |
|
102 |
/** |
103 |
* Test false return on sample3 (sample4 doesn't execute) |
104 |
* @throws Exception |
105 |
*/ |
106 |
public void testEvaluateAllChildrenWithoutSubController() throws Exception { |
107 |
LoopController controller = new LoopController(); |
108 |
controller.setLoops(2); |
109 |
controller.addTestElement(new TestSampler("Sample1")); |
110 |
IfController ifCont = new IfController("true==true"); |
111 |
ifCont.setEvaluateAll(true); |
112 |
controller.addTestElement(ifCont); |
113 |
|
114 |
ifCont.addTestElement(new TestSampler("Sample2")); |
115 |
TestSampler sample3 = new TestSampler("Sample3"); |
116 |
ifCont.addTestElement(sample3); |
117 |
TestSampler sample4 = new TestSampler("Sample4"); |
118 |
ifCont.addTestElement(sample4); |
119 |
|
120 |
String[] order = new String[] { "Sample1", "Sample2", "Sample3", |
121 |
"Sample1", "Sample2", "Sample3" }; |
122 |
int counter = 0; |
123 |
controller.setRunningVersion(true); |
124 |
ifCont.setRunningVersion(true); |
125 |
|
126 |
Sampler sampler = null; |
127 |
while ((sampler = controller.next()) != null) { |
128 |
sampler.sample(null); |
129 |
if (sampler.getName().equals("Sample3")) { |
130 |
ifCont.setCondition("true==false"); |
131 |
} |
132 |
assertEquals(order[counter], sampler.getName()); |
133 |
counter++; |
134 |
} |
135 |
assertEquals(counter, 6); |
136 |
} |
137 |
|
138 |
/** |
139 |
* test 2 loops with a sub generic controller (sample4 doesn't execute) |
140 |
* @throws Exception |
141 |
*/ |
142 |
public void testEvaluateAllChildrenWithSubController() throws Exception { |
143 |
LoopController controller = new LoopController(); |
144 |
controller.setLoops(2); |
145 |
controller.addTestElement(new TestSampler("Sample1")); |
146 |
IfController ifCont = new IfController("true==true"); |
147 |
ifCont.setEvaluateAll(true); |
148 |
controller.addTestElement(ifCont); |
149 |
ifCont.addTestElement(new TestSampler("Sample2")); |
150 |
|
151 |
GenericController genericCont = new GenericController(); |
152 |
TestSampler sample3 = new TestSampler("Sample3"); |
153 |
genericCont.addTestElement(sample3); |
154 |
TestSampler sample4 = new TestSampler("Sample4"); |
155 |
genericCont.addTestElement(sample4); |
156 |
ifCont.addTestElement(genericCont); |
157 |
|
158 |
String[] order = new String[] { "Sample1", "Sample2", "Sample3", |
159 |
"Sample1", "Sample2", "Sample3" }; |
160 |
int counter = 0; |
161 |
controller.setRunningVersion(true); |
162 |
ifCont.setRunningVersion(true); |
163 |
genericCont.setRunningVersion(true); |
164 |
|
165 |
Sampler sampler = null; |
166 |
while ((sampler = controller.next()) != null) { |
167 |
sampler.sample(null); |
168 |
if (sampler.getName().equals("Sample3")) { |
169 |
ifCont.setCondition("true==false"); |
170 |
} |
171 |
assertEquals(order[counter], sampler.getName()); |
172 |
counter++; |
173 |
} |
174 |
assertEquals(counter, 6); |
175 |
} |
74 |
} |
176 |
} |