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 import java.util.List ; 39 40 import de.nava.informa.core.*; 41 import de.nava.informa.impl.basic.Channel; 42 import de.nava.informa.impl.basic.ChannelBuilder; 43 import de.nava.informa.impl.basic.Item; 44 import de.nava.informa.parsers.FeedParser; 45 import de.nava.informa.utils.InformaTestCase; 46 import junit.framework.TestSuite; 47 import junit.framework.Test; 48 import junit.textui.TestRunner; 49 50 public class TestRSS_2_0_Exporter extends InformaTestCase { 51 52 public TestRSS_2_0_Exporter(String name) { 53 super("TestRSS_2_0_Exporter", name); 54 } 55 56 public void testExportChannel() 57 throws IOException , MalformedURLException , ParseException { 58 59 String ch_title = "The Great Demo Channel"; 60 String ch_desc = "Just a very simple short description."; 61 62 ChannelBuilder builder = new ChannelBuilder(); 63 64 ChannelIF channel = new Channel(ch_title); 66 channel.setDescription(ch_desc); 67 channel.setSite(new URL ("http://nava.de")); 68 ItemIF itemA = new Item("Bugo", "All about it!", 69 new URL ("http://nava.de/huhu2002")); 70 itemA.setFound(new Date ()); 71 CategoryIF cat1 = builder.createCategory(null, "cat1"); 72 CategoryIF cat1a = builder.createCategory(cat1, "cat1a"); 73 CategoryIF cat1aa = builder.createCategory(cat1a, "cat1aa"); 74 CategoryIF cat1ab = builder.createCategory(cat1a, "cat1ab"); 75 CategoryIF cat1aba = builder.createCategory(cat1ab, "cat1aba"); 76 CategoryIF cat1abb = builder.createCategory(cat1ab, "cat1abb"); 77 CategoryIF cat1ac = builder.createCategory(cat1a, "cat1ac"); 78 CategoryIF cat1b = builder.createCategory(cat1, "cat1b"); 79 CategoryIF cat1c = builder.createCategory(cat1, "cat1c"); 80 CategoryIF cat1ca = builder.createCategory(cat1c, "cat1ca"); 81 CategoryIF cat2 = builder.createCategory(null, "cat2"); 82 itemA.addCategory(cat1); 83 itemA.addCategory(cat2); 84 assertEquals(2, itemA.getCategories().size()); 85 channel.addItem(itemA); 86 ItemIF itemB = new Item("SoCool", 88 "????**$12 @??? # <strong>should</strong> work", 89 new URL ("http://nava.de/very/nested/98")); 90 itemB.setFound(new Date ()); 91 CategoryIF catX = builder.createCategory(null, "catX"); 92 CategoryIF catXa = builder.createCategory(catX, "catXa"); 93 itemB.addCategory(catX); 94 assertEquals(1, itemB.getCategories().size()); 95 channel.addItem(itemB); 96 assertEquals(2, channel.getItems().size()); 97 String basename = "export-rss20.xml"; 99 String exp_file = getOutputDir() + FS + basename; 100 ChannelExporterIF exporter = new RSS_2_0_Exporter(exp_file); 101 exporter.write(channel); 102 103 channel = null; 105 106 File inpFile = new File (exp_file); 108 channel = FeedParser.parse(new ChannelBuilder(), inpFile); 109 110 assertEquals(ch_title, channel.getTitle()); 111 assertEquals(ch_desc, channel.getDescription()); 112 113 Collection items = channel.getItems(); 114 assertEquals(2, items.size()); 115 Iterator it = items.iterator(); 116 ItemIF item = (ItemIF) it.next(); 117 if (item.equals(itemA)) { 118 assertEquals(item, itemA); 119 120 List catList = (List )item.getCategories(); 122 assertEquals(catList.size(), 2); 123 Iterator itCat = catList.iterator(); 124 CategoryIF cat = (CategoryIF)itCat.next(); 125 if (cat.equals(cat1)) { 126 assertEquals(cat.getTitle(), cat1.getTitle()); 127 } 128 else { 129 assertEquals(cat.getTitle(), cat2.getTitle()); 130 } 131 132 item = (ItemIF) it.next(); 133 assertEquals(item, itemB); 134 } else { 135 assertEquals(item, itemB); 136 137 List catList = (List )item.getCategories(); 139 assertEquals(catList.size(), 1); 140 Iterator itCat = catList.iterator(); 141 CategoryIF cat = (CategoryIF)itCat.next(); 142 assertEquals(cat.getTitle(), catX.getTitle()); 143 144 item = (ItemIF) it.next(); 145 assertEquals(item, itemA); 146 } 147 } 148 149 public static Test suite() { 150 TestSuite suite = new TestSuite(); 151 suite.addTest(new TestSuite(TestRSS_2_0_Exporter.class)); 152 return suite; 153 } 154 155 public static void main(String [] args) { 156 TestRunner.run(suite()); 157 } 158 159 } 160 | Popular Tags |