1 37 package net.sourceforge.cruisecontrol.bootstrappers; 38 39 import java.text.SimpleDateFormat ; 40 import java.util.ArrayList ; 41 import java.util.Date ; 42 import java.util.Iterator ; 43 import java.util.List ; 44 import java.io.File ; 45 46 import junit.framework.TestCase; 47 import net.sourceforge.cruisecontrol.CruiseControlException; 48 49 52 public class CurrentBuildStatusFTPBootstrapperTest extends TestCase { 53 private final List filesToClear = new ArrayList (); 54 55 public CurrentBuildStatusFTPBootstrapperTest(String name) { 56 super(name); 57 } 58 59 public void tearDown() { 60 for (Iterator iterator = filesToClear.iterator(); iterator.hasNext();) { 61 File file = (File ) iterator.next(); 62 if (file.exists()) { 63 file.delete(); 64 } 65 } 66 } 67 68 public void testValidate1() { 69 CurrentBuildStatusFTPBootstrapper cbsfb = 70 new CurrentBuildStatusFTPBootstrapper(); 71 try { 72 cbsfb.validate(); 73 fail("did not fail for unset properties"); 74 } catch (CruiseControlException cce) { 75 } 77 } 78 79 public void testValidate2() { 80 CurrentBuildStatusFTPBootstrapper cbsfb = 81 new CurrentBuildStatusFTPBootstrapper(); 82 cbsfb.setTargetHost("x"); 83 try { 84 cbsfb.validate(); 85 fail("'file' should be a required attribute on CurrentBuildStatusFTPBootstrapper"); 86 } catch (CruiseControlException cce) { 87 } 89 } 90 91 public void testValidate3() { 92 CurrentBuildStatusFTPBootstrapper cbsfb = 93 new CurrentBuildStatusFTPBootstrapper(); 94 cbsfb.setFile("x"); 95 try { 96 cbsfb.validate(); 97 fail("'targetHost' should be a required attribute on CurrentBuildStatusFTPBootstrapper"); 98 } catch (CruiseControlException cce) { 99 } 101 } 102 103 public void testValidate4() throws Exception { 104 CurrentBuildStatusFTPBootstrapper cbsfb = 105 new CurrentBuildStatusFTPBootstrapper(); 106 cbsfb.setTargetHost("x"); 107 cbsfb.setFile("x"); 108 cbsfb.setDestDir("x"); 109 cbsfb.validate(); 110 } 111 112 public void testMakeFile1() throws Exception { 113 CurrentBuildStatusFTPBootstrapper cbsfb = 114 new CurrentBuildStatusFTPBootstrapper(); 115 cbsfb.setFile("_testCurrentBuildStatus1.txt"); 116 filesToClear.add(new File ("_testCurrentBuildStatus1.txt")); 117 118 SimpleDateFormat formatter = new SimpleDateFormat ("MM/dd/yyyy HH:mm:ss"); 121 String expected = 122 "Current Build Started At:\n" 123 + formatter.format(new Date ()); 124 String out = cbsfb.makeFile(); 125 assertEquals(expected, out); 126 } 127 } 128 | Popular Tags |