1 37 package net.sourceforge.cruisecontrol.sourcecontrols; 38 39 import java.io.File ; 40 import java.util.Date ; 41 import java.util.List ; 42 import java.net.URL ; 43 44 import junit.framework.TestCase; 45 import net.sourceforge.cruisecontrol.CruiseControlException; 46 import net.sourceforge.cruisecontrol.Modification; 47 48 public class HttpFileTest extends TestCase { 49 50 public void testValidate() { 51 HttpFile httpFile = new HttpFile(); 52 53 try { 54 httpFile.validate(); 55 fail("HttpFile should throw when url not set."); 56 } catch (CruiseControlException e) { 57 assertEquals("'url' is required for HttpFile", e.getMessage()); 58 } 59 60 httpFile.setURL("Invalid URL"); 61 try { 62 httpFile.validate(); 63 fail("HttpFile should throw when an invalid URL is provided"); 64 } catch (CruiseControlException e) { 65 assertEquals( 66 "'url' is not a valid connection string : no protocol: Invalid URL", 67 e.getMessage()); 68 } 69 } 70 71 public void testGetModifications() throws Exception { 72 final long timestamp = 100; 73 HttpFile httpFile = new HttpFile() { 74 protected long getURLLastModified(URL url) { 75 return timestamp; 76 } 77 }; 78 httpFile.setURL("http://dummy.domain.net/my/path?que=ry"); 79 List modifications = httpFile.getModifications(new Date (1), new Date ()); 80 assertEquals(1, modifications.size()); 81 Modification modif = (Modification) modifications.get(0); 82 assertEquals("my/path?que=ry", modif.getFileName()); 83 assertEquals("dummy.domain.net", modif.getFolderName()); 84 assertEquals("dummy.domain.net/my/path?que=ry", modif.getFullPath()); 85 assertEquals("", modif.comment); 86 assertEquals(timestamp, modif.modifiedTime.getTime()); 87 assertEquals("User", modif.userName); 88 } 89 90 public void testGetModificationsInvalidURL() throws Exception { 91 HttpFile httpFile = new HttpFile(); 92 File tempFile = File.createTempFile("HttpFileTest", null); 93 tempFile.deleteOnExit(); 94 httpFile.setURL(tempFile.toURL().toExternalForm()); 95 tempFile.delete(); 96 httpFile.getModifications(new Date (), new Date ()); 98 } 99 } 100 | Popular Tags |