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.ChannelFormat; 39 import de.nava.informa.core.ChannelIF; 40 import de.nava.informa.core.ItemIF; 41 import de.nava.informa.core.ParseException; 42 import de.nava.informa.impl.basic.ChannelBuilder; 43 import de.nava.informa.utils.InformaTestCase; 44 45 public class TestRSS_1_0_Parser extends InformaTestCase { 46 47 static ChannelIF channel; 48 static URL inpURL; 49 50 public TestRSS_1_0_Parser(String name) 51 throws IOException , ParseException { 52 53 super("TestRSS_1_0_Parser", name); 54 this.method_name = name; 55 if (channel == null) { 56 File inpFile = new File (getDataDir(), "bloggy.rdf"); 57 channel = FeedParser.parse(new ChannelBuilder(), inpFile); 58 inpURL = inpFile.toURL(); 60 } 61 } 62 63 public void testCreatedChannel() { 64 assertEquals("bloggy", channel.getTitle()); 65 assertEquals("Thoughts, rants, and photos", channel.getDescription()); 66 assertEquals(inpURL, channel.getLocation()); 67 assertEquals("http://bloggy.com/mt/", channel.getSite().toString()); 68 69 assertEquals(channel.getDescription(), channel.getElementValue("description")); 70 71 String attribute = channel.getAttributeValue("admin:generatorAgent", "rdf:resource"); 72 assertEquals("http://www.movabletype.org/?v=2.51", attribute); 73 } 74 75 public void testCreatedItems() { 76 assertEquals(15, channel.getItems().size()); 77 ItemIF item = searchForItem(channel, "We know what culture is"); 78 assertNotNull("Item not found", item); 79 assertEquals("We know what culture is, right?", item.getTitle()); 80 assertEquals("http://bloggy.com/mt/archives/000842.html", 81 item.getLink().toString()); 82 assertEquals(100, item.getDescription().length()); 83 assertEquals("War", item.getSubject()); 84 assertEquals("barry", item.getCreator()); 85 Calendar expDate = new GregorianCalendar (TimeZone.getTimeZone("GMT")); 86 expDate.set(2003, Calendar.APRIL, 1, 18, 43, 21); 87 expDate.set(Calendar.MILLISECOND, 0); 88 assertEquals(expDate.getTime(), item.getDate()); 89 } 90 91 public void testParseGoogleWeblog() throws Exception { 92 File inpFile = new File (getDataDir(), "google-weblog.rdf"); 93 ChannelIF channel_gw = FeedParser.parse(new ChannelBuilder(), inpFile); 94 assertEquals("Google Weblog", channel_gw.getTitle()); 95 assertEquals(15, channel_gw.getItems().size()); 96 assertEquals(ChannelFormat.RSS_1_0, channel_gw.getFormat()); 97 } 98 99 public void testParseW3CSynd() throws Exception { 100 File inpFile = new File (getDataDir(), "w3c-synd.rdf"); 101 ChannelIF channel_w3c = FeedParser.parse(new ChannelBuilder(), inpFile); 102 assertEquals("World Wide Web Consortium", channel_w3c.getTitle()); 103 assertEquals(7, channel_w3c.getItems().size()); 104 assertEquals(ChannelFormat.RSS_1_0, channel_w3c.getFormat()); 105 } 106 107 } 108 | Popular Tags |