KickJava   Java API By Example, From Geeks To Geeks.

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


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

4 package org.oddjob.monitor.action;
5
6 import junit.framework.TestCase;
7
8 import org.apache.log4j.Logger;
9 import org.oddjob.arooa.ArooaConstants;
10 import org.oddjob.arooa.ArooaContext;
11 import org.oddjob.arooa.PropertyProxyResolver;
12 import org.oddjob.arooa.handlers.NestedPropertyHandler;
13 import org.oddjob.designer.model.DesignDefinition;
14 import org.oddjob.designer.view.DummyView;
15 import org.oddjob.designer.view.DummyViewFactory;
16 import org.oddjob.monitor.model.ExplorerContext;
17 import org.oddjob.monitor.model.ExplorerModel;
18 import org.oddjob.scheduling.OJScheduleInstruction;
19 import org.oddjob.scheduling.OddjobScheduler;
20 import org.oddjob.scheduling.ScheduleInstruction;
21 import org.oddjob.scheduling.ScheduleSummary;
22
23 public class ScheduleActionTest extends TestCase {
24     private static final Logger logger = Logger.getLogger(ScheduleActionTest.class);
25     
26             
27     
28     public void testScheduleSomething() throws Exception JavaDoc {
29         class MySched implements OddjobScheduler {
30             String JavaDoc name;
31             ScheduleInstruction si;
32             MySched(String JavaDoc name) {
33                 this.name = name;
34             }
35             public boolean canSchedule(Object JavaDoc component) {
36                 return true;
37             }
38             public ScheduleSummary[] summariesFor(Object JavaDoc object) {
39                 return null;
40             }
41             public void schedule(ScheduleInstruction scheduleInstruction) {
42                 this.si = scheduleInstruction;
43             }
44             public void unSchedule(String JavaDoc id) {
45             }
46             public String JavaDoc toString() {
47                 return name;
48             }
49             
50         }
51     
52         MySched sched1 = new MySched("Scheduler 1");
53         
54         // context required to create the schedule type.
55
ArooaContext arooaContext = new ArooaContext();
56         PropertyProxyResolver propertyProxyResolver = new PropertyProxyResolver();
57         propertyProxyResolver.addResource("/org/oddjob/values/proxies.properties");
58         arooaContext.set(ArooaConstants.PROPERTY_PROXY_RESOLVER, propertyProxyResolver);
59         arooaContext.set(ArooaConstants.PROPERTY_HANDLER, new NestedPropertyHandler());
60
61         ExplorerModel model = new ExplorerModel();
62         // this will ensure we have one schedule in our ExplorerContext.
63
model.setRoot(sched1);
64         model.setArooaContext(arooaContext);
65         
66         ExplorerContext ec = new ExplorerContext(model);
67         
68         ScheduleAction test = new ScheduleAction(sched1, "ojschedule");
69         assertFalse(test.enabled());
70         
71         test.select(new Object JavaDoc(), ec);
72         
73         assertTrue(test.enabled());
74
75         DesignDefinition dd = test.form();
76         
77         DummyView dv = DummyViewFactory.create(dd);
78         
79         dv.get("Schedule Id").attribute("foo");
80         dv.get("Schedule Name").attribute("Test Schedule");
81         dv.get("Schedule").get("Schedule").create("dayofyear")
82                 .get("select").get("On").attribute("25-dec");
83         
84         test.action();
85         
86         OJScheduleInstruction si = (OJScheduleInstruction) sched1.si;
87         assertEquals("foo", si.getId());
88         assertEquals("Test Schedule", si.getName());
89         logger.debug(si.getSchedule());
90     }
91
92 }
93
Popular Tags