1 37 package net.sourceforge.cruisecontrol.publishers; 38 39 import java.io.File ; 40 import java.io.IOException ; 41 import java.text.SimpleDateFormat ; 42 import java.util.ArrayList ; 43 import java.util.Date ; 44 import java.util.Iterator ; 45 import java.util.List ; 46 47 import junit.framework.TestCase; 48 import net.sourceforge.cruisecontrol.CruiseControlException; 49 import net.sourceforge.cruisecontrol.util.Util; 50 51 54 public class CurrentBuildStatusPublisherTest extends TestCase { 55 private static final String TEST_DIR = "tmp"; 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 CurrentBuildStatusPublisher publisher = new CurrentBuildStatusPublisher(); 70 try { 71 publisher.validate(); 72 fail("'file' should be a required attribute on CurrentBuildStatusPublisher"); 73 } catch (CruiseControlException cce) { 74 } 75 76 publisher.setFile("somefile"); 77 publisher.validate(); 78 79 publisher.setFile(System.getProperty("java.io.tmpdir") + File.separator + "filename"); 80 publisher.validate(); 81 } 82 83 public void testWriteFile() throws CruiseControlException, IOException { 84 CurrentBuildStatusPublisher publisher = new CurrentBuildStatusPublisher(); 85 final String fileName = TEST_DIR + File.separator + "_testCurrentBuildStatus.txt"; 86 publisher.setFile(fileName); 87 filesToClear.add(new File (fileName)); 88 Date date = new Date (); 89 SimpleDateFormat formatter = new SimpleDateFormat ("MM/dd/yyyy HH:mm:ss"); 90 final String buildTime = formatter.format(new Date (date.getTime() + (300 * 1000))); 91 92 publisher.writeFile(date, 300); 93 String expected = "Next Build Starts At:\n" + buildTime; 94 assertEquals(expected, Util.readFileToString(TEST_DIR + File.separator + "_testCurrentBuildStatus.txt")); 95 } 96 } 97 | Popular Tags |