001: /*
002: * Bossa Workflow System
003: *
004: * $Id: ResourceRegistryTest.java,v 1.9 2004/01/29 21:24:37 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: public class ResourceRegistryTest extends TestCase {
030:
031: private ResourceRegistry resourceRegistry;
032:
033: public ResourceRegistryTest(String name) {
034: super (name);
035: }
036:
037: protected void setUp() {
038: resourceRegistry = new ResourceRegistry("null");
039: }
040:
041: public void testAddResource() {
042: assertNotNull(resourceRegistry.createResourceImpl("r1", false));
043: assertNull(resourceRegistry.createResourceImpl("r1", false));
044: }
045:
046: public void testGetResource() {
047: assertNull(resourceRegistry.getResource("r1"));
048: Resource r = resourceRegistry.createResourceImpl("r1", false);
049: assertSame(r, resourceRegistry.getResource("r1"));
050: }
051:
052: public void testNullResourceId() {
053: assertNull(resourceRegistry.createResourceImpl(null, false));
054: assertNull(resourceRegistry.getResource(null));
055: }
056:
057: public void testRemoveResource() {
058: Resource r = resourceRegistry.createResourceImpl("r1", false);
059: assertTrue(resourceRegistry.removeResourceImpl(r, false));
060: assertNotNull(resourceRegistry.createResourceImpl("r1", false));
061: }
062:
063: public void testNestedRemoveResource() {
064: Resource r1 = resourceRegistry.createResourceImpl("r1", false);
065: Resource r2 = resourceRegistry.createResourceImpl("r2", false);
066: r1.includeImpl(r2, false);
067:
068: assertTrue(resourceRegistry.removeResourceImpl(r2, false));
069: assertFalse(r1.contains(r2));
070: }
071:
072: public void testAddRemoveSubContext() {
073: ResourceRegistry subContext = new ResourceRegistry("test");
074: assertFalse(resourceRegistry.removeSubContext(subContext));
075: assertTrue(resourceRegistry.registerSubContext(subContext));
076: assertSame(resourceRegistry, subContext.getSuperContext());
077: assertFalse(resourceRegistry.registerSubContext(subContext));
078: assertTrue(resourceRegistry.removeSubContext(subContext));
079: assertNull(subContext.getSuperContext());
080: assertTrue(resourceRegistry.registerSubContext(subContext));
081: }
082:
083: public void testGetSubContext() {
084: ResourceRegistry subContext = new ResourceRegistry("test");
085: assertTrue(resourceRegistry.registerSubContext(subContext));
086: assertSame(subContext, resourceRegistry.getSubContext("test"));
087: assertNull(resourceRegistry.getSubContext("invalid"));
088: }
089:
090: public void testRemoveResourceInSubContext() {
091: ResourceRegistry subContext = new ResourceRegistry("test");
092: assertTrue(resourceRegistry.registerSubContext(subContext));
093: Resource r1 = resourceRegistry.createResourceImpl("r1", false);
094: Resource r2 = subContext.createResourceImpl("r2", false);
095: r2.includeImpl(r1, false);
096:
097: assertTrue(resourceRegistry.removeResourceImpl(r1, false));
098: assertFalse(r2.contains(r1));
099: }
100:
101: public void testGetResourceManager() {
102: ResourceManager resourceManager = new ResourceManager();
103: ResourceRegistry subContext = new ResourceRegistry("test");
104: resourceManager.registerSubContext(resourceRegistry);
105: resourceRegistry.registerSubContext(subContext);
106:
107: assertSame(resourceManager, subContext.getResourceManager());
108:
109: resourceRegistry.removeSubContext(subContext);
110: assertNull(subContext.getResourceManager());
111: }
112:
113: public void testGetGlobalId() {
114: ResourceManager resourceManager = new ResourceManager();
115: ResourceRegistry subContext = new ResourceRegistry("test");
116: resourceManager.registerSubContext(resourceRegistry);
117: resourceRegistry.registerSubContext(subContext);
118:
119: assertEquals("root.null.test", subContext.getGlobalId());
120: }
121: }
|