001: /*
002: * Bossa Workflow System
003: *
004: * $Id: TransactionsTest.java,v 1.14 2004/03/03 22:27:42 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.wfnet;
026:
027: import java.util.HashMap;
028: import java.util.Map;
029:
030: import junit.framework.TestCase;
031:
032: import com.bigbross.bossa.Bossa;
033: import com.bigbross.bossa.BossaException;
034: import com.bigbross.bossa.BossaFactory;
035: import com.bigbross.bossa.BossaTestUtil;
036: import com.bigbross.bossa.resource.Resource;
037:
038: public class TransactionsTest extends TestCase {
039:
040: private CaseTypeManager caseTypeManager;
041: private Resource jdoe;
042:
043: public TransactionsTest(String name) {
044: super (name);
045: }
046:
047: protected void setUp() throws Exception {
048: Bossa bossa = BossaFactory.transientBossa();
049: caseTypeManager = bossa.getCaseTypeManager();
050:
051: jdoe = bossa.getResourceManager().createResource("jdoe");
052:
053: caseTypeManager.registerCaseTypeImpl(BossaTestUtil
054: .createCaseType("theTestCaseType"));
055: CaseType caseType = caseTypeManager
056: .getCaseType("theTestCaseType");
057: caseType.openCaseImpl(null);
058: }
059:
060: public void testRegisterCaseType() throws Exception {
061: CaseType caseType = BossaTestUtil
062: .createCaseType("anotherTestCaseType");
063: RegisterCaseType transaction = new RegisterCaseType(caseType);
064:
065: transaction.execute(caseTypeManager);
066:
067: CaseType stored = caseTypeManager
068: .getCaseType("anotherTestCaseType");
069: assertNotNull(stored);
070: assertSame(caseType, stored);
071: }
072:
073: public void testRemoveCaseType() {
074: RemoveCaseType transaction = new RemoveCaseType(
075: "theTestCaseType");
076:
077: transaction.execute(caseTypeManager);
078:
079: assertNull(caseTypeManager.getCaseType("theTestCaseType"));
080: }
081:
082: public void testOpenWorkItem() throws Exception {
083: Case caze = caseTypeManager.getCaseType("theTestCaseType")
084: .getCase(1);
085: WorkItem wi = (WorkItem) caze.getWorkItems().get(0);
086: OpenWorkItem transaction = new OpenWorkItem(wi, jdoe);
087:
088: Activity act = (Activity) transaction.execute(caseTypeManager);
089: assertNotNull(act);
090: assertEquals(wi.getId(), act.getWorkItemId());
091:
092: Map expected = new HashMap();
093: expected.put("A", new Integer(0));
094: CaseTest.sameState(expected, caze.getState());
095: }
096:
097: public void testCloseActivity() throws Exception {
098: Case caze = caseTypeManager.getCaseType("theTestCaseType")
099: .getCase(1);
100: WorkItem wi = (WorkItem) caze.getWorkItems().get(0);
101: Activity activity = caze.open(wi, jdoe);
102: CloseActivity transaction = new CloseActivity(activity, null);
103:
104: assertEquals(1, caze.getActivities().size());
105: transaction.execute(caseTypeManager);
106: assertEquals(0, caze.getActivities().size());
107:
108: Map expected = new HashMap();
109: expected.put("B", new Integer(1));
110: CaseTest.sameState(expected, caze.getState());
111: }
112:
113: public void testCancelActivity() throws Exception {
114: Case caze = caseTypeManager.getCaseType("theTestCaseType")
115: .getCase(1);
116: WorkItem wi = (WorkItem) caze.getWorkItems().get(0);
117: Activity activity = caze.open(wi, jdoe);
118: CancelActivity transaction = new CancelActivity(activity);
119:
120: assertEquals(1, caze.getActivities().size());
121: transaction.execute(caseTypeManager);
122: assertEquals(0, caze.getActivities().size());
123:
124: Map expected = new HashMap();
125: expected.put("A", new Integer(1));
126: CaseTest.sameState(expected, caze.getState());
127: }
128:
129: public void testOpenCase() throws BossaException {
130: Map state = new HashMap();
131: state.put("A", new Integer(0));
132: state.put("B", new Integer(0));
133: state.put("C", new Integer(1));
134: state.put("D", new Integer(0));
135: state.put("E", new Integer(1));
136: state.put("F", new Integer(0));
137: state.put("G", new Integer(2));
138: state.put("H", new Integer(0));
139: OpenCase transaction = new OpenCase("theTestCaseType", state);
140:
141: Case caze = (Case) transaction.execute(caseTypeManager);
142: assertSame(caze, caseTypeManager.getCaseType("theTestCaseType")
143: .getCase(2));
144: CaseTest.sameState(state, caze.getState());
145: }
146:
147: public void testSetState() throws BossaException {
148: Case caze = caseTypeManager.getCaseType("theTestCaseType")
149: .getCase(1);
150: Map newState = new HashMap();
151: newState.put("E", new Integer(1));
152: SetState transaction = new SetState(caze, newState);
153:
154: transaction.execute(caseTypeManager);
155:
156: Map expected = new HashMap();
157: expected.put("A", new Integer(1));
158: expected.put("E", new Integer(1));
159: CaseTest.sameState(expected, caze.getState());
160: }
161:
162: public void testCloseCase() throws Exception {
163: CaseType caseType = caseTypeManager
164: .getCaseType("theTestCaseType");
165: Case caze = caseType.getCase(1);
166: CloseCase transaction = new CloseCase(caze);
167:
168: transaction.execute(caseTypeManager);
169: assertNull(caseType.getCase(1));
170: }
171: }
|