KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > utils > TestFeedManager


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 // $Id: TestFeedManager.java,v 1.5 2004/10/14 23:16:38 niko_schmuck Exp $
27

28 package de.nava.informa.utils;
29
30 import java.io.File JavaDoc;
31
32 import java.util.Collection JavaDoc;
33 import java.util.Iterator JavaDoc;
34
35 import junit.framework.AssertionFailedError;
36
37 import de.nava.informa.core.ChannelIF;
38 import de.nava.informa.impl.basic.ChannelBuilder;
39 import de.nava.informa.impl.basic.Feed;
40 import de.nava.informa.parsers.FeedParser;
41 import de.nava.informa.parsers.OPMLParser;
42 import de.nava.informa.core.FeedIF;
43 import de.nava.informa.utils.InformaTestCase;
44
45
46 /**
47  * @author Jean-Guy Avelin
48  */

49 public class TestFeedManager extends InformaTestCase {
50
51   public TestFeedManager(String JavaDoc name) {
52     super("TestFeedManager", name);
53   }
54   
55   public void testaddFeed() {
56     FeedManager FM = new FeedManager();
57
58     File JavaDoc inpFile = new File JavaDoc(getDataDir(), "xmlhack-0.91.xml");
59     try {
60       ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile);
61       String JavaDoc url = new Feed(channel).getLocation().toString();
62       FeedIF feed = FM.addFeed(url);
63       assertEquals(feed, FM.addFeed(url)); //same reference
64
} catch (Exception JavaDoc e) {
65       System.err.println("testaddFeed error " + e);
66       throw new AssertionFailedError("testaddFeed error " + e);
67     }
68   }
69   
70   public void testhasFeed() {
71     FeedManager FM = new FeedManager();
72
73      File JavaDoc inpFile = new File JavaDoc(getDataDir(), "xmlhack-0.91.xml");
74      try {
75     assertFalse( FM.hasFeed("") );
76     
77     ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile);
78     
79     String JavaDoc url = new Feed(channel).getLocation().toString();
80     
81     assertFalse( FM.hasFeed(url) );
82     
83     FM.addFeed(url);
84     assertTrue( FM.hasFeed(url) );
85     
86      } catch (Exception JavaDoc e) {
87     System.err.println("testhasFeed error " + e);
88     throw new AssertionFailedError("testhasFeed error " + e);
89      }
90   }
91    
92   public void testaddFeeds() {
93     FeedManager FM = new FeedManager();
94
95     File JavaDoc inpFile = new File JavaDoc(getDataDir(), "favchannels.opml");
96     try {
97       String JavaDoc opmlUri = "file://"+inpFile.toString();
98       System.err.println("parsing "+opmlUri);
99       Collection JavaDoc feeds = OPMLParser.parse(inpFile);
100       
101       Iterator JavaDoc it = feeds.iterator();
102       
103       // no feed present in FM
104
while ( it.hasNext() ) {
105         FeedIF opmlFeed = (FeedIF) it.next();
106         assertFalse( FM.hasFeed( opmlFeed.getLocation().toString() ));
107       }
108       
109       Collection JavaDoc feeds2 = FM.addFeeds(opmlUri);
110       assertEquals(25, feeds2.size());
111       
112       it = feeds2.iterator();
113       
114       while ( it.hasNext() ) {
115         FeedIF opmlFeed = (FeedIF) it.next();
116         assertTrue( FM.hasFeed( opmlFeed.getLocation().toString() ) );
117       }
118       
119       // compare with collection returned by opml parser
120
it = feeds.iterator();
121       while ( it.hasNext() ) {
122         FeedIF opmlFeed = (FeedIF) it.next();
123         assertTrue( FM.hasFeed( opmlFeed.getLocation().toString() ) );
124       }
125       
126       /// just one more test ...
127
assertTrue( FM.hasFeed("http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/rss091.xml"));
128       
129     } catch (Exception JavaDoc e) {
130       System.err.println("testaddFeeds error " + e);
131       e.printStackTrace();
132       throw new AssertionFailedError("testaddFeeds error " + e);
133     }
134   }
135
136 }
137
Popular Tags