001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2005, ThoughtWorks, Inc.
004: * 200 E. Randolph, 25th Floor
005: * Chicago, IL 60601 USA
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * + Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * + Redistributions in binary form must reproduce the above
016: * copyright notice, this list of conditions and the following
017: * disclaimer in the documentation and/or other materials provided
018: * with the distribution.
019: *
020: * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
021: * names of its contributors may be used to endorse or promote
022: * products derived from this software without specific prior
023: * written permission.
024: *
025: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
029: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
030: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
031: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
032: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
033: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
034: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
035: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
036: ********************************************************************************/package net.sourceforge.cruisecontrol.publishers.rss;
037:
038: import java.io.BufferedOutputStream;
039: import java.io.File;
040: import java.io.FileOutputStream;
041: import java.io.FileWriter;
042: import java.io.InputStream;
043:
044: import junit.framework.TestCase;
045: import net.sourceforge.cruisecontrol.testutil.TestUtil.FilesToDelete;
046: import net.sourceforge.cruisecontrol.util.IO;
047:
048: /*
049: * Copyright (c) 2005 Hewlett-Packard Development Company, L.P.
050: */
051: public class FeedTest extends TestCase {
052:
053: private File tempFile;
054: private final FilesToDelete filesToDelete = new FilesToDelete();
055:
056: public void setUp() throws Exception {
057: tempFile = File.createTempFile("FeedTest", "tmp");
058: tempFile.deleteOnExit();
059: filesToDelete.add(tempFile);
060:
061: BufferedOutputStream bos = new BufferedOutputStream(
062: new FileOutputStream(tempFile));
063: InputStream is = getClass().getResourceAsStream("RSSFeed.xml");
064:
065: int bytesRead;
066: byte[] buffer = new byte[1024];
067: while ((bytesRead = is.read(buffer)) > 0) {
068: bos.write(buffer, 0, bytesRead);
069: }
070: bos.close();
071: is.close();
072: }
073:
074: public void tearDown() {
075: filesToDelete.delete();
076: }
077:
078: public void testConstructors() {
079: Feed feed = new Feed(tempFile);
080:
081: assertEquals("CruiseControl Build Results", feed.getTitle());
082: assertEquals("http://MyMachine.MyDomain.com/cruisecontrol/",
083: feed.getLink());
084: assertEquals(
085: "Automated build results for CruiseControl project(s) VERSION_10",
086: feed.getDescription());
087:
088: //validate the number of items and the contents of the first item.
089: assertEquals(11, feed.getItems().size());
090: Item item = (Item) feed.getItems().get(0);
091: assertEquals("VERSION_10 build.7 Build Successful", item
092: .getTitle());
093: assertEquals(
094: "http://MyMachine.MyDomain.com/cruisecontrol/buildresults/"
095: + "VERSION_10?log=log20050817084109Lbuild.7",
096: item.getLink());
097: assertEquals(
098: "<em>Build Time:</em> Wed Aug 17 08:41:09 MDT 2005<br/>"
099: + "<em>Label:</em> build.7<br/><em>Modifications: </em>1<br/>"
100: + "\n<ul><li>//depot/MyProduct/VERSION_10/dev/main/src/datacenter/"
101: + "ApplicationServer/PlayTime/default.build"
102: + " by jefferson (deploy the mock object dll)</li></ul>",
103: item.getDescription());
104: }
105:
106: public void testWrite() throws Exception {
107: FileWriter fw = null;
108: File outFile = null;
109:
110: try {
111: outFile = File.createTempFile("FeedTest", "tmp");
112: filesToDelete.add(outFile);
113: fw = new FileWriter(outFile);
114: Feed feed = new Feed(tempFile);
115: feed.write(fw);
116: fw.close();
117:
118: // Feed feed2 = new Feed(outFile);
119: assertEquals("CruiseControl Build Results", feed.getTitle());
120: assertEquals(
121: "http://MyMachine.MyDomain.com/cruisecontrol/",
122: feed.getLink());
123: assertEquals(
124: "Automated build results for CruiseControl project(s) VERSION_10",
125: feed.getDescription());
126:
127: //validate the number of items and the contents of the first item.
128: assertEquals(11, feed.getItems().size());
129: Item item = (Item) feed.getItems().get(0);
130: assertEquals("VERSION_10 build.7 Build Successful", item
131: .getTitle());
132: assertEquals(
133: "http://MyMachine.MyDomain.com/cruisecontrol/buildresults/"
134: + "VERSION_10?log=log20050817084109Lbuild.7",
135: item.getLink());
136: assertEquals(
137: "<em>Build Time:</em> Wed Aug 17 08:41:09 MDT 2005<br/>"
138: + "<em>Label:</em> build.7<br/><em>Modifications: </em>1<br/>"
139: + "\n<ul><li>//depot/MyProduct/VERSION_10/dev/main/src/datacenter/"
140: + "ApplicationServer/PlayTime/default.build"
141: + " by jefferson (deploy the mock object dll)</li></ul>",
142: item.getDescription());
143: } finally {
144: IO.close(fw);
145: }
146: }
147: }
|