1 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 service = (Runnable ) registry.getService("org.apache.hivemind.annotations.SimpleAnnotatedModule.Test", Runnable .class); 32 service.run(); 33 } 34 35 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 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 |