1   package org.bejug.javacareers.feeder.parser;
2   
3   /***
4    Copyright (C) 2005 The Java Community
5   
6    This program is free software; you can redistribute it and/or modify  it under
7    the terms of the GNU General Public License as published by  the Free Software
8    Foundation; either version 2 of the License, or  (at your option) any later
9    version.
10  
11   This program is distributed in the hope that it will be useful,  but WITHOUT
12   ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS
13   FOR A PARTICULAR PURPOSE. See the  GNU General Public License for more details.
14  
15   You should have received a copy of the GNU General Public License  along with
16   this program; if not, write to the Free Software  Foundation, Inc., 59 Temple
17   Place, Suite 330, Boston, MA 02111-1307 USA.
18   */
19  
20  
21  import java.io.File;
22  import java.io.FileOutputStream;
23  import java.io.IOException;
24  import java.io.OutputStreamWriter;
25  import java.io.Writer;
26  import java.nio.charset.Charset;
27  import java.util.List;
28  
29  import junit.framework.TestCase;
30  
31  import org.apache.commons.logging.Log;
32  import org.apache.commons.logging.LogFactory;
33  import org.gnu.stealthp.rsslib.RSSChannel;
34  import org.gnu.stealthp.rsslib.RSSException;
35  import org.gnu.stealthp.rsslib.RSSHandler;
36  import org.gnu.stealthp.rsslib.RSSImage;
37  import org.gnu.stealthp.rsslib.RSSItem;
38  import org.gnu.stealthp.rsslib.RSSParser;
39  
40  /***
41   * @author Bavo Bruylandt (Last modified by $Author: shally $)
42   * @version $Revision: 1.11 $ - $Date: 2005/12/09 10:46:57 $
43   */
44  public class RssGeneratorTests extends TestCase {
45  
46  
47      /***
48       * 
49       */
50      private static final Log LOG = LogFactory.getLog(RssGeneratorTests.class);
51  
52      /***
53       * @throws RSSException if an error
54       */
55      public void testFeedGenerator() throws RSSException {
56  
57  
58          RSSItem item = new RSSItem();
59          item.setTitle(("Test item 5"));
60          item.setLink(("Http://www.test.be"));
61          item.setDescription(("test desc 2"));
62          RSSChannel channel = new RSSChannel();
63  
64          channel.setDescription("2 D�VELOPPEUR .NET bij Euremis in Waals-Brabant");
65          channel.setLink(("test link 8"));
66          channel.setTitle(("test title 5"));
67          channel.setCopyright(("JCS INT."));
68          channel.setManagingEditor(("JCS INT."));
69          channel.setWebMaster(("JCS INT."));
70  
71          RSSImage image = new RSSImage();
72          image.setTitle("Test Image");
73          image.setLink("http://www.junit.org");
74          image.setUrl("http://www.google.be/images/hp0.gif");
75          channel.setRSSImage(image);
76  
77          RssFeedGenerator generator = new RssFeedGenerator();
78          generator.setChannel(channel);
79          generator.addItem(item);
80          generator.addItem(item);
81          LOG.info("Debug: Generator properties are set");
82          LOG.info("test");
83          LOG.error("test");
84  
85          Writer writer = null;
86          try {
87              File file = new File("build/test2.rss");
88              LOG.info("Debug: Writing to: " + file.getAbsolutePath());
89              //writer = new FileWriter(file);
90              writer = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8"));
91              generator.parseToRSS(writer);
92              LOG.info("Debug: Written:" + writer.toString());
93          } catch (IOException e) {
94              e.printStackTrace();
95          } finally {
96              try {
97                  if (writer != null) {
98                      writer.close();
99                  }
100             } catch (IOException e) {
101                 e.printStackTrace();
102             }
103         }
104         RSSHandler handler = new RSSHandler();
105         LOG.info("Debug: Trying parse");
106         RSSParser.parseXmlFile("build/test2.rss", handler, false);
107         LOG.info("Debug: Parse done");
108         LOG.info("Debug: Getting channel");
109         RSSChannel channelback = handler.getRSSChannel();
110         assertEquals(channelback.getCopyright(), channel.getCopyright());
111         assertEquals(channelback.getDescription(), channel.getDescription());
112         LOG.debug(channelback.getLink());
113         List items = channelback.getItems();
114         RSSItem itemback = (RSSItem) items.get(0);
115         assertNotNull(itemback);
116         assertEquals(item.getLink(), itemback.getLink());
117 
118     }
119 
120 
121 }
122 
123 
124 /***
125  * $Log: RssGeneratorTests.java,v $
126  * Revision 1.11  2005/12/09 10:46:57  shally
127  * Opkuis voor checkstyle en PMD
128  *
129  * Revision 1.10  2005/09/30 14:38:08  bavo_jcs
130  * Fixed URL
131  *
132  * Revision 1.9  2005/09/13 08:11:06  schauwvliege
133  * organize imports
134  *
135  * Revision 1.8  2005/09/01 09:38:55  bavo_jcs
136  * Added logo
137  *
138  * Revision 1.7  2005/08/30 13:07:48  psong09
139  * renamed author: psong09
140  *
141  * Revision 1.6  2005/06/29 09:00:25  psong09
142  * comment component updated
143  *
144  * Revision 1.5  2005/06/14 13:35:00  schauwvliege
145  * fixed tests
146  *
147  * Revision 1.4  2005/06/14 12:05:54  schauwvliege
148  * CheckStyle and fixing tests
149  *
150  * Revision 1.3  2005/06/10 13:27:22  bavo_jcs
151  * new version
152  *
153  * Revision 1.2  2005/06/09 08:19:03  bejug_cc
154  * Fix initial import
155  *
156  * Revision 1.7  2005/06/03 15:11:36  bbr
157  * fixed
158  *
159  * Revision 1.6  2005/06/03 13:04:48  bbr
160  * fixed
161  *
162  * Revision 1.5  2005/06/03 12:32:50  bbr
163  * fixed
164  *
165  * Revision 1.4  2005/05/26 15:38:13  bbr
166  * UTF-8 fix
167  *
168  * Revision 1.3  2005/05/25 13:05:02  ssc
169  * package name
170  *
171  * Revision 1.2  2005/05/24 11:52:39  bbr
172  * Using spring sheduling
173  *
174  * Revision 1.1  2005/05/23 17:38:13  sja
175  * Package move to org.bejug.javacareers.feeder
176  *
177  * Revision 1.1  2005/05/23 15:42:00  bbr
178  * added weight to lucene
179  *
180  * Revision 1.1  2005/05/11 11:53:25  bavo_jcs
181  * refactored
182  * - conform to conventions
183  * - some javadoc
184  * - Added FeederTask design
185  *
186  * Revision 1.2  2005/05/10 16:04:04  bavo_jcs
187  * cleanup
188  *
189  * Revision 1.1  2005/05/09 15:48:46  bavo_jcs
190  * added RSS generator
191  * cleanup/javadoc TODO
192  *
193  */