1 4 package org.oddjob.jobs; 5 6 import org.oddjob.Oddjob; 7 import org.oddjob.state.JobState; 8 9 import junit.framework.TestCase; 10 11 public class IfJobTest extends TestCase { 12 13 public void testIf1() { 14 DummyStateJob child = new DummyStateJob(); 15 child.setDesired("complete"); 16 17 IfJob j = new IfJob(); 18 j.addComponentChild(child); 19 j.init(); 20 j.run(); 21 22 assertEquals(JobState.COMPLETE, j.lastJobStateEvent().getJobState()); 23 24 child.hardReset(); 25 26 assertEquals(JobState.READY, j.lastJobStateEvent().getJobState()); 27 } 28 29 public void testIf2() { 30 DummyStateJob child = new DummyStateJob(); 31 child.setDesired("not complete"); 32 33 IfJob j = new IfJob(); 34 j.addComponentChild(child); 35 j.init(); 36 37 j.run(); 38 39 assertEquals(JobState.NOT_COMPLETE, j.lastJobStateEvent().getJobState()); 40 41 child.hardReset(); 42 43 assertEquals(JobState.READY, j.lastJobStateEvent().getJobState()); 44 } 45 46 public void testIf3() { 47 DummyStateJob child = new DummyStateJob(); 48 child.setDesired("exception"); 49 50 IfJob j = new IfJob(); 51 j.addComponentChild(child); 52 j.init(); 53 54 j.run(); 55 56 assertEquals(JobState.EXCEPTION, j.lastJobStateEvent().getJobState()); 57 58 child.hardReset(); 59 60 assertEquals(JobState.READY, j.lastJobStateEvent().getJobState()); 61 } 62 63 public void testThen1() { 64 DummyStateJob child = new DummyStateJob(); 65 child.setDesired("complete"); 66 67 DummyStateJob then = new DummyStateJob(); 68 then.setDesired("complete"); 69 70 IfJob j = new IfJob(); 71 j.addComponentChild(child); 72 j.addComponentThen(then); 73 j.init(); 74 75 j.run(); 76 77 assertEquals(JobState.COMPLETE, j.lastJobStateEvent().getJobState()); 78 79 child.hardReset(); 80 81 assertEquals(JobState.READY, j.lastJobStateEvent().getJobState()); 82 83 then.hardReset(); 84 85 assertEquals(JobState.READY, j.lastJobStateEvent().getJobState()); 86 87 } 88 89 public void testThen2() { 90 DummyStateJob child = new DummyStateJob(); 91 child.setDesired("complete"); 92 93 DummyStateJob then = new DummyStateJob(); 94 then.setDesired("not complete"); 95 96 IfJob j = new IfJob(); 97 j.addComponentChild(child); 98 j.addComponentThen(then); 99 j.init(); 100 101 j.run(); 102 103 assertEquals(JobState.NOT_COMPLETE, j.lastJobStateEvent().getJobState()); 104 } 105 106 public void testThen3() { 107 DummyStateJob child = new DummyStateJob(); 108 child.setDesired("complete"); 109 110 DummyStateJob then = new DummyStateJob(); 111 then.setDesired("exception"); 112 113 IfJob j = new IfJob(); 114 j.addComponentChild(child); 115 j.addComponentThen(then); 116 j.init(); 117 118 j.run(); 119 120 assertEquals(JobState.EXCEPTION, j.lastJobStateEvent().getJobState()); 121 122 then.softReset(); 123 124 assertEquals(JobState.READY, j.lastJobStateEvent().getJobState()); 125 assertEquals(JobState.COMPLETE, child.lastJobStateEvent().getJobState()); 126 assertEquals(JobState.READY, then.lastJobStateEvent().getJobState()); 127 128 child.hardReset(); 129 130 assertEquals(JobState.READY, j.lastJobStateEvent().getJobState()); 131 } 132 133 public void testElse1() { 134 DummyStateJob child = new DummyStateJob(); 135 child.setDesired("not complete"); 136 137 DummyStateJob elze = new DummyStateJob(); 138 elze.setDesired("complete"); 139 140 IfJob j = new IfJob(); 141 j.addComponentChild(child); 142 j.addComponentElse(elze); 143 j.init(); 144 145 j.run(); 146 147 assertEquals(JobState.NOT_COMPLETE, j.lastJobStateEvent().getJobState()); 148 149 j.softReset(); 150 151 assertEquals(JobState.READY, j.lastJobStateEvent().getJobState()); 152 assertEquals(JobState.READY, child.lastJobStateEvent().getJobState()); 153 assertEquals(JobState.READY, elze.lastJobStateEvent().getJobState()); 154 } 155 156 public void testElse2() { 157 DummyStateJob child = new DummyStateJob(); 158 child.setDesired("not complete"); 159 160 DummyStateJob elze = new DummyStateJob(); 161 elze.setDesired("not complete"); 162 163 IfJob j = new IfJob(); 164 j.addComponentChild(child); 165 j.addComponentElse(elze); 166 j.init(); 167 168 j.run(); 169 170 assertEquals(JobState.NOT_COMPLETE, j.lastJobStateEvent().getJobState()); 171 } 172 173 public void testElse3() { 174 DummyStateJob child = new DummyStateJob(); 175 child.setDesired("not complete"); 176 177 DummyStateJob elze = new DummyStateJob(); 178 elze.setDesired("exception"); 179 180 IfJob j = new IfJob(); 181 j.addComponentChild(child); 182 j.addComponentElse(elze); 183 j.init(); 184 185 j.run(); 186 187 assertEquals(JobState.EXCEPTION, j.lastJobStateEvent().getJobState()); 188 } 189 190 public void testElseComplete() { 192 DummyStateJob child = new DummyStateJob(); 193 child.setDesired("complete"); 194 195 DummyStateJob elze = new DummyStateJob(); 196 elze.setDesired("complete"); 197 198 IfJob j = new IfJob(); 199 j.addComponentChild(child); 200 j.addComponentElse(elze); 201 j.init(); 202 203 j.run(); 204 205 assertEquals(JobState.COMPLETE, j.lastJobStateEvent().getJobState()); 206 } 207 208 public void testException1() { 209 DummyStateJob child = new DummyStateJob(); 210 child.setDesired("exception"); 211 212 DummyStateJob exception = new DummyStateJob(); 213 exception.setDesired("complete"); 214 215 IfJob j = new IfJob(); 216 j.addComponentChild(child); 217 j.addComponentException(exception); 218 j.init(); 219 220 j.run(); 221 222 assertEquals(JobState.EXCEPTION, j.lastJobStateEvent().getJobState()); 223 } 224 225 public void testException2() { 226 DummyStateJob child = new DummyStateJob(); 227 child.setDesired("exception"); 228 229 DummyStateJob exception = new DummyStateJob(); 230 exception.setDesired("not complete"); 231 232 IfJob j = new IfJob(); 233 j.addComponentChild(child); 234 j.addComponentException(exception); 235 j.init(); 236 237 j.run(); 238 239 assertEquals(JobState.EXCEPTION, j.lastJobStateEvent().getJobState()); 240 } 241 242 public void testException3() { 243 DummyStateJob child = new DummyStateJob(); 244 child.setDesired("exception"); 245 246 DummyStateJob exception = new DummyStateJob(); 247 exception.setDesired("exception"); 248 249 IfJob j = new IfJob(); 250 j.addComponentChild(child); 251 j.addComponentException(exception); 252 j.init(); 253 254 j.run(); 255 256 assertEquals(JobState.EXCEPTION, j.lastJobStateEvent().getJobState()); 257 } 258 259 public void testInOddjob() { 260 261 Oddjob oj = new Oddjob(); 262 oj.setInput(WaitJobTest.class.getResourceAsStream("if.xml")); 263 264 oj.run(); 265 266 assertEquals(JobState.COMPLETE, oj.lastJobStateEvent().getJobState()); 267 } 268 } 269 | Popular Tags |