1 4 package org.oddjob.jobs.job; 5 6 import junit.framework.TestCase; 7 8 import org.oddjob.Helper; 9 import org.oddjob.Stateful; 10 import org.oddjob.framework.SimpleJob; 11 import org.oddjob.state.JobState; 12 import org.oddjob.state.JobStateHandler; 13 import org.oddjob.state.JobStateListener; 14 15 18 public class DependsJobTest extends TestCase { 19 20 class TestJob extends SimpleJob { 21 boolean ran; 22 public int execute() { 23 ran = true; 24 return 0; 25 } 26 } 27 28 32 public void testReady() { 33 TestJob testJob = new TestJob(); 34 DependsJob j = new DependsJob(); 35 j.setJob(testJob); 36 j.run(); 37 38 assertTrue(testJob.ran); 39 assertEquals("Complete", JobState.COMPLETE, Helper.getJobState(j)); 40 } 41 42 46 public void testAlreadyComplete() { 47 TestJob testJob = new TestJob(); 48 testJob.run(); 49 testJob.ran = false; 50 assertEquals(JobState.COMPLETE, testJob.lastJobStateEvent().getJobState()); 51 52 DependsJob j = new DependsJob(); 53 j.setJob(testJob); 54 j.run(); 55 56 assertFalse(testJob.ran); 57 assertEquals("Complete", JobState.COMPLETE, Helper.getJobState(j)); 58 } 59 60 64 public void testExecuting() throws InterruptedException { 65 class Executing implements Stateful { 66 JobStateHandler h = new JobStateHandler(this); 67 public void addJobStateListener(JobStateListener listener) { 68 h.addJobStateListener(listener); 69 } 70 public void removeJobStateListener(JobStateListener listener) { 71 h.removeJobStateListener(listener); 72 } 73 } 74 Executing testJob = new Executing(); 75 testJob.h.requestJobStateExecuting(); 76 77 DependsJob j = new DependsJob(); 78 j.setJob(testJob); 79 Thread t = new Thread (j); 80 t.start(); 81 82 while (JobState.EXECUTING != Helper.getJobState(j)) { 83 Thread.yield(); 84 } 85 86 testJob.h.setJobStateNotComplete(); 87 88 t.join(); 89 assertEquals(JobState.NOT_COMPLETE, Helper.getJobState(j)); 90 } 91 } 92 | Popular Tags |