KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > bootstrappers > LockFileBootstrapperTest


1 package net.sourceforge.cruisecontrol.bootstrappers;
2
3 import java.io.File JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.util.ArrayList JavaDoc;
6 import java.util.Iterator JavaDoc;
7 import java.util.List JavaDoc;
8
9 import junit.framework.TestCase;
10 import net.sourceforge.cruisecontrol.CruiseControlException;
11
12 public class LockFileBootstrapperTest extends TestCase {
13
14     private LockFileBootstrapper bootstrapper;
15     private List JavaDoc filesToDelete;
16     
17     protected void setUp() {
18         bootstrapper = new LockFileBootstrapper();
19         filesToDelete = new ArrayList JavaDoc();
20     }
21
22     protected void tearDown() throws Exception JavaDoc {
23         for (Iterator JavaDoc iter = filesToDelete.iterator(); iter.hasNext();) {
24             File JavaDoc file = (File JavaDoc) iter.next();
25             file.delete();
26         }
27         bootstrapper = null;
28         filesToDelete = null;
29     }
30
31     public void testAttemptToCreateLockFile() throws IOException JavaDoc, CruiseControlException {
32         File JavaDoc lock = File.createTempFile("test", ".lck");
33         filesToDelete.add(lock);
34         lock.delete();
35         assertFalse(lock.exists());
36         
37         bootstrapper.setLockFile(lock.getAbsolutePath());
38         
39         bootstrapper.bootstrap();
40         assertTrue(lock.exists());
41         
42         try {
43             bootstrapper.bootstrap();
44             fail("should throw exception when lock already exists");
45         } catch (CruiseControlException expected) {
46         }
47     }
48     
49     public void testValidate() throws CruiseControlException {
50         try {
51             bootstrapper.validate();
52             fail("should throw exception when lock file not set");
53         } catch (CruiseControlException expected) {
54         }
55         
56         bootstrapper.setLockFile("delete.me");
57         bootstrapper.validate();
58     }
59     
60 }
61
Popular Tags