KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > persist > PersisterBaseTest


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

4 package org.oddjob.persist;
5
6 import junit.framework.TestCase;
7
8 import org.apache.commons.beanutils.PropertyUtils;
9 import org.oddjob.arooa.registry.ComponentRegistry;
10 import org.oddjob.framework.RunnableWrapper;
11 import org.oddjob.jobs.EchoJob;
12
13 public class PersisterBaseTest extends TestCase {
14
15     class MockPersister extends PersisterBase {
16         String JavaDoc id;
17         Object JavaDoc component;
18         public void persist(String JavaDoc id, Object JavaDoc component) {
19             this.id = id;
20             this.component = component;
21         }
22         public Object JavaDoc restore(String JavaDoc id) {
23             return null;
24         }
25         public void remove(String JavaDoc id) {
26         }
27     }
28     
29     public void test1() throws Exception JavaDoc {
30         MockPersister test = new MockPersister();
31         
32         Object JavaDoc j = RunnableWrapper.wrapperFor(new EchoJob());
33         PropertyUtils.setProperty(j, "text", "Hello");
34         test.setRoot(j);
35         
36         ComponentRegistry registry = new ComponentRegistry();
37         registry.register("foo", j);
38         
39         test.initialise(registry);
40         
41         assertEquals("foo", test.id);
42         assertEquals(j, test.component);
43         
44         test.id = null;
45         test.component = null;
46         
47         ((Runnable JavaDoc) j).run();
48         
49         assertEquals("foo", test.id);
50         assertEquals(j, test.component);
51     }
52 }
53
Popular Tags