KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > exporters > TestRSS_0_91_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_0_91_Exporter.java,v 1.11 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_0_91_Exporter extends InformaTestCase {
50
51   public TestRSS_0_91_Exporter(String JavaDoc name) {
52     super("TestRSS_0_91_Exporter", name);
53   }
54
55   public void testExportChannel()
56     throws IOException JavaDoc, MalformedURLException JavaDoc, ParseException {
57
58     String JavaDoc ch_title = "The Great Demo Channel";
59     String JavaDoc ch_desc = "Just a very simple short description.";
60     
61     // create dummy channel
62
ChannelIF channel = new Channel(ch_title);
63     channel.setDescription(ch_desc);
64     channel.setSite(new URL JavaDoc("http://nava.de"));
65     ItemIF itemA = new Item("Bugo", "All about it!",
66                             new URL JavaDoc("http://nava.de/huhu2002"));
67     itemA.setFound(new Date JavaDoc());
68     channel.addItem(itemA);
69     // TODO: what about markup here ???
70
ItemIF itemB = new Item("SoCool",
71                             "????**$12 @??? # <strong>should</strong> work",
72                             new URL JavaDoc("http://nava.de/very/nested/98"));
73     itemB.setFound(new Date JavaDoc());
74     channel.addItem(itemB);
75     assertEquals(2, channel.getItems().size());
76     // export this channel to file (encoding: utf-8)
77
String JavaDoc basename = "export-rss091.xml";
78     String JavaDoc exp_file = getOutputDir() + FS + basename;
79     ChannelExporterIF exporter = new RSS_0_91_Exporter(exp_file);
80     exporter.write(channel);
81
82     // clean channel object
83
channel = null;
84     
85     // read in again
86
File JavaDoc inpFile = new File JavaDoc(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 JavaDoc items = channel.getItems();
93     assertEquals(2, items.size());
94     Iterator JavaDoc 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