KickJava   Java API By Example, From Geeks To Geeks.

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


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: TestFeedParser.java,v 1.1 2004/05/13 22:55:35 niko_schmuck Exp $
28

29 package de.nava.informa.parsers;
30
31 import java.io.BufferedReader JavaDoc;
32 import java.io.FileReader JavaDoc;
33 import java.net.URL JavaDoc;
34
35 import junit.framework.Test;
36 import junit.framework.TestSuite;
37
38 import org.apache.commons.logging.Log;
39 import org.apache.commons.logging.LogFactory;
40
41 import de.nava.informa.core.ChannelBuilderIF;
42 import de.nava.informa.core.ChannelIF;
43 import de.nava.informa.utils.InformaTestCase;
44
45 /**
46  * Test class which reads in a textfile (containing one URL per line)
47  * and trying to parse each one as an own test case. Expects at least
48  * one news item in each individual assertion.
49  *
50  * @author Niko Schmuck
51  */

52 public class TestFeedParser extends InformaTestCase {
53
54   private static Log logger = LogFactory.getLog(InformaTestCase.class);
55
56   private String JavaDoc testURL;
57   private ChannelBuilderIF builder;
58   
59   public TestFeedParser(String JavaDoc testMethodName, String JavaDoc testURL) {
60     super("TestFeedParser", testMethodName);
61     this.testURL = testURL;
62     this.builder = new de.nava.informa.impl.basic.ChannelBuilder();
63   }
64
65   public void testParseNewsFeedValidChannel() throws Exception JavaDoc {
66     logger.info("Reading in feed from " + testURL);
67     ChannelIF channel = FeedParser.parse(builder, new URL JavaDoc(testURL));
68     assertNotNull("Failed parsing channel " + testURL, channel.getItems());
69     assertTrue("Expected at least one item at channel " + testURL,
70                channel.getItems().size() > 0 );
71   }
72   
73   public static Test suite() throws Exception JavaDoc {
74     TestSuite suite = new TestSuite();
75     // Read in file and construct test suite
76
String JavaDoc line;
77     BufferedReader JavaDoc rdr = new BufferedReader JavaDoc(new FileReader JavaDoc(getDataDir() + FS + "newsfeeds.txt"));
78     while ((line = rdr.readLine()) != null) {
79       if (line.startsWith("#")) { // Ignore line
80
continue;
81       }
82       suite.addTest(new TestFeedParser("testParseNewsFeedValidChannel", line));
83     }
84     return suite;
85   }
86   
87 }
88
Popular Tags