KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > util > TestCmsDateUtil


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/util/TestCmsDateUtil.java,v $
3  * Date : $Date: 2005/06/27 23:22:20 $
4  * Version: $Revision: 1.8 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.util;
33
34 import java.util.TimeZone JavaDoc;
35
36 import junit.framework.TestCase;
37
38 /**
39  * Test cases for the class "CmsDateUtil".<p>
40  *
41  * @author Alexander Kandzior
42  *
43  * @version $Revision: 1.8 $
44  *
45  * @since 6.0.0
46  */

47 public class TestCmsDateUtil extends TestCase {
48
49     /**
50      * Default JUnit constructor.<p>
51      *
52      * @param arg0 JUnit parameters
53      */

54     public TestCmsDateUtil(String JavaDoc arg0) {
55         super(arg0);
56     }
57
58     /**
59      * Tests HTTP-Header date format generation.<p>
60      *
61      * Issue:
62      * Http headers generated with bad formatting according to http spec.<p>
63      *
64      * @throws Exception if something goes wrong
65      */

66     public void testHttpDateGeneration() throws Exception JavaDoc {
67
68         String JavaDoc dateString = "Mon, 12 Jul 2004 10:00:00 GMT";
69         long dateLong = CmsDateUtil.parseHeaderDate(dateString);
70         String JavaDoc result = CmsDateUtil.getHeaderDate(dateLong);
71         assertEquals(dateString, result);
72         assertSame(CmsDateUtil.HEADER_DEFAULT.getTimeZone(), CmsDateUtil.GMT_TIMEZONE);
73     }
74     
75     /**
76      * Tests HTTP-Header time zone reuse.<p>
77      *
78      * Issue:
79      * Time zone information in static formatting objects may be changed in the application.<p>
80      *
81      * @throws Exception if something goes wrong
82      */

83     public void testHttpDateTimeZoneUsage() throws Exception JavaDoc {
84
85         TimeZone JavaDoc wrongZone = TimeZone.getTimeZone("GMT+1");
86         CmsDateUtil.HEADER_DEFAULT.setTimeZone(wrongZone);
87         
88         String JavaDoc dateString = "Mon, 12 Jul 2004 11:00:00 GMT";
89         long dateLong = CmsDateUtil.parseHeaderDate(dateString);
90         String JavaDoc result = CmsDateUtil.getHeaderDate(dateLong);
91         assertEquals(dateString, result);
92         assertSame(CmsDateUtil.HEADER_DEFAULT.getTimeZone(), CmsDateUtil.GMT_TIMEZONE);
93         
94         wrongZone = TimeZone.getTimeZone("GMT+2");
95         CmsDateUtil.HEADER_DEFAULT.setTimeZone(wrongZone);
96         
97         dateString = "Tue, 13 Jul 2004 12:00:00 GMT";
98         dateLong = CmsDateUtil.parseHeaderDate(dateString);
99         result = CmsDateUtil.getHeaderDate(dateLong);
100         assertEquals(dateString, result);
101         assertSame(CmsDateUtil.HEADER_DEFAULT.getTimeZone(), CmsDateUtil.GMT_TIMEZONE);
102     }
103 }
104
Popular Tags