KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > TStampTest


1 /*
2  * Copyright 2001-2002,2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package org.apache.tools.ant.taskdefs;
18
19 import java.util.Calendar JavaDoc;
20 import java.util.TimeZone JavaDoc;
21 import java.util.Date JavaDoc;
22 import java.text.SimpleDateFormat JavaDoc;
23
24 import junit.framework.TestCase;
25 import org.apache.tools.ant.Project;
26 import org.apache.tools.ant.Location;
27
28 /**
29  *
30  */

31 public class TStampTest extends TestCase {
32
33     protected Tstamp tstamp;
34     protected Project project;
35     protected Location location;
36
37     public TStampTest(String JavaDoc s) {
38         super(s);
39     }
40
41     protected void setUp() throws Exception JavaDoc {
42         location = new Location("test.xml");
43         project = new Project();
44         tstamp = new Tstamp();
45         tstamp.setLocation(location);
46         tstamp.setProject(project);
47     }
48
49     public void testTimeZone() throws Exception JavaDoc {
50         Tstamp.CustomFormat format = tstamp.createFormat();
51         format.setProperty("today");
52         format.setPattern("HH:mm:ss z");
53         format.setTimezone("GMT");
54         Date JavaDoc date = Calendar.getInstance().getTime();
55         format.execute(project, date, location);
56         String JavaDoc today = project.getProperty("today");
57
58         SimpleDateFormat JavaDoc sdf = new SimpleDateFormat JavaDoc("HH:mm:ss z");
59         sdf.setTimeZone( TimeZone.getTimeZone("GMT") );
60         String JavaDoc expected = sdf.format(date);
61
62         assertEquals(expected, today);
63     }
64
65     /**
66      * verifies that custom props have priority over the
67      * originals
68      * @throws Exception
69      */

70     public void testWriteOrder() throws Exception JavaDoc {
71         Tstamp.CustomFormat format = tstamp.createFormat();
72         format.setProperty("TODAY");
73         format.setPattern("HH:mm:ss z");
74         format.setTimezone("GMT");
75         Date JavaDoc date = Calendar.getInstance().getTime();
76         format.execute(project, date, location);
77         String JavaDoc today = project.getProperty("TODAY");
78
79         SimpleDateFormat JavaDoc sdf = new SimpleDateFormat JavaDoc("HH:mm:ss z");
80         sdf.setTimeZone( TimeZone.getTimeZone("GMT") );
81         String JavaDoc expected = sdf.format(date);
82
83         assertEquals(expected, today);
84
85     }
86
87     /**
88      * verifies that custom props have priority over the
89      * originals
90      * @throws Exception
91      */

92     public void testPrefix() throws Exception JavaDoc {
93         tstamp.setPrefix("prefix");
94         tstamp.execute();
95         String JavaDoc prop= project.getProperty("prefix.DSTAMP");
96         assertNotNull(prop);
97     }
98
99     public void testFormatPrefix() throws Exception JavaDoc {
100     Tstamp.CustomFormat format = tstamp.createFormat();
101         format.setProperty("format");
102         format.setPattern("HH:mm:ss z");
103         format.setTimezone("GMT");
104
105         tstamp.setPrefix("prefix");
106         tstamp.execute();
107         String JavaDoc prop= project.getProperty("prefix.format");
108         assertNotNull(prop);
109     }
110
111 }
112
Popular Tags