01: /*
02: * Bossa Workflow System
03: *
04: * $Id: ResourceManagerTest.java,v 1.10 2003/10/28 17:02:31 gdvieira Exp $
05: *
06: * Copyright (C) 2003 OpenBR Sistemas S/C Ltda.
07: *
08: * This file is part of Bossa.
09: *
10: * Bossa is free software; you can redistribute it and/or modify it
11: * under the terms of version 2 of the GNU General Public License as
12: * published by the Free Software Foundation.
13: *
14: * This program is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17: * General Public License for more details.
18: *
19: * You should have received a copy of the GNU General Public
20: * License along with this program; if not, write to the
21: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22: * Boston, MA 02111-1307, USA.
23: */
24:
25: package com.bigbross.bossa.resource;
26:
27: import junit.framework.TestCase;
28:
29: public class ResourceManagerTest extends TestCase {
30:
31: private ResourceManager resourceManager;
32:
33: public ResourceManagerTest(String name) {
34: super (name);
35: }
36:
37: protected void setUp() {
38: resourceManager = new ResourceManager();
39: }
40:
41: public void testAddRemoveRegistries() {
42: ResourceRegistry context1 = new ResourceRegistry("c1");
43: assertFalse(resourceManager.removeRegistry(context1));
44: assertTrue(resourceManager.addRegistry(context1));
45: assertFalse(resourceManager.addRegistry(context1));
46: assertTrue(resourceManager.removeRegistry(context1));
47: }
48:
49: public void testFindSelf() {
50: String globalId = resourceManager.getGlobalId();
51: assertSame(resourceManager, resourceManager
52: .getRegistry(globalId));
53: }
54:
55: public void testFindRegistry() {
56: ResourceRegistry context1 = new ResourceRegistry("c1");
57: ResourceRegistry context2 = new ResourceRegistry("c2");
58: resourceManager.registerSubContext(context1);
59: context1.registerSubContext(context2);
60:
61: assertSame(context1, resourceManager.getRegistry(context1
62: .getGlobalId()));
63: assertSame(context2, resourceManager.getRegistry(context2
64: .getGlobalId()));
65: }
66:
67: public void testFindRegistryTree() {
68: ResourceRegistry context1 = new ResourceRegistry("c1");
69: ResourceRegistry context2 = new ResourceRegistry("c2");
70: context1.registerSubContext(context2);
71: resourceManager.registerSubContext(context1);
72:
73: assertSame(context1, resourceManager.getRegistry(context1
74: .getGlobalId()));
75: assertSame(context2, resourceManager.getRegistry(context2
76: .getGlobalId()));
77: }
78:
79: public void testRemoveRegistry() {
80: ResourceRegistry context1 = new ResourceRegistry("c1");
81: ResourceRegistry context2 = new ResourceRegistry("c2");
82: resourceManager.registerSubContext(context1);
83: context1.registerSubContext(context2);
84: String id1 = context1.getGlobalId();
85: String id2 = context2.getGlobalId();
86: resourceManager.removeSubContext(context1);
87:
88: assertNull(resourceManager.getRegistry(id1));
89: assertNull(resourceManager.getRegistry(id2));
90: }
91: }
|