1 26 27 29 package de.nava.informa.exporters; 30 31 import java.io.File ; 32 import java.io.IOException ; 33 import java.net.MalformedURLException ; 34 import java.net.URL ; 35 import java.util.Collection ; 36 import java.util.Date ; 37 import java.util.Iterator ; 38 39 import de.nava.informa.core.ChannelExporterIF; 40 import de.nava.informa.core.ChannelIF; 41 import de.nava.informa.core.ItemIF; 42 import de.nava.informa.core.ParseException; 43 import de.nava.informa.impl.basic.Channel; 44 import de.nava.informa.impl.basic.ChannelBuilder; 45 import de.nava.informa.impl.basic.Item; 46 import de.nava.informa.parsers.FeedParser; 47 import de.nava.informa.utils.InformaTestCase; 48 49 public class TestRSS_1_0_Exporter extends InformaTestCase { 50 51 public TestRSS_1_0_Exporter(String name) { 52 super("TestRSS_1_0_Exporter", name); 53 } 54 55 public void testExportChannel() 56 throws IOException , MalformedURLException , ParseException { 57 58 60 String ch_title = "The Great Demo Channel"; 61 String ch_desc = "Just a very simple short description."; 62 63 ChannelIF channel = new Channel(ch_title); 65 channel.setDescription(ch_desc); 66 channel.setSite(new URL ("http://nava.de")); 67 channel.setLocation(new URL ("http://nava.de/news.rdf")); 68 ItemIF itemA = new Item("Bugo", "All about it!", 69 new URL ("http://nava.de/huhu2002")); 70 itemA.setFound(new Date ()); 71 channel.addItem(itemA); 72 ItemIF itemB = new Item("SoCool", 74 "????**$12 @??? # <strong>should</strong> work", 75 new URL ("http://nava.de/very/nested/98")); 76 itemB.setFound(new Date ()); 77 channel.addItem(itemB); 78 assertEquals(2, channel.getItems().size()); 79 String basename = "export-rss10.xml"; 81 String exp_file = getOutputDir() + FS + basename; 82 ChannelExporterIF exporter = new RSS_1_0_Exporter(exp_file); 83 exporter.write(channel); 84 85 channel = null; 87 88 File inpFile = new File (exp_file); 90 channel = FeedParser.parse(new ChannelBuilder(), inpFile); 91 92 assertEquals(ch_title, channel.getTitle()); 93 assertEquals(ch_desc, channel.getDescription()); 94 95 Collection items = channel.getItems(); 96 assertEquals(2, items.size()); 97 Iterator it = items.iterator(); 98 ItemIF item = (ItemIF) it.next(); 99 if (item.equals(itemA)) { 100 assertEquals(item, itemA); 101 item = (ItemIF) it.next(); 102 assertEquals(item, itemB); 103 } else { 104 assertEquals(item, itemB); 105 item = (ItemIF) it.next(); 106 assertEquals(item, itemA); 107 } 108 } 109 110 } 111 | Popular Tags |