1 37 package net.sourceforge.cruisecontrol.publishers.rss; 38 39 import java.io.BufferedOutputStream ; 40 import java.io.FileWriter ; 41 import java.io.FileOutputStream ; 42 import java.io.InputStream ; 43 import java.io.IOException ; 44 import java.io.File ; 45 46 import junit.framework.TestCase; 47 48 51 public class FeedTest extends TestCase { 52 53 private File tempFile; 54 55 public void setUp() throws Exception { 56 tempFile = File.createTempFile("FeedTest", "tmp"); 57 tempFile.deleteOnExit(); 58 59 BufferedOutputStream bos = new BufferedOutputStream (new FileOutputStream (tempFile)); 60 InputStream is = getClass().getResourceAsStream("RSSFeed.xml"); 61 62 int bytesRead; 63 byte[] buffer = new byte[1024]; 64 while ((bytesRead = is.read(buffer)) > 0) { 65 bos.write(buffer, 0, bytesRead); 66 } 67 bos.close(); 68 is.close(); 69 } 70 71 public void tearDown() { 72 tempFile.delete(); 73 } 74 75 public void testConstructors() { 76 Feed feed = new Feed(tempFile); 77 78 assertEquals("CruiseControl Build Results", feed.getTitle()); 79 assertEquals("http://MyMachine.MyDomain.com/cruisecontrol/", feed.getLink()); 80 assertEquals( 81 "Automated build results for CruiseControl project(s) VERSION_10", 82 feed.getDescription()); 83 84 assertEquals(11, feed.getItems().size()); 86 Item item = (Item) feed.getItems().get(0); 87 assertEquals("VERSION_10 build.7 Build Successful", item.getTitle()); 88 assertEquals("http://MyMachine.MyDomain.com/cruisecontrol/buildresults/" 89 + "VERSION_10?log=log20050817084109Lbuild.7", item.getLink()); 90 assertEquals( 91 "<em>Build Time:</em> Wed Aug 17 08:41:09 MDT 2005<br/>" 92 + "<em>Label:</em> build.7<br/><em>Modifications: </em>1<br/>" 93 + "\n<ul><li>//depot/MyProduct/VERSION_10/dev/main/src/datacenter/" 94 + "ApplicationServer/PlayTime/default.build" 95 + " by jefferson (deploy the mock object dll)</li></ul>", 96 item.getDescription()); 97 } 98 99 100 public void testWrite() throws Exception { 101 FileWriter fw = null; 102 File outFile = null; 103 104 try { 105 outFile = File.createTempFile("FeedTest", "tmp"); 106 fw = new FileWriter (outFile); 107 Feed feed = new Feed(tempFile); 108 feed.write(fw); 109 fw.close(); 110 111 assertEquals("CruiseControl Build Results", feed.getTitle()); 113 assertEquals("http://MyMachine.MyDomain.com/cruisecontrol/", feed.getLink()); 114 assertEquals( 115 "Automated build results for CruiseControl project(s) VERSION_10", 116 feed.getDescription()); 117 118 assertEquals(11, feed.getItems().size()); 120 Item item = (Item) feed.getItems().get(0); 121 assertEquals("VERSION_10 build.7 Build Successful", item.getTitle()); 122 assertEquals( 123 "http://MyMachine.MyDomain.com/cruisecontrol/buildresults/" 124 + "VERSION_10?log=log20050817084109Lbuild.7", 125 item.getLink()); 126 assertEquals( 127 "<em>Build Time:</em> Wed Aug 17 08:41:09 MDT 2005<br/>" 128 + "<em>Label:</em> build.7<br/><em>Modifications: </em>1<br/>" 129 + "\n<ul><li>//depot/MyProduct/VERSION_10/dev/main/src/datacenter/" 130 + "ApplicationServer/PlayTime/default.build" 131 + " by jefferson (deploy the mock object dll)</li></ul>", 132 item.getDescription()); 133 } finally { 134 if (fw != null) { 135 try { 136 fw.close(); 137 } catch (IOException ignore) { 138 } 139 } 140 if (outFile != null) { 141 outFile.delete(); 142 } 143 } 144 } 145 } | Popular Tags |