KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hivemind > test > TestRegistryBuilder


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package hivemind.test;
16
17 import org.apache.hivemind.ApplicationRuntimeException;
18 import org.apache.hivemind.Registry;
19 import org.apache.hivemind.definition.RegistryDefinition;
20 import org.apache.hivemind.definition.impl.ModuleDefinitionImpl;
21 import org.apache.hivemind.definition.impl.RegistryDefinitionImpl;
22 import org.apache.hivemind.impl.RegistryBuilder;
23 import org.apache.hivemind.service.ClassFactory;
24
25 /**
26  * Tests the {@link org.apache.hivemind.impl.RegistryBuilder} class.
27  *
28  * @author Howard Lewis Ship
29  */

30 public class TestRegistryBuilder extends FrameworkTestCase
31 {
32
33     public void testConstructDefaultRegistry() throws Exception JavaDoc
34     {
35         Registry r = RegistryBuilder.constructDefaultRegistry();
36
37         ClassFactory factory = (ClassFactory) r.getService(
38                 "hivemind.ClassFactory",
39                 ClassFactory.class);
40
41         assertNotNull(factory);
42     }
43
44     public void testDuplicateModuleId() throws Exception JavaDoc
45     {
46         String JavaDoc duplicateModuleId = "non.unique.module";
47
48         RegistryDefinition registryDefinition = new RegistryDefinitionImpl();
49         registryDefinition.addModule(createModuleDefinition(duplicateModuleId));
50         try
51         {
52             registryDefinition.addModule(createModuleDefinition(duplicateModuleId));
53             fail("Duplicate module id not detected");
54         }
55         catch (RuntimeException JavaDoc expected)
56         {
57         }
58     }
59
60     public void testDuplicateExtensionPoints() throws Exception JavaDoc
61     {
62         ModuleDefinitionImpl testModule = createModuleDefinition("hivemind.test");
63
64         testModule.addServicePoint(createServicePointDefinition(testModule, "MyService", Comparable JavaDoc.class));
65         try
66         {
67             testModule.addServicePoint(createServicePointDefinition(testModule, "MyService", Comparable JavaDoc.class));
68             fail("duplicate service point not detected");
69         }
70         catch (ApplicationRuntimeException expected)
71         {
72         }
73
74         testModule.addConfigurationPoint(createConfigurationPointDefinition(testModule, "MyConfig"));
75         try
76         {
77             testModule.addConfigurationPoint(createConfigurationPointDefinition(testModule, "MyConfig"));
78             fail("duplicate configuration point not detected");
79         }
80         catch (ApplicationRuntimeException expected)
81         {
82         }
83     }
84 }
Popular Tags