KickJava   Java API By Example, From Geeks To Geeks.

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


1 //
2
// Informa -- RSS Library for Java
3
// Copyright (c) 2002 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_1_0_Parser.java,v 1.12 2004/05/13 22:55:35 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.ChannelFormat;
39 import de.nava.informa.core.ChannelIF;
40 import de.nava.informa.core.ItemIF;
41 import de.nava.informa.core.ParseException;
42 import de.nava.informa.impl.basic.ChannelBuilder;
43 import de.nava.informa.utils.InformaTestCase;
44
45 public class TestRSS_1_0_Parser extends InformaTestCase {
46
47   static ChannelIF channel;
48   static URL JavaDoc inpURL;
49
50   public TestRSS_1_0_Parser(String JavaDoc name)
51     throws IOException JavaDoc, ParseException {
52
53     super("TestRSS_1_0_Parser", name);
54     this.method_name = name;
55     if (channel == null) {
56       File JavaDoc inpFile = new File JavaDoc(getDataDir(), "bloggy.rdf");
57       channel = FeedParser.parse(new ChannelBuilder(), inpFile);
58       // for later reference
59
inpURL = inpFile.toURL();
60     }
61   }
62
63   public void testCreatedChannel() {
64     assertEquals("bloggy", channel.getTitle());
65     assertEquals("Thoughts, rants, and photos", channel.getDescription());
66     assertEquals(inpURL, channel.getLocation());
67     assertEquals("http://bloggy.com/mt/", channel.getSite().toString());
68
69     assertEquals(channel.getDescription(), channel.getElementValue("description"));
70
71     String JavaDoc attribute = channel.getAttributeValue("admin:generatorAgent", "rdf:resource");
72     assertEquals("http://www.movabletype.org/?v=2.51", attribute);
73   }
74
75   public void testCreatedItems() {
76     assertEquals(15, channel.getItems().size());
77     ItemIF item = searchForItem(channel, "We know what culture is");
78     assertNotNull("Item not found", item);
79     assertEquals("We know what culture is, right?", item.getTitle());
80     assertEquals("http://bloggy.com/mt/archives/000842.html",
81                  item.getLink().toString());
82     assertEquals(100, item.getDescription().length());
83     assertEquals("War", item.getSubject());
84     assertEquals("barry", item.getCreator());
85     Calendar JavaDoc expDate = new GregorianCalendar JavaDoc(TimeZone.getTimeZone("GMT"));
86     expDate.set(2003, Calendar.APRIL, 1, 18, 43, 21);
87     expDate.set(Calendar.MILLISECOND, 0);
88     assertEquals(expDate.getTime(), item.getDate());
89   }
90
91   public void testParseGoogleWeblog() throws Exception JavaDoc {
92     File JavaDoc inpFile = new File JavaDoc(getDataDir(), "google-weblog.rdf");
93     ChannelIF channel_gw = FeedParser.parse(new ChannelBuilder(), inpFile);
94     assertEquals("Google Weblog", channel_gw.getTitle());
95     assertEquals(15, channel_gw.getItems().size());
96     assertEquals(ChannelFormat.RSS_1_0, channel_gw.getFormat());
97   }
98
99   public void testParseW3CSynd() throws Exception JavaDoc {
100     File JavaDoc inpFile = new File JavaDoc(getDataDir(), "w3c-synd.rdf");
101     ChannelIF channel_w3c = FeedParser.parse(new ChannelBuilder(), inpFile);
102     assertEquals("World Wide Web Consortium", channel_w3c.getTitle());
103     assertEquals(7, channel_w3c.getItems().size());
104     assertEquals(ChannelFormat.RSS_1_0, channel_w3c.getFormat());
105   }
106
107 }
108
Popular Tags