001: /*
002: * Copyright (C) 1999-2005 <a href="mailto:paschke@in.tum.de">Adrian Paschke</a>
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package test.org.mandarax.lib.date;
020:
021: import org.mandarax.kernel.InferenceEngine;
022: import org.mandarax.kernel.KnowledgeBase;
023: import org.mandarax.lib.date.SimpleDate;
024: import java.util.Calendar;
025: import java.util.TimeZone;
026:
027: import junit.framework.TestCase;
028:
029: /**
030: * Test case for SimpleDates. Time zones are testet in synchronized and not synchronized mode.
031: * @author <A HREF="mailto:paschke@in.tum.de">Adrian Paschke</A>
032: * @version 3.4 <7 March 05>
033: * @since 3.3.1
034: */
035:
036: public class TestSimpleDate extends DateTestCase {
037:
038: private Calendar t1;
039: private Calendar t2;
040: private Calendar t3;
041:
042: /**
043: * Constructor.
044: * @param testName the name of the test
045: */
046: public TestSimpleDate(String testName) {
047: super (testName);
048:
049: }
050:
051: /**
052: * set up fixtures
053: */
054: protected void setUp() {
055: t1 = new SimpleDate();
056: TimeZone tz = TimeZone.getTimeZone("Europe/Berlin");
057: t1.setTimeZone(tz);
058:
059: }
060:
061: /**
062: * Test case 1: Synchronized with different time zones
063: * @throws an exception (indicating that the test case has failed)
064: */
065: public void simpleDateTest1() throws Exception {
066: Calendar t = (SimpleDate) t1.clone();
067: TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
068: t.setTimeZone(tz);
069: if (t.equals(t1))
070: assertTrue(true);
071: else
072: assertTrue(t + " is not equal " + t1, false);
073: }
074:
075: /**
076: * Test case 2: Not synchronized with different time zones
077: * @throws an exception (indicating that the test case has failed)
078: */
079: public void simpleDateTest2() throws Exception {
080: SimpleDate t = (SimpleDate) t1.clone();
081: t.setSynchronized(false);
082: TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
083: t.setTimeZone(tz);
084: if (!t.equals(t1))
085: assertTrue(true);
086: else
087: assertTrue(t + " is equal " + t1, false);
088: }
089:
090: /**
091: * Test case 3: Not synchronized with different time zones and the same absolute time
092: * @throws an exception (indicating that the test case has failed)
093: */
094: public void simpleDateTest3() throws Exception {
095: SimpleDate t = (SimpleDate) t1.clone();
096: t.setSynchronized(false);
097: TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
098: t.setTimeZone(tz);
099: t.add(Calendar.MILLISECOND, +3600000);
100: t.add(Calendar.MILLISECOND, +28800000);
101: if (t.equals(t1))
102: assertTrue(true);
103: else
104: assertTrue(t + " is not equal " + t1, false);
105: }
106:
107: /**
108: * Test case 4: Synchronized with different time zones
109: * @throws an exception (indicating that the test case has failed)
110: */
111: public void simpleDateTest4() throws Exception {
112: Calendar t = (SimpleDate) t1.clone();
113: TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
114: t.setTimeZone(tz);
115: t.add(Calendar.MINUTE, 1);
116: if (t.after(t1))
117: assertTrue(true);
118: else
119: assertTrue(t + " is not after " + t1, false);
120: }
121:
122: /**
123: * Test case 5: Synchronized with different time zones
124: * @throws an exception (indicating that the test case has failed)
125: */
126: public void simpleDateTest5() throws Exception {
127: Calendar t = (SimpleDate) t1.clone();
128: TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
129: t.setTimeZone(tz);
130: t.add(Calendar.MINUTE, 1);
131: if (t1.before(t))
132: assertTrue(true);
133: else
134: assertTrue(t1 + " is not before " + t, false);
135: }
136:
137: /**
138: * Test case 6: Not synchronized with different time zones
139: * @throws an exception (indicating that the test case has failed)
140: */
141: public void simpleDateTest6() throws Exception {
142: SimpleDate t = (SimpleDate) t1.clone();
143: t.setSynchronized(false);
144: TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
145: t.setTimeZone(tz);
146: if (t.before(t1))
147: assertTrue(true);
148: else
149: assertTrue(t + " is not before " + t1, false);
150: }
151:
152: /**
153: * Test case 7: Not synchronized with different time zones
154: * @throws an exception (indicating that the test case has failed)
155: */
156: public void simpleDateTest7() throws Exception {
157: SimpleDate t = (SimpleDate) t1.clone();
158: t.setSynchronized(false);
159: TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
160: t.setTimeZone(tz);
161: if (t1.after(t))
162: assertTrue(true);
163: else
164: assertTrue(t1 + " is not after " + t, false);
165: }
166:
167: }
|