01: //
02: // Informa -- RSS Library for Java
03: // Copyright (c) 2002 by Niko Schmuck
04: //
05: // Niko Schmuck
06: // http://sourceforge.net/projects/informa
07: // mailto:niko_schmuck@users.sourceforge.net
08: //
09: // 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: // $Id: TestRSS_0_91_Parser.java,v 1.15 2005/09/27 22:17:09 niko_schmuck Exp $
27:
28: package de.nava.informa.parsers;
29:
30: import java.io.File;
31: import java.io.IOException;
32: import java.net.URL;
33: import java.util.Date;
34: import java.util.Iterator;
35:
36: import de.nava.informa.core.ChannelFormat;
37: import de.nava.informa.core.ChannelIF;
38: import de.nava.informa.core.ItemIF;
39: import de.nava.informa.core.ParseException;
40: import de.nava.informa.impl.basic.ChannelBuilder;
41: import de.nava.informa.utils.InformaTestCase;
42:
43: public class TestRSS_0_91_Parser extends InformaTestCase {
44:
45: static ChannelIF channel;
46: static URL inpURL;
47:
48: public TestRSS_0_91_Parser(String name) throws IOException,
49: ParseException {
50:
51: super ("TestRSS_0_91_Parser", name);
52: if (channel == null) {
53: File inpFile = new File(getDataDir(), "xmlhack-0.91.xml");
54: channel = FeedParser.parse(new ChannelBuilder(), inpFile);
55: // for later reference
56: inpURL = inpFile.toURL();
57: }
58: }
59:
60: public void testCreatedChannel() {
61: assertEquals("xmlhack", channel.getTitle());
62: assertEquals("Developer news from the XML community", channel
63: .getDescription());
64: assertEquals(inpURL, channel.getLocation());
65: assertEquals("http://www.xmlhack.com", channel.getSite()
66: .toString());
67: assertEquals(ChannelFormat.RSS_0_91, channel.getFormat());
68:
69: String[] elements = { "title", "url", "link", "width",
70: "height", "description" };
71: String[] values = channel.getElementValues("image", elements);
72: assertEquals("xmlhack", values[0]);
73: assertEquals("http://www.xmlhack.com/images/mynetscape88.gif",
74: values[1]);
75: assertEquals("http://www.xmlhack.com", values[2]);
76: assertEquals("88", values[3]);
77: assertEquals("31", values[4]);
78: assertEquals(
79: "News, opinions, tips and issues concerning XML development",
80: values[5]);
81: }
82:
83: public void testCreatedItems() {
84: assertEquals(6, channel.getItems().size());
85: Iterator it = channel.getItems().iterator();
86: assertNotNull("Could not get items iterator", it);
87: ItemIF item = searchForItem(channel, "Revised");
88: assertNotNull("Item not found", item);
89: assertEquals("Revised DOM Level 3 drafts", item.getTitle());
90: assertEquals("http://www.xmlhack.com/read.php?item=1612", item
91: .getLink().toString());
92: assertEquals(196, item.getDescription().length());
93: assertNotNull(item.getFound());
94: Date now = new Date();
95: assertTrue(now.after(item.getFound()));
96: }
97:
98: }
|