KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > exporters > TestRSS_1_0_Exporter


1 //
2
// Informa -- RSS Library for Java
3
// Copyright (c) 2002 by Niko Schmuck
4
//
5
// Niko Schmuck
6
// http://sourceforge.net/projects/informa
7
// mailto:niko_schmuck@users.sourceforge.net
8
//
9
// This library is free software.
10
//
11
// You may redistribute it and/or modify it under the terms of the GNU
12
// Lesser General Public License as published by the Free Software Foundation.
13
//
14
// Version 2.1 of the license should be included with this distribution in
15
// the file LICENSE. If the license is not included with this distribution,
16
// you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
17
// or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
18
// MA 02139 USA.
19
//
20
// This library is distributed in the hope that it will be useful,
21
// but WITHOUT ANY WARRANTY; without even the implied waranty of
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
// Lesser General Public License for more details.
24
//
25

26
27 // $Id: TestRSS_1_0_Exporter.java,v 1.7 2004/05/13 22:55:18 niko_schmuck Exp $
28

29 package de.nava.informa.exporters;
30
31 import java.io.File JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.net.MalformedURLException JavaDoc;
34 import java.net.URL JavaDoc;
35 import java.util.Collection JavaDoc;
36 import java.util.Date JavaDoc;
37 import java.util.Iterator JavaDoc;
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 JavaDoc name) {
52     super("TestRSS_1_0_Exporter", name);
53   }
54
55   public void testExportChannel()
56     throws IOException JavaDoc, MalformedURLException JavaDoc, ParseException {
57
58     // TODO: refactor this into more reusable test case !!!
59

60     String JavaDoc ch_title = "The Great Demo Channel";
61     String JavaDoc ch_desc = "Just a very simple short description.";
62     
63     // create dummy channel
64
ChannelIF channel = new Channel(ch_title);
65     channel.setDescription(ch_desc);
66     channel.setSite(new URL JavaDoc("http://nava.de"));
67     channel.setLocation(new URL JavaDoc("http://nava.de/news.rdf"));
68     ItemIF itemA = new Item("Bugo", "All about it!",
69                             new URL JavaDoc("http://nava.de/huhu2002"));
70     itemA.setFound(new Date JavaDoc());
71     channel.addItem(itemA);
72     // TODO: what about markup here ???
73
ItemIF itemB = new Item("SoCool",
74                             "????**$12 @??? # <strong>should</strong> work",
75                             new URL JavaDoc("http://nava.de/very/nested/98"));
76     itemB.setFound(new Date JavaDoc());
77     channel.addItem(itemB);
78     assertEquals(2, channel.getItems().size());
79     // export this channel to file (encoding: utf-8)
80
String JavaDoc basename = "export-rss10.xml";
81     String JavaDoc exp_file = getOutputDir() + FS + basename;
82     ChannelExporterIF exporter = new RSS_1_0_Exporter(exp_file);
83     exporter.write(channel);
84
85     // clean channel object
86
channel = null;
87     
88     // read in again
89
File JavaDoc inpFile = new File JavaDoc(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 JavaDoc items = channel.getItems();
96     assertEquals(2, items.size());
97     Iterator JavaDoc 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