KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > parsers > TestRSS_2_0_Parser


1 //
2
// Informa -- RSS Library for Java
3
// Copyright (c) 2002, 2003 by Niko Schmuck
4
//
5
// Niko Schmuck
6
// http://sourceforge.net/projects/informa
7
// mailto:niko_schmuck@users.sourceforge.net
8
//
9
// This library is free software.
10
//
11
// You may redistribute it and/or modify it under the terms of the GNU
12
// Lesser General Public License as published by the Free Software Foundation.
13
//
14
// Version 2.1 of the license should be included with this distribution in
15
// the file LICENSE. If the license is not included with this distribution,
16
// you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
17
// or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
18
// MA 02139 USA.
19
//
20
// This library is distributed in the hope that it will be useful,
21
// but WITHOUT ANY WARRANTY; without even the implied waranty of
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
// Lesser General Public License for more details.
24
//
25

26
27 // $Id: TestRSS_2_0_Parser.java,v 1.10 2004/08/26 06:43:53 niko_schmuck Exp $
28

29 package de.nava.informa.parsers;
30
31 import java.io.File JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.net.URL JavaDoc;
34 import java.util.Calendar JavaDoc;
35 import java.util.GregorianCalendar JavaDoc;
36 import java.util.TimeZone JavaDoc;
37
38 import de.nava.informa.core.*;
39 import de.nava.informa.impl.basic.ChannelBuilder;
40 import de.nava.informa.utils.InformaTestCase;
41
42 public class TestRSS_2_0_Parser extends InformaTestCase {
43
44   static ChannelIF channel;
45   static URL JavaDoc inpURL;
46   
47   public TestRSS_2_0_Parser(String JavaDoc name)
48     throws IOException JavaDoc, ParseException {
49     
50     super("TestRSS_2_0_Parser", name);
51     if (channel == null) {
52       File JavaDoc inpFile = new File JavaDoc(getDataDir(), "informa-projnews.xml");
53       channel = FeedParser.parse(new ChannelBuilder(), inpFile);
54       // for later reference
55
inpURL = inpFile.toURL();
56     }
57   }
58
59   public void testCreatedChannel() {
60     assertEquals("SourceForge.net: SF.net Project News: RSS Library for Java",
61                  channel.getTitle());
62     assertEquals(313, channel.getDescription().length());
63     assertEquals(inpURL, channel.getLocation());
64     assertEquals("http://sourceforge.net/projects/informa/",
65                  channel.getSite().toString());
66     assertEquals(ChannelFormat.RSS_2_0, channel.getFormat());
67   }
68
69   public void testItemDetails() {
70     assertEquals(5, channel.getItems().size());
71     ItemIF item = searchForItem(channel, "First alpha release of Informa");
72     assertNotNull("Item not found", item);
73     assertEquals("First alpha release of Informa is now out", item.getTitle());
74     assertEquals("http://sourceforge.net/forum/forum.php?forum_id=200619",
75                  item.getLink().toString());
76     assertEquals(121, item.getDescription().length());
77     Calendar JavaDoc expDate = new GregorianCalendar JavaDoc(TimeZone.getTimeZone("GMT"));
78     expDate.set(2002, Calendar.AUGUST, 7, 0, 32, 5);
79     expDate.set(Calendar.MILLISECOND, 0);
80     assertEquals(expDate.getTime(), item.getDate());
81   }
82   
83   public void testParseW3CSynd() throws Exception JavaDoc {
84     File JavaDoc inpFile = new File JavaDoc(getDataDir(), "msdn-rss2.xml");
85     ChannelIF channel_msdn = FeedParser.parse(new ChannelBuilder(), inpFile);
86     assertEquals("MSDN Just Published", channel_msdn.getTitle());
87     assertEquals(63, channel_msdn.getItems().size());
88     assertEquals(ChannelFormat.RSS_2_0, channel_msdn.getFormat());
89   }
90
91   public void testParseYahooBusiness() throws Exception JavaDoc {
92     File JavaDoc inpFile = new File JavaDoc(getDataDir(), "business.rss");
93     ChannelIF channel_business = FeedParser.parse(new ChannelBuilder(), inpFile);
94     assertEquals("Yahoo! News - Business", channel_business.getTitle());
95     assertEquals("http://news.yahoo.com/news?tmpl=index&cid=1885",
96                  channel_business.getSite().toString());
97     assertEquals(11, channel_business.getItems().size());
98     assertEquals(ChannelFormat.RSS_2_0, channel_business.getFormat());
99     ItemIF item = searchForItem(channel_business, "Taking the World by Hand (Forbes.com)");
100     assertNotNull("Item not found", item);
101   }
102
103   public void testParseWithDefaultNS() throws Exception JavaDoc {
104     File JavaDoc inpFile = new File JavaDoc(getDataDir(), "rss2withNS.xml");
105     ChannelIF channel_wns = FeedParser.parse(new ChannelBuilder(), inpFile);
106     assertEquals("Blogging Roller", channel_wns.getTitle());
107     assertEquals(15, channel_wns.getItems().size());
108     assertEquals(ChannelFormat.RSS_2_0, channel_wns.getFormat());
109     assertEquals(((CategoryIF)((ItemIF)channel_wns.getItems().toArray()[0]).getCategories().toArray()[0]).getTitle(), "Roller");
110   }
111
112 }
113
Popular Tags