KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > parsers > TestRSS_0_91_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_0_91_Parser.java,v 1.14 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.Date JavaDoc;
35 import java.util.Iterator JavaDoc;
36
37 import de.nava.informa.core.ChannelFormat;
38 import de.nava.informa.core.ChannelIF;
39 import de.nava.informa.core.ItemIF;
40 import de.nava.informa.core.ParseException;
41 import de.nava.informa.impl.basic.ChannelBuilder;
42 import de.nava.informa.utils.InformaTestCase;
43
44 public class TestRSS_0_91_Parser extends InformaTestCase {
45
46   static ChannelIF channel;
47   static URL JavaDoc inpURL;
48
49   public TestRSS_0_91_Parser(String JavaDoc name)
50     throws IOException JavaDoc, ParseException {
51
52     super("TestRSS_0_91_Parser", name);
53     if (channel == null) {
54       File JavaDoc inpFile = new File JavaDoc(getDataDir(), "xmlhack-0.91.xml");
55       channel = FeedParser.parse(new ChannelBuilder(), inpFile);
56       // for later reference
57
inpURL = inpFile.toURL();
58     }
59   }
60
61   public void testCreatedChannel() {
62     assertEquals("xmlhack", channel.getTitle());
63     assertEquals("Developer news from the XML community",
64                  channel.getDescription());
65     assertEquals(inpURL, channel.getLocation());
66     assertEquals("http://www.xmlhack.com", channel.getSite().toString());
67     assertEquals(ChannelFormat.RSS_0_91, channel.getFormat());
68
69     String JavaDoc[] elements = {"title", "url", "link", "width", "height", "description"};
70     String JavaDoc[] values = channel.getElementValues("image", elements);
71     assertEquals("xmlhack", values[0]);
72     assertEquals("http://www.xmlhack.com/images/mynetscape88.gif", values[1]);
73     assertEquals("http://www.xmlhack.com", values[2]);
74     assertEquals("88", values[3]);
75     assertEquals("31", values[4]);
76     assertEquals("News, opinions, tips and issues concerning XML development", values[5]);
77   }
78
79   public void testCreatedItems() {
80     assertEquals(6, channel.getItems().size());
81     Iterator JavaDoc it = channel.getItems().iterator();
82     ItemIF item = searchForItem(channel, "Revised");
83     assertNotNull("Item not found", item);
84     assertEquals("Revised DOM Level 3 drafts", item.getTitle());
85     assertEquals("http://www.xmlhack.com/read.php?item=1612",
86                  item.getLink().toString());
87     assertEquals(196, item.getDescription().length());
88     assertNotNull(item.getFound());
89     Date JavaDoc now = new Date JavaDoc();
90     assertTrue(now.after(item.getFound()));
91   }
92
93 }
94
Popular Tags