KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > annotations > TestAnnotatedModuleReader


1 // Copyright 2007 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 org.apache.hivemind.annotations;
16
17 import org.apache.hivemind.ApplicationRuntimeException;
18 import org.apache.hivemind.annotations.internal.AnnotatedModuleProcessor;
19 import org.apache.hivemind.definition.ModuleDefinition;
20 import org.apache.hivemind.definition.RegistryDefinition;
21 import org.apache.hivemind.definition.ServicePointDefinition;
22 import org.apache.hivemind.definition.impl.RegistryDefinitionImpl;
23 import org.apache.hivemind.impl.DefaultClassResolver;
24 import org.apache.hivemind.impl.DefaultErrorHandler;
25
26 public class TestAnnotatedModuleReader extends AnnotationTestCase
27 {
28     public void testSimpleModule()
29     {
30         TypedRegistry registry = constructRegistry(SimpleAnnotatedModule.class);
31         Runnable JavaDoc service = (Runnable JavaDoc) registry.getService("org.apache.hivemind.annotations.SimpleAnnotatedModule.Test", Runnable JavaDoc.class);
32         service.run();
33     }
34
35     /**
36      * Tests the string representation of the location of a module and an extension point
37      */

38     public void testLocation()
39     {
40         RegistryDefinition registry = constructRegistryDefinition(SimpleAnnotatedModule.class);
41         ModuleDefinition module = registry.getModule("org.apache.hivemind.annotations.SimpleAnnotatedModule");
42         assertEquals("Class org.apache.hivemind.annotations.SimpleAnnotatedModule", module.getLocation().toString());
43         ServicePointDefinition service = registry.getServicePoint("org.apache.hivemind.annotations.SimpleAnnotatedModule.Test");
44         assertEquals("Class org.apache.hivemind.annotations.SimpleAnnotatedModule, method getRunnable", service.getLocation().toString());
45     }
46     
47     /**
48      * Checks that an explicitly defined id in the module annotation takes precedence
49      * over the package and class name.
50      */

51     public void testModuleId()
52     {
53         RegistryDefinition registry = constructRegistryDefinition(ModuleWithExplicitId.class);
54         assertNotNull(registry.getModule("Test"));
55     }
56   
57     public void testModuleClassNotFinal()
58     {
59         AnnotatedModuleProcessor processor = new AnnotatedModuleProcessor(new RegistryDefinitionImpl(),
60                 new DefaultClassResolver(), new DefaultErrorHandler());
61         try
62         {
63             processor.processModule(FinalModule.class);
64             fail("Final class must not be allowed as module class");
65         }
66         catch (ApplicationRuntimeException expected)
67         {
68         }
69     }
70     
71     public void testModuleClassNotAbstract()
72     {
73         AnnotatedModuleProcessor processor = new AnnotatedModuleProcessor(new RegistryDefinitionImpl(),
74                 new DefaultClassResolver(), new DefaultErrorHandler());
75         try
76         {
77             processor.processModule(AbstractModule.class);
78             fail("Abstract class must not be allowed as module class");
79         }
80         catch (ApplicationRuntimeException expected)
81         {
82         }
83     }
84     
85     public void testModuleClassPublic()
86     {
87         AnnotatedModuleProcessor processor = new AnnotatedModuleProcessor(new RegistryDefinitionImpl(),
88                 new DefaultClassResolver(), new DefaultErrorHandler());
89         try
90         {
91             processor.processModule(NotPublicModule.class);
92             fail("Protected class must not be allowed as module class");
93         }
94         catch (ApplicationRuntimeException expected)
95         {
96         }
97     }
98
99 }
100
Popular Tags