001: /*
002: * Bossa Workflow System
003: *
004: * $Id: TransactionsTest.java,v 1.9 2004/01/30 22:45:50 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.resource;
026:
027: import junit.framework.TestCase;
028:
029: import com.bigbross.bossa.Bossa;
030: import com.bigbross.bossa.BossaFactory;
031: import com.bigbross.bossa.BossaTestUtil;
032: import com.bigbross.bossa.wfnet.CaseTypeManager;
033:
034: public class TransactionsTest extends TestCase {
035:
036: private ResourceManager resourceManager;
037:
038: public TransactionsTest(String name) {
039: super (name);
040: }
041:
042: protected void setUp() {
043: resourceManager = new ResourceManager();
044: }
045:
046: public void testCreateResource() {
047: CreateResource transaction = new CreateResource("joe");
048: Resource resource = (Resource) transaction
049: .execute(resourceManager);
050: assertSame(resource, resourceManager.getResource("joe"));
051: }
052:
053: public void testRemoveResource() {
054: Resource resource = resourceManager.createResourceImpl("joe",
055: false);
056: assertNotNull(resource);
057:
058: RemoveResource transaction = new RemoveResource(resource);
059: assertTrue(((Boolean) transaction.execute(resourceManager))
060: .booleanValue());
061: assertNull(resourceManager.getResource("joe"));
062: }
063:
064: public void testIncludeInResource() throws Exception {
065: Resource group = resourceManager.createResourceImpl("trumps",
066: false);
067: Resource element = resourceManager.createResourceImpl("joe",
068: false);
069:
070: IncludeInResource transaction = new IncludeInResource(group,
071: element);
072: assertTrue(((Boolean) transaction.execute(resourceManager))
073: .booleanValue());
074: assertTrue(group.contains(element));
075: }
076:
077: public void testIncludeInCaseTypeResource() throws Exception {
078: Bossa bossa = BossaFactory.transientBossa();
079: CaseTypeManager caseTypeManager = bossa.getCaseTypeManager();
080: caseTypeManager.registerCaseType(BossaTestUtil
081: .createCaseType("test"));
082: ResourceManager myResourceManager = bossa.getResourceManager();
083:
084: Resource group = (Resource) caseTypeManager.getCaseType("test")
085: .getResources().get(0);
086: Resource element = myResourceManager.createResourceImpl("joe",
087: false);
088:
089: IncludeInResource transaction = new IncludeInResource(group,
090: element);
091: assertTrue(((Boolean) transaction.execute(myResourceManager))
092: .booleanValue());
093: assertTrue(group.contains(element));
094: }
095:
096: public void testExcludeInResource() throws Exception {
097: Resource group1 = resourceManager.createResourceImpl("trumps",
098: false);
099: Resource group2 = resourceManager.createResourceImpl("good",
100: false);
101: Resource element = resourceManager.createResourceImpl("joe",
102: false);
103: group1.includeImpl(group2, false);
104: group2.includeImpl(element, false);
105: assertTrue(group1.contains(element));
106:
107: ExcludeInResource transaction = new ExcludeInResource(group1,
108: element);
109: assertTrue(((Boolean) transaction.execute(resourceManager))
110: .booleanValue());
111: assertFalse(group1.contains(element));
112: }
113:
114: public void testExcludeInCaseTypeResource() throws Exception {
115: Bossa bossa = BossaFactory.transientBossa();
116: CaseTypeManager caseTypeManager = bossa.getCaseTypeManager();
117: caseTypeManager.registerCaseType(BossaTestUtil
118: .createCaseType("test"));
119: ResourceManager myResourceManager = bossa.getResourceManager();
120:
121: Resource group1 = (Resource) caseTypeManager
122: .getCaseType("test").getResources().get(0);
123: Resource group2 = myResourceManager.createResourceImpl("good",
124: false);
125: Resource element = myResourceManager.createResourceImpl("joe",
126: false);
127: group1.includeImpl(group2, false);
128: group2.includeImpl(element, false);
129: assertTrue(group1.contains(element));
130:
131: ExcludeInResource transaction = new ExcludeInResource(group1,
132: element);
133: assertTrue(((Boolean) transaction.execute(myResourceManager))
134: .booleanValue());
135: assertFalse(group1.contains(element));
136: }
137:
138: public void testRemoveFromResource() throws Exception {
139: Resource group = resourceManager.createResourceImpl("trumps",
140: false);
141: Resource element = resourceManager.createResourceImpl("joe",
142: false);
143: group.includeImpl(element, false);
144: assertTrue(group.contains(element));
145:
146: RemoveFromResource transaction = new RemoveFromResource(group,
147: element);
148: transaction.execute(resourceManager);
149: assertFalse(group.contains(element));
150: }
151:
152: public void testRemoveFromCaseTypeResource() throws Exception {
153: Bossa bossa = BossaFactory.transientBossa();
154: CaseTypeManager caseTypeManager = bossa.getCaseTypeManager();
155: caseTypeManager.registerCaseType(BossaTestUtil
156: .createCaseType("test"));
157: ResourceManager myResourceManager = bossa.getResourceManager();
158:
159: Resource group = (Resource) caseTypeManager.getCaseType("test")
160: .getResources().get(0);
161: Resource element = myResourceManager.createResourceImpl("joe",
162: false);
163: group.includeImpl(element, false);
164: assertTrue(group.contains(element));
165:
166: RemoveFromResource transaction = new RemoveFromResource(group,
167: element);
168: transaction.execute(myResourceManager);
169: assertFalse(group.contains(element));
170: }
171: }
|