1 37 package net.sourceforge.cruisecontrol.bootstrappers; 38 39 import junit.framework.TestCase; 40 import net.sourceforge.cruisecontrol.CruiseControlException; 41 import net.sourceforge.cruisecontrol.util.Util; 42 43 import java.io.File ; 44 import java.io.IOException ; 45 import java.text.SimpleDateFormat ; 46 import java.util.ArrayList ; 47 import java.util.Date ; 48 import java.util.Iterator ; 49 import java.util.List ; 50 51 54 public class CurrentBuildStatusBootstrapperTest extends TestCase { 55 private static final String TEST_DIR = System.getProperty("java.io.tmpdir"); 56 private final List filesToClear = new ArrayList (); 57 58 public void tearDown() { 59 for (Iterator iterator = filesToClear.iterator(); iterator.hasNext();) { 60 File file = (File ) iterator.next(); 61 if (file.exists()) { 62 file.delete(); 63 } 64 } 65 filesToClear.clear(); 66 } 67 68 public void testValidate() throws CruiseControlException { 69 CurrentBuildStatusBootstrapper bootstrapper = new CurrentBuildStatusBootstrapper(); 70 try { 71 bootstrapper.validate(); 72 fail("'file' should be a required attribute on CurrentBuildStatusBootstrapper"); 73 } catch (CruiseControlException cce) { 74 } 75 76 bootstrapper.setFile("somefile"); 77 bootstrapper.validate(); 78 79 bootstrapper.setFile(TEST_DIR + File.separator + "filename"); 80 bootstrapper.validate(); 81 } 82 83 public void testBootstrap() throws CruiseControlException, IOException { 84 CurrentBuildStatusBootstrapper bootstrapper = new CurrentBuildStatusBootstrapper(); 85 final String fileName = TEST_DIR + File.separator + "_testCurrentBuildStatus.txt"; 86 bootstrapper.setFile(fileName); 87 filesToClear.add(new File (fileName)); 88 89 bootstrapper.bootstrap(); 90 Date date = new Date (); 92 93 SimpleDateFormat formatter = new SimpleDateFormat ("MM/dd/yyyy HH:mm:ss"); 94 String expected = "Current Build Started At:\n" + formatter.format(date); 95 assertEquals(expected, Util.readFileToString(fileName)); 96 } 97 } 98 | Popular Tags |