1 37 package net.sourceforge.cruisecontrol.publishers; 38 39 import java.io.File ; 40 41 import org.apache.tools.ant.Project; 42 43 import junit.framework.TestCase; 44 import net.sourceforge.cruisecontrol.CruiseControlException; 45 46 49 public class ArtifactsPublisherTest extends TestCase { 50 51 private ArtifactsPublisher publisher; 52 private File tempFile; 53 54 protected void setUp() throws Exception { 55 publisher = new ArtifactsPublisher(); 56 tempFile = File.createTempFile("temp", ".tmp"); 57 tempFile.deleteOnExit(); 58 } 59 60 protected void tearDown() throws Exception { 61 publisher = null; 62 if (tempFile.exists()) { 63 tempFile.delete(); 64 } 65 tempFile = null; 66 } 67 68 public void testShouldPublish() { 69 assertTrue(publisher.shouldPublish(true)); 71 assertTrue(publisher.shouldPublish(false)); 72 73 publisher.setPublishOnFailure(true); 75 assertTrue(publisher.shouldPublish(true)); 76 assertTrue(publisher.shouldPublish(false)); 77 78 publisher.setPublishOnFailure(false); 80 assertTrue(publisher.shouldPublish(true)); 81 assertFalse(publisher.shouldPublish(false)); 82 } 83 84 public void testPublishDirectory() { 85 File tempDir = tempFile.getParentFile(); 86 Project project = new Project(); 87 publisher.setDir(tempFile.getAbsolutePath()); 88 try { 89 publisher.publishDirectory(project, tempDir); 90 fail(); 91 } catch (CruiseControlException expected) { 92 String message = expected.getMessage(); 93 assertTrue(message.startsWith("target directory ")); 94 } 95 } 96 97 public void testPublishFileWhenTargetFileNotExist() { 98 File tempDir = tempFile.getParentFile(); 99 publisher.setFile(tempFile.getName()); 100 try { 101 publisher.publishFile(tempDir); 102 fail(); 103 } catch (CruiseControlException expected) { 104 String message = expected.getMessage(); 105 assertTrue(message.startsWith("target file ")); 106 } 107 } 108 109 public void testValidate() { 110 try { 111 publisher.validate(); 112 fail(); 113 } catch (CruiseControlException expected) { 114 assertNotNull(expected); 115 } 116 117 publisher.setDest("foo"); 118 publisher.setDir("bar"); 119 publisher.setFile("baz"); 120 121 try { 122 publisher.validate(); 123 fail(); 124 } catch (CruiseControlException expected) { 125 assertNotNull(expected); 126 } 127 128 publisher.setFile(null); 129 try { 130 publisher.validate(); 131 } catch (CruiseControlException notExpected) { 132 fail(); 133 } 134 135 publisher.setDir(null); 136 publisher.setFile("baz"); 137 try { 138 publisher.validate(); 139 } catch (CruiseControlException notExpected) { 140 fail(); 141 } 142 143 publisher.setDest(null); 144 try { 145 publisher.validate(); 146 fail(); 147 } catch (CruiseControlException expected) { 148 assertNotNull(expected); 149 } 150 } 151 152 public void testGetDestinationDirectory() { 153 String tempDir = tempFile.getParent(); 154 publisher.setDest(tempDir); 155 String timestamp = "20040102030405"; 156 File destinationDir = publisher.getDestinationDirectory(timestamp); 157 String expected = tempDir + File.separatorChar + timestamp; 158 assertEquals(expected, destinationDir.getPath()); 159 160 final String subdir = "subdir"; 161 publisher.setSubdirectory(subdir); 162 destinationDir = publisher.getDestinationDirectory(timestamp); 163 expected = tempDir + File.separatorChar + timestamp + File.separatorChar + subdir; 164 assertEquals(expected, destinationDir.getPath()); 165 166 } 167 } 168 | Popular Tags |