001: //
002: // Informa -- RSS Library for Java
003: // Copyright (c) 2002 by Niko Schmuck
004: //
005: // Niko Schmuck
006: // http://sourceforge.net/projects/informa
007: // mailto:niko_schmuck@users.sourceforge.net
008: //
009: // This library is free software.
010: //
011: // You may redistribute it and/or modify it under the terms of the GNU
012: // Lesser General Public License as published by the Free Software Foundation.
013: //
014: // Version 2.1 of the license should be included with this distribution in
015: // the file LICENSE. If the license is not included with this distribution,
016: // you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
017: // or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
018: // MA 02139 USA.
019: //
020: // This library is distributed in the hope that it will be useful,
021: // but WITHOUT ANY WARRANTY; without even the implied waranty of
022: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
023: // Lesser General Public License for more details.
024:
025: // $Id: TestFeedManager.java,v 1.8 2006/12/04 23:43:28 italobb Exp $
026:
027: package de.nava.informa.utils;
028:
029: import java.io.File;
030: import java.util.Collection;
031: import java.util.Iterator;
032:
033: import de.nava.informa.core.ChannelIF;
034: import de.nava.informa.core.FeedIF;
035: import de.nava.informa.impl.basic.ChannelBuilder;
036: import de.nava.informa.impl.basic.Feed;
037: import de.nava.informa.parsers.FeedParser;
038: import de.nava.informa.parsers.OPMLParser;
039:
040: /**
041: * @author Jean-Guy Avelin
042: */
043: public class TestFeedManager extends InformaTestCase {
044:
045: public TestFeedManager(String name) {
046: super ("TestFeedManager", name);
047: }
048:
049: public void testaddFeed() throws Exception {
050: FeedManager FM = new FeedManager();
051:
052: File inpFile = new File(getDataDir(), "xmlhack-0.91.xml");
053: ChannelIF channel = FeedParser.parse(new ChannelBuilder(),
054: inpFile);
055: String url = new Feed(channel).getLocation().toString();
056: FeedIF feed = FM.addFeed(url);
057: assertEquals(feed, FM.addFeed(url)); // same reference
058: }
059:
060: public void testhasFeed() throws Exception {
061: FeedManager FM = new FeedManager();
062:
063: File inpFile = new File(getDataDir(), "xmlhack-0.91.xml");
064: assertFalse(FM.hasFeed(""));
065:
066: ChannelIF channel = FeedParser.parse(new ChannelBuilder(),
067: inpFile);
068:
069: String url = new Feed(channel).getLocation().toString();
070:
071: assertFalse(FM.hasFeed(url));
072:
073: FM.addFeed(url);
074: assertTrue(FM.hasFeed(url));
075: }
076:
077: public void testaddFeeds() throws Exception {
078: FeedManager FM = new FeedManager();
079:
080: File inpFile = new File(getDataDir(), "favchannels.opml");
081: String opmlUri = inpFile.toURI().toString();
082: System.err.println("parsing " + opmlUri);
083: Collection feeds = OPMLParser.parse(inpFile);
084:
085: Iterator it = feeds.iterator();
086:
087: // no feed present in FM
088: while (it.hasNext()) {
089: FeedIF opmlFeed = (FeedIF) it.next();
090: assertFalse(FM.hasFeed(opmlFeed.getLocation().toString()));
091: }
092:
093: Collection feeds2 = FM.addFeeds(opmlUri);
094: assertEquals(19, feeds2.size());
095:
096: it = feeds2.iterator();
097:
098: while (it.hasNext()) {
099: FeedIF opmlFeed = (FeedIF) it.next();
100: assertTrue(FM.hasFeed(opmlFeed.getLocation().toString()));
101: }
102:
103: // compare with collection returned by opml parser
104: it = feeds.iterator();
105: while (it.hasNext()) {
106: FeedIF opmlFeed = (FeedIF) it.next();
107: assertTrue(FM.hasFeed(opmlFeed.getLocation().toString()));
108: }
109:
110: // / just one more test ...
111: assertTrue(FM
112: .hasFeed("http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/rss091.xml"));
113: }
114:
115: }
|