1 15 package hivemind.test; 16 17 import org.apache.hivemind.ApplicationRuntimeException; 18 import org.apache.hivemind.Registry; 19 import org.apache.hivemind.definition.ImplementationDefinition; 20 import org.apache.hivemind.definition.impl.ModuleDefinitionImpl; 21 import org.apache.hivemind.definition.impl.ServicePointDefinitionImpl; 22 23 28 public class TestServicesByInterface extends FrameworkTestCase 29 { 30 private Registry registry; 31 32 protected void setUp() throws Exception 33 { 34 super.setUp(); 35 36 ModuleDefinitionImpl module = createModuleDefinition("hivemind.tests.serviceByInterface"); 37 38 ServicePointDefinitionImpl sp1 = createServicePointDefinition(module, "uniqueService", IUniqueService.class); 39 ImplementationDefinition impl1 = createServiceImplementationDefinition(module, UniqueServiceImpl.class); 40 sp1.addImplementation(impl1); 41 42 module.addServicePoint(sp1); 43 44 ServicePointDefinitionImpl sp2 = createServicePointDefinition(module, "multipleServiceOne", IMultipleService.class); 45 ImplementationDefinition impl2 = createServiceImplementationDefinition(module, MultipleServiceImpl.class); 46 sp2.addImplementation(impl2); 47 48 module.addServicePoint(sp2); 49 50 ServicePointDefinitionImpl sp3 = createServicePointDefinition(module, "multipleServiceTwo", IMultipleService.class); 51 sp3.addImplementation(impl2); 52 53 module.addServicePoint(sp3); 54 55 registry = buildFrameworkRegistry(module); 56 } 57 58 protected void tearDown() throws Exception 59 { 60 super.tearDown(); 61 62 registry.shutdown(); 63 } 64 65 public void testUniqueGetServiceByInterface() 66 { 67 IUniqueService service = (IUniqueService) registry.getService(IUniqueService.class); 68 69 assertNotNull(service); 70 } 71 72 public void testNonExistentGetServiceByInterface() 73 { 74 try 75 { 76 registry.getService(INonExistentService.class); 77 unreachable(); 78 } 79 catch (ApplicationRuntimeException ex) 80 { 81 assertExceptionSubstring( 82 ex, 83 "There is no service point for interface hivemind.test.INonExistentService."); 84 } 85 } 86 87 public void testMultipleExistentGetServiceByInterface() 88 { 89 try 90 { 91 registry.getService(IMultipleService.class); 92 unreachable(); 93 } 94 catch (ApplicationRuntimeException ex) 95 { 96 assertExceptionSubstring( 97 ex, 98 "There are multiple service points for interface hivemind.test.IMultipleService: " 99 + "{hivemind.tests.serviceByInterface.multipleServiceTwo," 100 + " hivemind.tests.serviceByInterface.multipleServiceOne}."); 101 } 102 } 103 } 104 | Popular Tags |