KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > publishers > rss > FeedTest


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2005, ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

37 package net.sourceforge.cruisecontrol.publishers.rss;
38
39 import java.io.BufferedOutputStream JavaDoc;
40 import java.io.FileWriter JavaDoc;
41 import java.io.FileOutputStream JavaDoc;
42 import java.io.InputStream JavaDoc;
43 import java.io.IOException JavaDoc;
44 import java.io.File JavaDoc;
45
46 import junit.framework.TestCase;
47
48 /*
49  * Copyright (c) 2005 Hewlett-Packard Development Company, L.P.
50  */

51 public class FeedTest extends TestCase {
52
53     private File JavaDoc tempFile;
54
55     public void setUp() throws Exception JavaDoc {
56         tempFile = File.createTempFile("FeedTest", "tmp");
57         tempFile.deleteOnExit();
58
59         BufferedOutputStream JavaDoc bos = new BufferedOutputStream JavaDoc(new FileOutputStream JavaDoc(tempFile));
60         InputStream JavaDoc 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         //validate the number of items and the contents of the first item.
85
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 JavaDoc {
101         FileWriter JavaDoc fw = null;
102         File JavaDoc outFile = null;
103
104         try {
105             outFile = File.createTempFile("FeedTest", "tmp");
106             fw = new FileWriter JavaDoc(outFile);
107             Feed feed = new Feed(tempFile);
108             feed.write(fw);
109             fw.close();
110
111             // Feed feed2 = new Feed(outFile);
112
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             //validate the number of items and the contents of the first item.
119
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 JavaDoc ignore) {
138                 }
139             }
140             if (outFile != null) {
141                 outFile.delete();
142             }
143         }
144     }
145 }
Popular Tags