1 25 26 28 package de.nava.informa.utils; 29 30 import java.io.File ; 31 32 import java.util.Collection ; 33 import java.util.Iterator ; 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 49 public class TestFeedManager extends InformaTestCase { 50 51 public TestFeedManager(String name) { 52 super("TestFeedManager", name); 53 } 54 55 public void testaddFeed() { 56 FeedManager FM = new FeedManager(); 57 58 File inpFile = new File (getDataDir(), "xmlhack-0.91.xml"); 59 try { 60 ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile); 61 String url = new Feed(channel).getLocation().toString(); 62 FeedIF feed = FM.addFeed(url); 63 assertEquals(feed, FM.addFeed(url)); } catch (Exception 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 inpFile = new File (getDataDir(), "xmlhack-0.91.xml"); 74 try { 75 assertFalse( FM.hasFeed("") ); 76 77 ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile); 78 79 String 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 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 inpFile = new File (getDataDir(), "favchannels.opml"); 96 try { 97 String opmlUri = "file://"+inpFile.toString(); 98 System.err.println("parsing "+opmlUri); 99 Collection feeds = OPMLParser.parse(inpFile); 100 101 Iterator it = feeds.iterator(); 102 103 while ( it.hasNext() ) { 105 FeedIF opmlFeed = (FeedIF) it.next(); 106 assertFalse( FM.hasFeed( opmlFeed.getLocation().toString() )); 107 } 108 109 Collection 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 it = feeds.iterator(); 121 while ( it.hasNext() ) { 122 FeedIF opmlFeed = (FeedIF) it.next(); 123 assertTrue( FM.hasFeed( opmlFeed.getLocation().toString() ) ); 124 } 125 126 assertTrue( FM.hasFeed("http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/rss091.xml")); 128 129 } catch (Exception 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 |