1 4 package org.oddjob.persist; 5 6 import java.io.File ; 7 8 import junit.framework.TestCase; 9 10 import org.apache.commons.beanutils.DynaBean; 11 import org.oddjob.Helper; 12 import org.oddjob.Resetable; 13 import org.oddjob.framework.RunnableWrapper; 14 import org.oddjob.jobs.EchoJob; 15 import org.oddjob.state.JobState; 16 17 21 public class SerializePersisterTest extends TestCase { 22 23 27 public void testPersist() { 28 Object job = RunnableWrapper.wrapperFor(new EchoJob()); 29 ((DynaBean) job).set("name", "Test"); 30 ((DynaBean) job).set("text", "Hello World"); 31 ((Runnable ) job).run(); 32 33 SerializePersister persister = new SerializePersister(); 34 persister.setDir(new File ("test/persist")); 35 36 try { 37 persister.persist("test-persist", job); 38 } 39 catch (OddjobPersistException e) { 40 e.printStackTrace(); 41 fail ("test persist should work." + e.getMessage()); 42 } 43 44 File check = new File ("test/persist/test-persist.ser"); 45 assertTrue(check.exists()); 46 } 47 48 52 public void testLoad() { 53 SerializePersister persister = new SerializePersister(); 54 persister.setDir(new File ("test/persist")); 55 56 Runnable job = (Runnable ) persister.restore("test-persist"); 57 58 assertEquals(JobState.COMPLETE, Helper.getJobState(job)); 59 60 62 ((Resetable) job).hardReset(); 63 64 assertEquals(JobState.READY, Helper.getJobState(job)); 65 66 job.run(); 67 68 assertEquals(JobState.COMPLETE, Helper.getJobState(job)); 69 } 70 71 public void testNullDirectory() { 72 SerializePersister persister = new SerializePersister(); 73 File file = persister.fileFor("whatever"); 74 75 assertNotNull(file); 76 } 77 } 78 | Popular Tags |