KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > parsers > TestAtom_0_3_Parser


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: TestAtom_0_3_Parser.java,v 1.5 2004/06/29 11:31:10 jga Exp $
28

29 package de.nava.informa.parsers;
30
31 import java.io.File JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.util.Calendar JavaDoc;
34 import java.util.GregorianCalendar JavaDoc;
35 import java.util.TimeZone JavaDoc;
36
37 import de.nava.informa.core.ChannelFormat;
38 import de.nava.informa.core.ChannelIF;
39 import de.nava.informa.core.ParseException;
40 import de.nava.informa.impl.basic.ChannelBuilder;
41 import de.nava.informa.impl.basic.Item;
42 import de.nava.informa.utils.InformaTestCase;
43
44 public class TestAtom_0_3_Parser extends InformaTestCase {
45
46   public TestAtom_0_3_Parser(String JavaDoc name)
47     throws IOException JavaDoc, ParseException {
48
49     super("TestAtom_0_3_Parser", name);
50     this.method_name = name;
51   }
52
53   public void testParseDiveIntoMark() throws Exception JavaDoc {
54     File JavaDoc inpFile = new File JavaDoc(getDataDir(), "diveintomark.xml");
55     ChannelIF channel_mark = FeedParser.parse(new ChannelBuilder(), inpFile);
56     assertEquals("dive into mark", channel_mark.getTitle());
57     assertEquals(3, channel_mark.getItems().size());
58     
59     // test generator
60
assertEquals("Movable Type", channel_mark.getGenerator());
61     
62     //test publisher
63
assertEquals("Mark Pilgrim", channel_mark.getCreator());
64     
65     //test Last pub date
66
// should be <modified>2004-05-13T17:16:00Z</modified>
67
Calendar JavaDoc updtDate = new GregorianCalendar JavaDoc(TimeZone.getTimeZone("GMT"));
68
69     updtDate.set(Calendar.YEAR, 2004);
70     updtDate.set(Calendar.MONTH, Calendar.MAY);
71     updtDate.set(Calendar.DAY_OF_MONTH, 13);
72     updtDate.set(Calendar.HOUR_OF_DAY, 17);
73     updtDate.set(Calendar.MINUTE, 16);
74     updtDate.set(Calendar.SECOND, 00);
75     updtDate.set(Calendar.MILLISECOND, 0);
76     assertEquals(updtDate.getTime(), channel_mark.getPubDate());
77     
78     //test build date
79

80     // test site url
81
assertNotNull(channel_mark.getSite());
82     assertEquals("http://diveintomark.org/",channel_mark.getSite().toExternalForm());
83     
84     // test link for first item
85
java.util.Iterator JavaDoc itemsColl = channel_mark.getItems().iterator();
86     Item item = (Item) itemsColl.next();
87     assertEquals("http://diveintomark.org/archives/2004/05/12/copy-editor".trim(),item.getLink().toExternalForm());
88      
89     assertEquals(ChannelFormat.ATOM_0_3, channel_mark.getFormat());
90   }
91
92   public void testEntryTitleFormat() throws Exception JavaDoc {
93     File JavaDoc inpFile = new File JavaDoc(getDataDir(), "blink.xml");
94     ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile);
95     java.util.Iterator JavaDoc itemsColl = channel.getItems().iterator();
96     // skip first entry
97
itemsColl.next();
98     while( itemsColl.hasNext() ) {
99       Item item = (Item) itemsColl.next();
100       //System.out.println("TC title :*"+item.getTitle()+"*"+item.getTitle().length());
101
assertEquals("History of the <blink> tag",item.getTitle());
102     }
103     }
104   
105   public void testLanguage() throws Exception JavaDoc {
106     File JavaDoc inpFile = new File JavaDoc(getDataDir(), "diveintomark.xml");
107     ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile);
108     
109     assertEquals("en",channel.getLanguage());
110  
111     }
112
113   public void testCopyright() throws Exception JavaDoc {
114     File JavaDoc inpFile = new File JavaDoc(getDataDir(), "multilink-linkblog.xml");
115     ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile);
116     
117     // test copyright text/plain
118
assertEquals("Copyright (c) 2004 Mark Pilgrim", channel.getCopyright());
119     
120     inpFile = new File JavaDoc(getDataDir(), "diveintomark.xml");
121     channel = FeedParser.parse(new ChannelBuilder(), inpFile);
122     assertEquals("Copyright 2004, Mark Pilgrim", channel.getCopyright());
123  
124     }
125 }
126
Popular Tags