KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > utils > TestParserUtils


1 //
2
// Informa -- RSS Library for Java
3
// Copyright (c) 2002-2003 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: TestParserUtils.java,v 1.5 2004/06/28 12:54:14 jga Exp $
28

29 package de.nava.informa.utils;
30
31 import java.util.Calendar JavaDoc;
32 import java.util.Date JavaDoc;
33 import java.util.GregorianCalendar JavaDoc;
34 import java.util.TimeZone JavaDoc;
35
36 public class TestParserUtils extends InformaTestCase {
37   
38   public TestParserUtils(String JavaDoc name) {
39     super("TestParserUtils", name);
40   }
41   
42   public void testParseDateFmt() {
43     String JavaDoc strdate = "Wed, 07 Aug 2002 00:32:05 GMT";
44     Date JavaDoc resDate = ParserUtils.getDate(strdate);
45
46    
47     Calendar JavaDoc expDate = new GregorianCalendar JavaDoc(TimeZone.getTimeZone("GMT"));
48     expDate.set(2002, Calendar.AUGUST, 7, 0, 32, 5);
49     expDate.set(Calendar.MILLISECOND, 0);
50     
51     assertEquals(expDate.getTime(), resDate);
52     
53     strdate = "2002-08-07T15:32:05-0500 ";
54     resDate = ParserUtils.getDate(strdate);
55
56     expDate = new GregorianCalendar JavaDoc(TimeZone.getTimeZone("GMT"));
57     expDate.set(2002, Calendar.AUGUST, 7, 20, 32, 5);
58     expDate.set(Calendar.MILLISECOND, 0);
59     assertEquals(expDate.getTime(), resDate);
60
61     strdate = "2002-08-07T15:32:05-05:00 ";
62     resDate = ParserUtils.getDate(strdate);
63     expDate = new GregorianCalendar JavaDoc(TimeZone.getTimeZone("GMT"));
64     expDate.set(2002, Calendar.AUGUST, 7, 20, 32, 5);
65     expDate.set(Calendar.MILLISECOND, 0);
66     assertEquals(expDate.getTime(), resDate);
67  
68     strdate = "2002-08-07T12:32:05+03:00 ";
69     resDate = ParserUtils.getDate(strdate);
70     expDate = new GregorianCalendar JavaDoc(TimeZone.getTimeZone("GMT"));
71     expDate.set(2002, Calendar.AUGUST, 7, 9, 32, 5);
72     expDate.set(Calendar.MILLISECOND, 0);
73     assertEquals(expDate.getTime(), resDate);
74     
75     strdate = "2002-08-07T12:32:05 GMT";
76     resDate = ParserUtils.getDate(strdate);
77     expDate = new GregorianCalendar JavaDoc(TimeZone.getTimeZone("GMT"));
78     expDate.set(2002, Calendar.AUGUST, 7, 12, 32, 5);
79     expDate.set(Calendar.MILLISECOND, 0);
80     assertEquals(expDate.getTime(), resDate);
81     
82     strdate = "2002-08-07T12:32:05 RET";
83     resDate = ParserUtils.getDate(strdate);
84     expDate = new GregorianCalendar JavaDoc(TimeZone.getTimeZone("GMT"));
85     expDate.set(2002, Calendar.AUGUST, 7, 8, 32, 5); // Reunion Time = GMT+4
86
expDate.set(Calendar.MILLISECOND, 0);
87     assertEquals(expDate.getTime(), resDate);
88     
89     strdate = "2002-08-07T12:32:05Z";
90     resDate = ParserUtils.getDate(strdate);
91     expDate = new GregorianCalendar JavaDoc(TimeZone.getTimeZone("GMT"));
92     expDate.set(2002, Calendar.AUGUST, 7, 12, 32, 5);
93     expDate.set(Calendar.MILLISECOND, 0);
94     assertEquals(expDate.getTime(), resDate);
95     
96     strdate = "2002-08-07T12:32:05+3:00 ";
97     resDate = ParserUtils.getDate(strdate);
98     expDate = new GregorianCalendar JavaDoc(TimeZone.getTimeZone("GMT"));
99     expDate.set(2002, Calendar.AUGUST, 7, 9, 32, 5);
100     expDate.set(Calendar.MILLISECOND, 0);
101     assertEquals(expDate.getTime(), resDate);
102     
103     strdate = "2002-08-07T06:32:05-3:00 ";
104     resDate = ParserUtils.getDate(strdate);
105     expDate = new GregorianCalendar JavaDoc(TimeZone.getTimeZone("GMT"));
106     expDate.set(2002, Calendar.AUGUST, 7, 9, 32, 5);
107     expDate.set(Calendar.MILLISECOND, 0);
108     assertEquals(expDate.getTime(), resDate);
109   
110     strdate = "2002-08-07T12:32:05GMT-02:00";
111     resDate = ParserUtils.getDate(strdate);
112     expDate = new GregorianCalendar JavaDoc(TimeZone.getTimeZone("GMT"));
113     expDate.set(2002, Calendar.AUGUST, 7, 14, 32, 5);
114     expDate.set(Calendar.MILLISECOND, 0);
115     assertEquals(expDate.getTime(), resDate);
116    }
117
118   public void testUnescape() {
119     String JavaDoc testString = "> > " < '";
120     //System.err.println(" decoded version = "+ParserUtils.unEscape(testString));
121
assertEquals("&gt; > \" < '", ParserUtils.unEscape(testString) );
122   }
123 }
124
Popular Tags