1 26 27 29 package de.nava.informa.parsers; 30 31 import java.io.File ; 32 import java.io.IOException ; 33 import java.net.URL ; 34 import java.util.Calendar ; 35 import java.util.GregorianCalendar ; 36 import java.util.TimeZone ; 37 38 import de.nava.informa.core.*; 39 import de.nava.informa.impl.basic.ChannelBuilder; 40 import de.nava.informa.utils.InformaTestCase; 41 42 public class TestRSS_2_0_Parser extends InformaTestCase { 43 44 static ChannelIF channel; 45 static URL inpURL; 46 47 public TestRSS_2_0_Parser(String name) 48 throws IOException , ParseException { 49 50 super("TestRSS_2_0_Parser", name); 51 if (channel == null) { 52 File inpFile = new File (getDataDir(), "informa-projnews.xml"); 53 channel = FeedParser.parse(new ChannelBuilder(), inpFile); 54 inpURL = inpFile.toURL(); 56 } 57 } 58 59 public void testCreatedChannel() { 60 assertEquals("SourceForge.net: SF.net Project News: RSS Library for Java", 61 channel.getTitle()); 62 assertEquals(313, channel.getDescription().length()); 63 assertEquals(inpURL, channel.getLocation()); 64 assertEquals("http://sourceforge.net/projects/informa/", 65 channel.getSite().toString()); 66 assertEquals(ChannelFormat.RSS_2_0, channel.getFormat()); 67 } 68 69 public void testItemDetails() { 70 assertEquals(5, channel.getItems().size()); 71 ItemIF item = searchForItem(channel, "First alpha release of Informa"); 72 assertNotNull("Item not found", item); 73 assertEquals("First alpha release of Informa is now out", item.getTitle()); 74 assertEquals("http://sourceforge.net/forum/forum.php?forum_id=200619", 75 item.getLink().toString()); 76 assertEquals(121, item.getDescription().length()); 77 Calendar expDate = new GregorianCalendar (TimeZone.getTimeZone("GMT")); 78 expDate.set(2002, Calendar.AUGUST, 7, 0, 32, 5); 79 expDate.set(Calendar.MILLISECOND, 0); 80 assertEquals(expDate.getTime(), item.getDate()); 81 } 82 83 public void testParseW3CSynd() throws Exception { 84 File inpFile = new File (getDataDir(), "msdn-rss2.xml"); 85 ChannelIF channel_msdn = FeedParser.parse(new ChannelBuilder(), inpFile); 86 assertEquals("MSDN Just Published", channel_msdn.getTitle()); 87 assertEquals(63, channel_msdn.getItems().size()); 88 assertEquals(ChannelFormat.RSS_2_0, channel_msdn.getFormat()); 89 } 90 91 public void testParseYahooBusiness() throws Exception { 92 File inpFile = new File (getDataDir(), "business.rss"); 93 ChannelIF channel_business = FeedParser.parse(new ChannelBuilder(), inpFile); 94 assertEquals("Yahoo! News - Business", channel_business.getTitle()); 95 assertEquals("http://news.yahoo.com/news?tmpl=index&cid=1885", 96 channel_business.getSite().toString()); 97 assertEquals(11, channel_business.getItems().size()); 98 assertEquals(ChannelFormat.RSS_2_0, channel_business.getFormat()); 99 ItemIF item = searchForItem(channel_business, "Taking the World by Hand (Forbes.com)"); 100 assertNotNull("Item not found", item); 101 } 102 103 public void testParseWithDefaultNS() throws Exception { 104 File inpFile = new File (getDataDir(), "rss2withNS.xml"); 105 ChannelIF channel_wns = FeedParser.parse(new ChannelBuilder(), inpFile); 106 assertEquals("Blogging Roller", channel_wns.getTitle()); 107 assertEquals(15, channel_wns.getItems().size()); 108 assertEquals(ChannelFormat.RSS_2_0, channel_wns.getFormat()); 109 assertEquals(((CategoryIF)((ItemIF)channel_wns.getItems().toArray()[0]).getCategories().toArray()[0]).getTitle(), "Roller"); 110 } 111 112 } 113 | Popular Tags |