001: /*
002: * Bossa Workflow System
003: *
004: * $Id: HistorianTest.java,v 1.8 2004/02/24 19:20:00 gdvieira Exp $
005: *
006: * Copyright (C) 2003,2004 OpenBR Sistemas S/C Ltda.
007: *
008: * This file is part of Bossa.
009: *
010: * Bossa is free software; you can redistribute it and/or modify it
011: * under the terms of version 2 of the GNU General Public License as
012: * published by the Free Software Foundation.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public
020: * License along with this program; if not, write to the
021: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
022: * Boston, MA 02111-1307, USA.
023: */
024:
025: package com.bigbross.bossa.history;
026:
027: import java.util.Date;
028: import java.util.HashMap;
029: import java.util.List;
030:
031: import junit.framework.TestCase;
032:
033: import com.bigbross.bossa.notify.Event;
034: import com.bigbross.bossa.resource.ResourceEvents;
035: import com.bigbross.bossa.wfnet.WFNetEvents;
036:
037: public class HistorianTest extends TestCase {
038:
039: private Historian historian;
040: private Event e0, e1, e2, e3;
041: public static final long t1 = 1069364322000L;
042: public static final long t2 = 1069365822000L;
043: public static final long t3 = 1069366362000L;
044: public static final long t4 = 1069367322000L;
045:
046: public HistorianTest(String name) {
047: super (name);
048: }
049:
050: protected void setUp() {
051: historian = new Historian(null);
052: HashMap attributes = new HashMap();
053: attributes.put(WFNetEvents.ATTRIB_CASE_TYPE_ID, "casetype1");
054: attributes.put(WFNetEvents.ATTRIB_CASE_ID, "1");
055: attributes.put(WFNetEvents.ATTRIB_RESOURCE_ID, "resource1");
056: Date aTime = new Date();
057: aTime.setTime(t1);
058: e0 = new Event("teste0", Event.WFNET_EVENT, attributes, aTime);
059: attributes = new HashMap();
060: attributes.put(WFNetEvents.ATTRIB_CASE_TYPE_ID, "casetype2");
061: attributes.put(WFNetEvents.ATTRIB_CASE_ID, "1");
062: attributes.put(WFNetEvents.ATTRIB_RESOURCE_ID, "resource2");
063: aTime = new Date();
064: aTime.setTime(t2);
065: e1 = new Event("teste1", Event.WFNET_EVENT, attributes, aTime);
066: attributes = new HashMap();
067: attributes.put(ResourceEvents.ATTRIB_HOST_RESOURCE_ID,
068: "hostresource");
069: attributes.put(ResourceEvents.ATTRIB_RESOURCE_ID, "resource1");
070: aTime = new Date();
071: aTime.setTime(t3);
072: e2 = new Event("teste2", Event.RESOURCE_EVENT, attributes,
073: aTime);
074: attributes = new HashMap();
075: attributes.put(WFNetEvents.ATTRIB_CASE_TYPE_ID, "casetype1");
076: attributes.put(WFNetEvents.ATTRIB_CASE_ID, "2");
077: attributes.put(WFNetEvents.ATTRIB_RESOURCE_ID, "resource3");
078: aTime = new Date();
079: aTime.setTime(t4);
080: e3 = new Event("teste3", Event.WFNET_EVENT, attributes, aTime);
081: }
082:
083: public void testNewEvents() {
084: historian.newEvent(e0);
085: historian.newEvent(e1);
086: historian.newEvent(e2);
087: historian.newEvent(e3);
088:
089: List events = historian.getHistory();
090: assertEquals(4, events.size());
091: assertSame(e0, events.get(0));
092: assertSame(e1, events.get(1));
093: assertSame(e2, events.get(2));
094: assertSame(e3, events.get(3));
095: }
096:
097: public void testOutOfOrderEvents() {
098: historian.newEvent(e0);
099: historian.newEvent(e2);
100: historian.newEvent(e3);
101: historian.newEvent(e1);
102:
103: List events = historian.getHistory();
104: assertEquals(4, events.size());
105: assertSame(e0, events.get(0));
106: assertSame(e1, events.get(1));
107: assertSame(e2, events.get(2));
108: assertSame(e3, events.get(3));
109: }
110:
111: public void testOpenRange() {
112: historian.newEvent(e0);
113: historian.newEvent(e1);
114: historian.newEvent(e2);
115: historian.newEvent(e3);
116:
117: Date start = new Date();
118: start.setTime(t3);
119:
120: List events = historian.getHistory(start);
121: assertEquals(2, events.size());
122: assertSame(e2, events.get(0));
123: assertSame(e3, events.get(1));
124: }
125:
126: public void testClosedRange() {
127: historian.newEvent(e0);
128: historian.newEvent(e1);
129: historian.newEvent(e2);
130: historian.newEvent(e3);
131:
132: Date start = new Date();
133: start.setTime(t2);
134: Date end = new Date();
135: end.setTime(t4);
136:
137: List events = historian.getHistory(start, end);
138: assertEquals(2, events.size());
139: assertSame(e1, events.get(0));
140: assertSame(e2, events.get(1));
141:
142: assertEquals(0, historian.getHistory(end, start).size());
143: }
144:
145: public void testCaseTypeHistory() {
146: historian.newEvent(e0);
147: historian.newEvent(e1);
148: historian.newEvent(e2);
149: historian.newEvent(e3);
150:
151: List events = historian.getCaseTypeHistory("casetype1");
152: assertEquals(2, events.size());
153: assertSame(e0, events.get(0));
154: assertSame(e3, events.get(1));
155:
156: assertEquals(0, historian.getCaseTypeHistory("foo").size());
157: }
158:
159: public void testCaseHistory() {
160: historian.newEvent(e0);
161: historian.newEvent(e1);
162: historian.newEvent(e2);
163: historian.newEvent(e3);
164:
165: List events = historian.getCaseHistory("casetype1", 2);
166: assertEquals(1, events.size());
167: assertSame(e3, events.get(0));
168:
169: assertEquals(0, historian.getCaseHistory("casetype1", 4).size());
170: }
171:
172: public void testResourceHistory() {
173: historian.newEvent(e0);
174: historian.newEvent(e1);
175: historian.newEvent(e2);
176: historian.newEvent(e3);
177:
178: List events = historian.getResourceHistory("resource1");
179: assertEquals(2, events.size());
180: assertSame(e0, events.get(0));
181: assertSame(e2, events.get(1));
182:
183: assertEquals(0, historian.getCaseTypeHistory("bar").size());
184: }
185:
186: public void testPurgeHistory() {
187: historian.newEvent(e0);
188: historian.newEvent(e1);
189: historian.newEvent(e2);
190: historian.newEvent(e3);
191:
192: Date end = new Date();
193: end.setTime(t3);
194:
195: historian.purgeHistoryImpl(end);
196: List events = historian.getHistory();
197: assertEquals(2, events.size());
198: assertSame(e2, events.get(0));
199: assertSame(e3, events.get(1));
200:
201: end.setTime(0);
202: historian.purgeHistoryImpl(end);
203: events = historian.getHistory();
204: assertEquals(2, events.size());
205:
206: end = new Date();
207: historian.purgeHistoryImpl(end);
208: events = historian.getHistory();
209: assertEquals(0, events.size());
210: }
211: }
|