001: /*
002: * Bossa Workflow System
003: *
004: * $Id: BossaTestUtil.java,v 1.12 2004/03/12 19:44:38 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;
026:
027: import java.util.HashMap;
028: import java.util.List;
029:
030: import com.bigbross.bossa.resource.Resource;
031: import com.bigbross.bossa.resource.ResourceManager;
032: import com.bigbross.bossa.wfnet.CaseType;
033: import com.bigbross.bossa.wfnet.CaseTypeManager;
034: import com.bigbross.bossa.wfnet.Place;
035: import com.bigbross.bossa.wfnet.Transition;
036:
037: public class BossaTestUtil {
038:
039: public static CaseType createCaseType(String id)
040: throws BossaException {
041: return createCaseType(id, new int[] { 1, 0, 0, 0, 0, 0, 0, 0 });
042: }
043:
044: public static CaseType createCaseType(String id, int[] marking)
045: throws BossaException {
046:
047: CaseType caseType = new CaseType(id);
048:
049: Place A = caseType.registerPlace("A", marking[0]);
050: Place B = caseType.registerPlace("B", marking[1]);
051: Place C = caseType.registerPlace("C", marking[2]);
052: Place D = caseType.registerPlace("D", marking[3]);
053: Place E = caseType.registerPlace("E", marking[4]);
054: Place F = caseType.registerPlace("F", marking[5]);
055: Place G = caseType.registerPlace("G", marking[6]);
056: Place H = caseType.registerPlace("H", marking[7]);
057:
058: Transition a = caseType.registerTransition("a", "requesters");
059: Transition b = caseType.registerTransition("b", "sales-$a");
060: Transition c = caseType.registerTransition("c", "directors");
061: Transition d = caseType.registerTransition("d", "sales");
062: Transition e = caseType.registerTransition("e", "sales");
063: Transition f = caseType.registerTransition("f", "$a");
064:
065: a.input(A, "1");
066: a.output(B, "1");
067:
068: b.input(B, "1");
069: b.output(C, "!SOK");
070: b.output(D, "SOK && DIR");
071: b.output(E, "SOK && !DIR");
072:
073: c.input(D, "1");
074: c.output(B, "ADIR == 'BACK'");
075: c.output(E, "ADIR == 'OK'");
076: c.output(H, "ADIR == 'CANCEL'");
077:
078: d.input(E, "1");
079: d.output(F, "1");
080:
081: e.input(F, "1");
082: e.output(G, "1");
083:
084: f.input(C, "1");
085: f.output(B, "OK");
086: f.output(H, "!OK");
087:
088: HashMap attributes = new HashMap();
089: attributes.put("SOK", new Boolean(false));
090: attributes.put("DIR", new Boolean(false));
091: attributes.put("ADIR", "");
092: attributes.put("OK", new Boolean(false));
093:
094: caseType.buildTemplate(attributes);
095:
096: return caseType;
097: }
098:
099: public static Bossa createCompleteTestBossa() throws BossaException {
100: Bossa bossa = BossaFactory.transientBossa();
101: setupTestBossa(bossa);
102: return bossa;
103: }
104:
105: public static void setupTestBossa(Bossa bossa)
106: throws BossaException {
107: CaseTypeManager caseTypeManager = bossa.getCaseTypeManager();
108: ResourceManager resourceManager = bossa.getResourceManager();
109:
110: caseTypeManager.registerCaseType(createCaseType("test"));
111:
112: Resource frank = resourceManager.createResource("frank");
113: Resource sally = resourceManager.createResource("sally");
114: Resource jerry = resourceManager.createResource("jerry");
115:
116: List resources = caseTypeManager.getCaseType("test")
117: .getResources();
118: for (int i = 0; i < 3; i++) {
119: Resource resource = (Resource) resources.get(i);
120: if (resource.getId().equals("requesters")) {
121: resource.include(frank);
122: resource.include(sally);
123: resource.include(jerry);
124: } else if (resource.getId().equals("sales")) {
125: resource.include(frank);
126: resource.include(sally);
127: } else if (resource.getId().equals("directors")) {
128: resource.include(jerry);
129: } else {
130: throw new BossaException("This should not happen.");
131: }
132: }
133: }
134: }
|