001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.tools.ant.taskdefs;
019:
020: import java.util.Calendar;
021: import java.util.TimeZone;
022: import java.util.Date;
023: import java.text.SimpleDateFormat;
024:
025: import junit.framework.TestCase;
026: import org.apache.tools.ant.Project;
027: import org.apache.tools.ant.Location;
028:
029: /**
030: *
031: */
032: public class TStampTest extends TestCase {
033:
034: protected Tstamp tstamp;
035: protected Project project;
036: protected Location location;
037:
038: public TStampTest(String s) {
039: super (s);
040: }
041:
042: protected void setUp() throws Exception {
043: location = new Location("test.xml");
044: project = new Project();
045: tstamp = new Tstamp();
046: tstamp.setLocation(location);
047: tstamp.setProject(project);
048: }
049:
050: public void testTimeZone() throws Exception {
051: Tstamp.CustomFormat format = tstamp.createFormat();
052: format.setProperty("today");
053: format.setPattern("HH:mm:ss z");
054: format.setTimezone("GMT");
055: Date date = Calendar.getInstance().getTime();
056: format.execute(project, date, location);
057: String today = project.getProperty("today");
058:
059: SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss z");
060: sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
061: String expected = sdf.format(date);
062:
063: assertEquals(expected, today);
064: }
065:
066: /**
067: * verifies that custom props have priority over the
068: * originals
069: * @throws Exception
070: */
071: public void testWriteOrder() throws Exception {
072: Tstamp.CustomFormat format = tstamp.createFormat();
073: format.setProperty("TODAY");
074: format.setPattern("HH:mm:ss z");
075: format.setTimezone("GMT");
076: Date date = Calendar.getInstance().getTime();
077: format.execute(project, date, location);
078: String today = project.getProperty("TODAY");
079:
080: SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss z");
081: sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
082: String expected = sdf.format(date);
083:
084: assertEquals(expected, today);
085:
086: }
087:
088: /**
089: * verifies that custom props have priority over the
090: * originals
091: * @throws Exception
092: */
093: public void testPrefix() throws Exception {
094: tstamp.setPrefix("prefix");
095: tstamp.execute();
096: String prop = project.getProperty("prefix.DSTAMP");
097: assertNotNull(prop);
098: }
099:
100: public void testFormatPrefix() throws Exception {
101: Tstamp.CustomFormat format = tstamp.createFormat();
102: format.setProperty("format");
103: format.setPattern("HH:mm:ss z");
104: format.setTimezone("GMT");
105:
106: tstamp.setPrefix("prefix");
107: tstamp.execute();
108: String prop = project.getProperty("prefix.format");
109: assertNotNull(prop);
110: }
111:
112: }
|