01: /*
02: * Bossa Workflow System
03: *
04: * $Id: TimeSourceTest.java,v 1.2 2003/12/01 21:00:39 gdvieira Exp $
05: *
06: * Copyright (C) 2003 OpenBR Sistemas S/C Ltda.
07: *
08: * This file is part of Bossa.
09: *
10: * Bossa is free software; you can redistribute it and/or modify it
11: * under the terms of version 2 of the GNU General Public License as
12: * published by the Free Software Foundation.
13: *
14: * This program is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17: * General Public License for more details.
18: *
19: * You should have received a copy of the GNU General Public
20: * License along with this program; if not, write to the
21: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22: * Boston, MA 02111-1307, USA.
23: */
24:
25: package com.bigbross.bossa;
26:
27: import java.util.Date;
28:
29: import junit.framework.TestCase;
30:
31: import com.bigbross.bossa.history.Historian;
32: import com.bigbross.bossa.notify.Event;
33: import com.bigbross.bossa.wfnet.CaseTypeManager;
34:
35: public class TimeSourceTest extends TestCase {
36:
37: private Date d1, d2;
38: private DeterministicTimeSource source;
39:
40: public TimeSourceTest(String name) {
41: super (name);
42: }
43:
44: protected void setUp() {
45: d1 = new Date(1069365822000L);
46: d2 = new Date(1069365933000L);
47: source = new DeterministicTimeSource();
48: }
49:
50: public void testSource() {
51: assertNull(source.getTime());
52: source.setTime(d1);
53: assertEquals(d1, source.getTime());
54: source.setTime(d2);
55: assertEquals(d2, source.getTime());
56: assertEquals(d2, source.getTime());
57: }
58:
59: public void testConstantTime() {
60: source.setTime(d2);
61: assertEquals(d2, source.getTime());
62: d1 = (Date) d2.clone();
63: d2.setTime(1069365967000L);
64: assertEquals(d1, source.getTime());
65: }
66:
67: public void testExternalTimeSource() throws Exception {
68: BossaFactory factory = new BossaFactory();
69: factory.setTransientBossa(true);
70: factory.setTimeSource(source);
71: Bossa bossa = factory.createBossa();
72: CaseTypeManager caseTypeManager = bossa.getCaseTypeManager();
73: Historian historian = bossa.getHistorian();
74:
75: source.setTime(d1);
76: caseTypeManager.registerCaseType(BossaTestUtil
77: .createCaseType("foo"));
78: assertEquals(d1, ((Event) historian.getHistory().get(0))
79: .getTime());
80: source.setTime(d2);
81: caseTypeManager.registerCaseType(BossaTestUtil
82: .createCaseType("bar"));
83: assertEquals(d2, ((Event) historian.getHistory().get(1))
84: .getTime());
85: }
86: }
|