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_0_91_Exporter extends InformaTestCase { 50 51 public TestRSS_0_91_Exporter(String name) { 52 super("TestRSS_0_91_Exporter", name); 53 } 54 55 public void testExportChannel() 56 throws IOException , MalformedURLException , ParseException { 57 58 String ch_title = "The Great Demo Channel"; 59 String ch_desc = "Just a very simple short description."; 60 61 ChannelIF channel = new Channel(ch_title); 63 channel.setDescription(ch_desc); 64 channel.setSite(new URL ("http://nava.de")); 65 ItemIF itemA = new Item("Bugo", "All about it!", 66 new URL ("http://nava.de/huhu2002")); 67 itemA.setFound(new Date ()); 68 channel.addItem(itemA); 69 ItemIF itemB = new Item("SoCool", 71 "????**$12 @??? # <strong>should</strong> work", 72 new URL ("http://nava.de/very/nested/98")); 73 itemB.setFound(new Date ()); 74 channel.addItem(itemB); 75 assertEquals(2, channel.getItems().size()); 76 String basename = "export-rss091.xml"; 78 String exp_file = getOutputDir() + FS + basename; 79 ChannelExporterIF exporter = new RSS_0_91_Exporter(exp_file); 80 exporter.write(channel); 81 82 channel = null; 84 85 File inpFile = new File (exp_file); 87 channel = FeedParser.parse(new ChannelBuilder(), inpFile); 88 89 assertEquals(ch_title, channel.getTitle()); 90 assertEquals(ch_desc, channel.getDescription()); 91 92 Collection items = channel.getItems(); 93 assertEquals(2, items.size()); 94 Iterator it = items.iterator(); 95 ItemIF item = (ItemIF) it.next(); 96 if (item.equals(itemA)) { 97 assertEquals(item, itemA); 98 item = (ItemIF) it.next(); 99 assertEquals(item, itemB); 100 } else { 101 assertEquals(item, itemB); 102 item = (ItemIF) it.next(); 103 assertEquals(item, itemA); 104 } 105 } 106 107 } 108 | Popular Tags |