001: /*
002: * Bossa Workflow System
003: *
004: * $Id: EventsNotificationTest.java,v 1.16 2004/02/11 21:42:47 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.notify;
026:
027: import java.util.HashMap;
028: import java.util.List;
029: import java.util.Map;
030:
031: import junit.framework.TestCase;
032:
033: import com.bigbross.bossa.Bossa;
034: import com.bigbross.bossa.BossaException;
035: import com.bigbross.bossa.BossaTestUtil;
036: import com.bigbross.bossa.resource.Resource;
037: import com.bigbross.bossa.resource.ResourceEvents;
038: import com.bigbross.bossa.resource.ResourceManager;
039: import com.bigbross.bossa.wfnet.Activity;
040: import com.bigbross.bossa.wfnet.Case;
041: import com.bigbross.bossa.wfnet.CaseTypeManager;
042: import com.bigbross.bossa.wfnet.WFNetEvents;
043: import com.bigbross.bossa.wfnet.WorkItem;
044: import com.bigbross.bossa.work.WorkManager;
045:
046: public class EventsNotificationTest extends TestCase {
047:
048: private CaseTypeManager caseTypeManager;
049: private ResourceManager resourceManager;
050: private WorkManager workManager;
051: private Resource frank, sally;
052: private MemoryListener listener;
053:
054: public EventsNotificationTest(String name) {
055: super (name);
056: }
057:
058: protected void setUp() throws Exception {
059: Bossa bossa = BossaTestUtil.createCompleteTestBossa();
060: caseTypeManager = bossa.getCaseTypeManager();
061: resourceManager = bossa.getResourceManager();
062: frank = resourceManager.getResource("frank");
063: sally = resourceManager.getResource("sally");
064: workManager = bossa.getWorkManager();
065:
066: listener = new MemoryListener("test", 0, null);
067: bossa.getNotificationBus().registerListener(listener);
068: }
069:
070: public void testLogRegisterRemoveCaseType() throws Exception {
071: String caseTypeId = "created";
072: caseTypeManager.registerCaseType(BossaTestUtil
073: .createCaseType(caseTypeId));
074: caseTypeManager.removeCaseType(caseTypeId);
075:
076: List events = listener.getNotifications();
077: assertEquals(2, events.size());
078: Event event = (Event) events.get(0);
079: assertEquals(Event.WFNET_EVENT, event.getType());
080: assertEquals(WFNetEvents.ID_REGISTER_CASE_TYPE, event.getId());
081: assertEquals(caseTypeId, event.getAttributes().get(
082: WFNetEvents.ATTRIB_CASE_TYPE_ID));
083: event = (Event) events.get(1);
084: assertEquals(Event.WFNET_EVENT, event.getType());
085: assertEquals(WFNetEvents.ID_REMOVE_CASE_TYPE, event.getId());
086: assertEquals(caseTypeId, event.getAttributes().get(
087: WFNetEvents.ATTRIB_CASE_TYPE_ID));
088: }
089:
090: public void testLogOpenCase() throws Exception {
091: WorkItem wi = (WorkItem) workManager.getWorkItems(frank, true)
092: .get(0);
093: Activity act = wi.open(frank);
094:
095: List events = listener.getNotifications();
096: Event event = (Event) events.get(0);
097: assertEquals(Event.WFNET_EVENT, event.getType());
098: assertEquals(WFNetEvents.ID_OPEN_CASE, event.getId());
099: assertEquals(Integer.toString(act.getCase().getId()), event
100: .getAttributes().get(WFNetEvents.ATTRIB_CASE_ID));
101: assertEquals(wi.getCaseType().getId(), event.getAttributes()
102: .get(WFNetEvents.ATTRIB_CASE_TYPE_ID));
103: }
104:
105: public void testLogCloseCase() throws Exception {
106: WorkItem wi = (WorkItem) workManager.getWorkItems(frank, true)
107: .get(0);
108: wi.open(frank).close();
109: wi = (WorkItem) workManager.getWorkItems(sally).get(0);
110: wi.open(sally).close();
111: wi = (WorkItem) workManager.getWorkItems(frank).get(0);
112: wi.open(frank).close();
113:
114: List events = listener.getNotifications();
115: Event event = (Event) events.get(events.size() - 1);
116: assertEquals(Event.WFNET_EVENT, event.getType());
117: assertEquals(WFNetEvents.ID_CLOSE_CASE, event.getId());
118: assertEquals(Integer.toString(wi.getCase().getId()), event
119: .getAttributes().get(WFNetEvents.ATTRIB_CASE_ID));
120: assertEquals(wi.getCaseType().getId(), event.getAttributes()
121: .get(WFNetEvents.ATTRIB_CASE_TYPE_ID));
122: }
123:
124: public void testLogOpenWorkItem() throws Exception {
125: WorkItem wi = (WorkItem) workManager.getWorkItems(frank, true)
126: .get(0);
127: Activity act = wi.open(frank);
128:
129: List events = listener.getNotifications();
130: Event event = (Event) events.get(events.size() - 1);
131: assertEquals(Event.WFNET_EVENT, event.getType());
132: assertEquals(WFNetEvents.ID_OPEN_WORK_ITEM, event.getId());
133: assertEquals(wi.getId(), event.getAttributes().get(
134: WFNetEvents.ATTRIB_WORK_ITEM_ID));
135: assertEquals(Integer.toString(act.getCase().getId()), event
136: .getAttributes().get(WFNetEvents.ATTRIB_CASE_ID));
137: assertEquals(wi.getCaseType().getId(), event.getAttributes()
138: .get(WFNetEvents.ATTRIB_CASE_TYPE_ID));
139: assertEquals(frank.getId(), event.getAttributes().get(
140: WFNetEvents.ATTRIB_RESOURCE_ID));
141: }
142:
143: public void testLogCloseActivity() throws Exception {
144: WorkItem wi = (WorkItem) workManager.getWorkItems(frank, true)
145: .get(0);
146: Activity act = wi.open(frank);
147: act.close();
148:
149: List events = listener.getNotifications();
150: Event event = (Event) events.get(events.size() - 1);
151: assertEquals(Event.WFNET_EVENT, event.getType());
152: assertEquals(WFNetEvents.ID_CLOSE_ACTIVITY, event.getId());
153: assertEquals(Integer.toString(act.getId()), event
154: .getAttributes().get(WFNetEvents.ATTRIB_ACTIVITY_ID));
155: assertEquals(act.getWorkItemId(), event.getAttributes().get(
156: WFNetEvents.ATTRIB_ACTIVITY_WI_ID));
157: assertEquals(Integer.toString(act.getCase().getId()), event
158: .getAttributes().get(WFNetEvents.ATTRIB_CASE_ID));
159: assertEquals(act.getCaseType().getId(), event.getAttributes()
160: .get(WFNetEvents.ATTRIB_CASE_TYPE_ID));
161: assertEquals(frank.getId(), event.getAttributes().get(
162: WFNetEvents.ATTRIB_RESOURCE_ID));
163: }
164:
165: public void testLogCancelActivity() throws Exception {
166: WorkItem wi = (WorkItem) workManager.getWorkItems(frank, true)
167: .get(0);
168: Activity act = wi.open(frank);
169: act.cancel();
170:
171: List events = listener.getNotifications();
172: Event event = (Event) events.get(events.size() - 1);
173: assertEquals(Event.WFNET_EVENT, event.getType());
174: assertEquals(WFNetEvents.ID_CANCEL_ACTIVITY, event.getId());
175: assertEquals(Integer.toString(act.getId()), event
176: .getAttributes().get(WFNetEvents.ATTRIB_ACTIVITY_ID));
177: assertEquals(act.getWorkItemId(), event.getAttributes().get(
178: WFNetEvents.ATTRIB_ACTIVITY_WI_ID));
179: assertEquals(Integer.toString(act.getCase().getId()), event
180: .getAttributes().get(WFNetEvents.ATTRIB_CASE_ID));
181: assertEquals(act.getCaseType().getId(), event.getAttributes()
182: .get(WFNetEvents.ATTRIB_CASE_TYPE_ID));
183: assertEquals(frank.getId(), event.getAttributes().get(
184: WFNetEvents.ATTRIB_RESOURCE_ID));
185: }
186:
187: public void testLogTokenOpenClose() throws Exception {
188: WorkItem wi = (WorkItem) workManager.getWorkItems(frank, true)
189: .get(0);
190: Activity act = wi.open(frank);
191: act.close();
192:
193: List events = listener.getNotifications();
194: Event event = (Event) events.get(events.size() - 3);
195: assertEquals(Event.WFNET_EVENT, event.getType());
196: assertEquals(WFNetEvents.ID_ADD_TOKENS, event.getId());
197: assertEquals("B", event.getAttributes().get(
198: WFNetEvents.ATTRIB_PLACE_ID));
199: assertEquals("1", event.getAttributes().get(
200: WFNetEvents.ATTRIB_TOKEN_NUMBER_ID));
201: assertEquals(Integer.toString(act.getCase().getId()), event
202: .getAttributes().get(WFNetEvents.ATTRIB_CASE_ID));
203: assertEquals(wi.getCaseType().getId(), event.getAttributes()
204: .get(WFNetEvents.ATTRIB_CASE_TYPE_ID));
205: event = (Event) events.get(events.size() - 6);
206: assertEquals(Event.WFNET_EVENT, event.getType());
207: assertEquals(WFNetEvents.ID_REMOVE_TOKENS, event.getId());
208: assertEquals("A", event.getAttributes().get(
209: WFNetEvents.ATTRIB_PLACE_ID));
210: assertEquals("1", event.getAttributes().get(
211: WFNetEvents.ATTRIB_TOKEN_NUMBER_ID));
212: assertEquals(Integer.toString(act.getCase().getId()), event
213: .getAttributes().get(WFNetEvents.ATTRIB_CASE_ID));
214: assertEquals(wi.getCaseType().getId(), event.getAttributes()
215: .get(WFNetEvents.ATTRIB_CASE_TYPE_ID));
216: }
217:
218: public void testLogTokenCancel() throws Exception {
219: WorkItem wi = (WorkItem) workManager.getWorkItems(frank, true)
220: .get(0);
221: Activity act = wi.open(frank);
222: act.cancel();
223:
224: List events = listener.getNotifications();
225: Event event = (Event) events.get(events.size() - 3);
226: assertEquals(Event.WFNET_EVENT, event.getType());
227: assertEquals(WFNetEvents.ID_ADD_TOKENS, event.getId());
228: assertEquals("A", event.getAttributes().get(
229: WFNetEvents.ATTRIB_PLACE_ID));
230: assertEquals("1", event.getAttributes().get(
231: WFNetEvents.ATTRIB_TOKEN_NUMBER_ID));
232: assertEquals(Integer.toString(act.getCase().getId()), event
233: .getAttributes().get(WFNetEvents.ATTRIB_CASE_ID));
234: assertEquals(wi.getCaseType().getId(), event.getAttributes()
235: .get(WFNetEvents.ATTRIB_CASE_TYPE_ID));
236: }
237:
238: public void testLogZeroTokens() throws Exception {
239: WorkItem wi = (WorkItem) workManager.getWorkItems(frank, true)
240: .get(0);
241: wi.open(frank).close();
242: wi = (WorkItem) workManager.getWorkItems(sally).get(0);
243: wi.open(sally).close();
244:
245: List events = listener.getNotifications();
246: Event event = (Event) events.get(events.size() - 3);
247: assertEquals(WFNetEvents.ID_ADD_TOKENS, event.getId());
248: event = (Event) events.get(events.size() - 4);
249: assertEquals(WFNetEvents.ID_OPEN_WORK_ITEM, event.getId());
250: }
251:
252: public void testLogActivate() throws Exception {
253: WorkItem wi = (WorkItem) workManager.getWorkItems(frank, true)
254: .get(0);
255: Activity act = wi.open(frank);
256: act.cancel();
257:
258: List events = listener.getNotifications();
259: Event event = (Event) events.get(events.size() - 2);
260: assertEquals(Event.WFNET_EVENT, event.getType());
261: assertEquals(WFNetEvents.ID_WORK_ITEM_ACTIVE, event.getId());
262: assertEquals(wi.getId(), event.getAttributes().get(
263: WFNetEvents.ATTRIB_WORK_ITEM_ID));
264: assertEquals(Integer.toString(act.getCase().getId()), event
265: .getAttributes().get(WFNetEvents.ATTRIB_CASE_ID));
266: assertEquals(wi.getCaseType().getId(), event.getAttributes()
267: .get(WFNetEvents.ATTRIB_CASE_TYPE_ID));
268: }
269:
270: public void testLogDeactivate() throws Exception {
271: WorkItem wi = (WorkItem) workManager.getWorkItems(frank, true)
272: .get(0);
273: Activity act = wi.open(frank);
274:
275: List events = listener.getNotifications();
276: Event event = (Event) events.get(events.size() - 2);
277: assertEquals(Event.WFNET_EVENT, event.getType());
278: assertEquals(WFNetEvents.ID_WORK_ITEM_INACTIVE, event.getId());
279: assertEquals(wi.getId(), event.getAttributes().get(
280: WFNetEvents.ATTRIB_WORK_ITEM_ID));
281: assertEquals(Integer.toString(act.getCase().getId()), event
282: .getAttributes().get(WFNetEvents.ATTRIB_CASE_ID));
283: assertEquals(wi.getCaseType().getId(), event.getAttributes()
284: .get(WFNetEvents.ATTRIB_CASE_TYPE_ID));
285: }
286:
287: public void testSetState() throws BossaException {
288: WorkItem wi = (WorkItem) workManager.getWorkItems(frank, true)
289: .get(0);
290: Activity act = wi.open(frank);
291: act.close();
292: Case caze = act.getCase();
293: Map newState = new HashMap();
294: newState.put("B", new Integer(0));
295: newState.put("E", new Integer(1));
296: caze.setState(newState);
297:
298: List events = listener.getNotifications();
299: Event event = (Event) events.get(events.size() - 5);
300: assertEquals(Event.WFNET_EVENT, event.getType());
301: assertEquals(WFNetEvents.ID_SET_TOKENS, event.getId());
302: String placeId = (String) event.getAttributes().get(
303: WFNetEvents.ATTRIB_PLACE_ID);
304: if ("B".equals(placeId)) {
305: assertEquals("0", event.getAttributes().get(
306: WFNetEvents.ATTRIB_TOKEN_NUMBER_ID));
307: } else if ("E".equals(placeId)) {
308: assertEquals("1", event.getAttributes().get(
309: WFNetEvents.ATTRIB_TOKEN_NUMBER_ID));
310: } else {
311: fail();
312: }
313: assertEquals(Integer.toString(caze.getId()), event
314: .getAttributes().get(WFNetEvents.ATTRIB_CASE_ID));
315: assertEquals(caze.getCaseType().getId(), event.getAttributes()
316: .get(WFNetEvents.ATTRIB_CASE_TYPE_ID));
317:
318: event = (Event) events.get(events.size() - 4);
319: assertEquals(Event.WFNET_EVENT, event.getType());
320: assertEquals(WFNetEvents.ID_SET_TOKENS, event.getId());
321:
322: event = (Event) events.get(events.size() - 3);
323: assertEquals(Event.WFNET_EVENT, event.getType());
324: assertEquals(WFNetEvents.ID_WORK_ITEM_INACTIVE, event.getId());
325:
326: event = (Event) events.get(events.size() - 2);
327: assertEquals(Event.WFNET_EVENT, event.getType());
328: assertEquals(WFNetEvents.ID_WORK_ITEM_ACTIVE, event.getId());
329:
330: event = (Event) events.get(events.size() - 1);
331: assertEquals(Event.WFNET_EVENT, event.getType());
332: assertEquals(WFNetEvents.ID_SET_STATE, event.getId());
333: assertEquals(Integer.toString(caze.getId()), event
334: .getAttributes().get(WFNetEvents.ATTRIB_CASE_ID));
335: assertEquals(caze.getCaseType().getId(), event.getAttributes()
336: .get(WFNetEvents.ATTRIB_CASE_TYPE_ID));
337: }
338:
339: public void testLogCreateRemoveResource() throws Exception {
340: Resource joe = resourceManager.createResource("joedoe");
341: resourceManager.removeResource(joe);
342:
343: List events = listener.getNotifications();
344: assertEquals(2, events.size());
345: Event event = (Event) events.get(0);
346: assertEquals(Event.RESOURCE_EVENT, event.getType());
347: assertEquals(ResourceEvents.ID_CREATE_RESOURCE, event.getId());
348: assertEquals(joe.getId(), event.getAttributes().get(
349: ResourceEvents.ATTRIB_RESOURCE_ID));
350: event = (Event) events.get(1);
351: assertEquals(Event.RESOURCE_EVENT, event.getType());
352: assertEquals(ResourceEvents.ID_REMOVE_RESOURCE, event.getId());
353: assertEquals(joe.getId(), event.getAttributes().get(
354: ResourceEvents.ATTRIB_RESOURCE_ID));
355: }
356:
357: public void testLogIncludeInResource() throws Exception {
358: frank.include(sally);
359:
360: List events = listener.getNotifications();
361: assertEquals(1, events.size());
362: Event event = (Event) events.get(0);
363: assertEquals(Event.RESOURCE_EVENT, event.getType());
364: assertEquals(ResourceEvents.ID_INCLUDE_IN_RESOURCE, event
365: .getId());
366: assertEquals(sally.getId(), event.getAttributes().get(
367: ResourceEvents.ATTRIB_RESOURCE_ID));
368: assertEquals(frank.getId(), event.getAttributes().get(
369: ResourceEvents.ATTRIB_HOST_RESOURCE_ID));
370: }
371:
372: public void testLogExcludeInResource() throws Exception {
373: frank.exclude(sally);
374:
375: List events = listener.getNotifications();
376: assertEquals(1, events.size());
377: Event event = (Event) events.get(0);
378: assertEquals(Event.RESOURCE_EVENT, event.getType());
379: assertEquals(ResourceEvents.ID_EXCLUDE_IN_RESOURCE, event
380: .getId());
381: assertEquals(sally.getId(), event.getAttributes().get(
382: ResourceEvents.ATTRIB_RESOURCE_ID));
383: assertEquals(frank.getId(), event.getAttributes().get(
384: ResourceEvents.ATTRIB_HOST_RESOURCE_ID));
385: }
386:
387: public void testLogRemoveFromResource() throws Exception {
388: frank.include(sally);
389: frank.remove(sally);
390:
391: List events = listener.getNotifications();
392: assertEquals(2, events.size());
393: Event event = (Event) events.get(1);
394: assertEquals(Event.RESOURCE_EVENT, event.getType());
395: assertEquals(ResourceEvents.ID_REMOVE_FROM_RESOURCE, event
396: .getId());
397: assertEquals(sally.getId(), event.getAttributes().get(
398: ResourceEvents.ATTRIB_RESOURCE_ID));
399: assertEquals(frank.getId(), event.getAttributes().get(
400: ResourceEvents.ATTRIB_HOST_RESOURCE_ID));
401: }
402: }
|