KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > monitor > action > SchedulerMenuTest


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.monitor.action;
5
6 import junit.framework.TestCase;
7
8 import org.oddjob.monitor.model.ExplorerContext;
9 import org.oddjob.monitor.model.ExplorerModel;
10 import org.oddjob.scheduling.OddjobScheduler;
11 import org.oddjob.scheduling.ScheduleInstruction;
12 import org.oddjob.scheduling.ScheduleSummary;
13
14 public class SchedulerMenuTest extends TestCase {
15
16     public void testNoSchedulers() {
17         Object JavaDoc root = new Object JavaDoc();
18         ExplorerModel em = new ExplorerModel();
19         em.setRoot(root);
20         ExplorerContext parentContext = new ExplorerContext(em);
21         
22         Object JavaDoc job = new Object JavaDoc();
23         ExplorerContext ec = new ExplorerContext(
24                 job, parentContext);
25         
26         SchedulerMenu test = new SchedulerMenu();
27         assertFalse(test.enabled());
28         
29         test.select(job, ec);
30         
31         assertTrue(test.enabled());
32         assertEquals(1, test.options().length);
33     }
34
35     public void testWithSchedulers() {
36         class MySched implements OddjobScheduler {
37             String JavaDoc name;
38             MySched(String JavaDoc name) {
39                 this.name = name;
40             }
41             public boolean canSchedule(Object JavaDoc component) {
42                 return true;
43             }
44             public ScheduleSummary[] summariesFor(Object JavaDoc object) {
45                 return null;
46             }
47             public void schedule(ScheduleInstruction scheduleInstruction) {
48             }
49             public void unSchedule(String JavaDoc id) {
50             }
51             public String JavaDoc toString() {
52                 return name;
53             }
54             
55         }
56     
57         MySched sched1 = new MySched("Scheduler 1");
58         MySched sched2 = new MySched("Scheduler 2");
59
60         Object JavaDoc job = new Object JavaDoc();
61         ExplorerModel em = new ExplorerModel();
62         em.setRoot(job);
63         
64         ExplorerContext ec = new ExplorerContext(em);
65         ec.getSchedulerTraker().addScheduler(sched1);
66         ec.getSchedulerTraker().addScheduler(sched2);
67         
68         SchedulerMenu test = new SchedulerMenu();
69         assertFalse(test.enabled());
70         
71         test.select(em, ec);
72         
73         assertTrue(test.enabled());
74         assertEquals(2, test.options().length);
75     }
76
77 }
78
Popular Tags