1 4 package org.oddjob.io; 5 6 import java.io.ByteArrayInputStream ; 7 import java.io.File ; 8 9 import junit.framework.TestCase; 10 11 import org.apache.commons.io.FileUtils; 12 import org.oddjob.Helper; 13 import org.oddjob.Oddjob; 14 import org.oddjob.state.JobState; 15 16 public class MkdirJobTest extends TestCase { 17 18 File dir = new File ("work/io/mkdir"); 19 20 public void setUp() throws Exception { 21 if (dir.exists()) { 22 FileUtils.forceDelete(dir); 23 } 24 } 25 26 public void testSimple() { 27 MkdirJob test = new MkdirJob(); 28 test.setDir(dir); 29 test.run(); 30 31 assertTrue(dir.exists()); 32 } 33 34 public void testFileExists() throws Exception { 35 FileUtils.touch(dir); 36 37 MkdirJob test = new MkdirJob(); 38 test.setDir(dir); 39 try { 40 test.run(); 41 fail("Should throw exception."); 42 } catch (Exception e) { 43 } 45 46 assertTrue(dir.isFile()); 47 } 48 49 public void testDirExists() throws Exception { 50 FileUtils.forceMkdir(dir); 51 52 MkdirJob test = new MkdirJob(); 53 test.setDir(dir); 54 test.run(); 55 56 assertTrue(dir.isDirectory()); 57 } 58 59 public void testMissingParents() throws Exception { 60 File create = new File (dir, "a/b/c"); 61 62 MkdirJob test = new MkdirJob(); 63 test.setDir(create); 64 test.run(); 65 66 assertTrue(create.exists()); 67 } 68 69 public void testInOddjob() { 70 String xml = "<oddjob><mkdir dir='work/io/mkdir'/></oddjob>"; 71 72 Oddjob oj = new Oddjob(); 73 oj.setInput(new ByteArrayInputStream (xml.getBytes())); 74 oj.run(); 75 76 assertEquals(JobState.COMPLETE, oj.lastJobStateEvent().getJobState()); 77 assertTrue(dir.exists()); 78 } 79 80 public void testSerailize() throws Exception { 81 MkdirJob test = new MkdirJob(); 82 test.setDir(dir); 83 84 Runnable copy = (Runnable ) Helper.copy(test); 85 copy.run(); 86 87 assertTrue(dir.exists()); 88 } 89 90 } 91 | Popular Tags |