1 15 package org.apache.hivemind.impl; 16 17 import hivemind.test.FrameworkTestCase; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 import java.util.Locale ; 22 import java.util.Map ; 23 24 import org.apache.hivemind.ApplicationRuntimeException; 25 import org.apache.hivemind.Location; 26 import org.apache.hivemind.definition.ModuleDefinition; 27 import org.apache.hivemind.definition.Visibility; 28 import org.apache.hivemind.definition.impl.ImplementationDefinitionImpl; 29 import org.apache.hivemind.definition.impl.ServicePointDefinitionImpl; 30 import org.apache.hivemind.internal.Module; 31 import org.apache.hivemind.internal.ServiceModel; 32 import org.apache.hivemind.internal.ServiceModelFactory; 33 import org.easymock.MockControl; 34 35 42 public class TestServicePoint extends FrameworkTestCase 43 { 44 private Module newModule() 45 { 46 ModuleImpl result = new ModuleImpl(); 47 result.setModuleId("test"); 48 result.setClassResolver(getClassResolver()); 49 result.setPackageName(""); 50 result.setRegistry(new RegistryInfrastructureImpl(new StrictErrorHandler(), Locale 51 .getDefault())); 52 return result; 53 } 54 55 public void testUnknownInterfaceClass() 56 { 57 Location l = newLocation(); 58 Module module = newModule(); 59 60 replayControls(); 61 62 ModuleDefinition moduleDefinition = createModuleDefinition("module"); 63 ServicePointDefinitionImpl definition = new ServicePointDefinitionImpl(moduleDefinition, "zip.zap", l, Visibility.PUBLIC, "foo.bar.Baz"); 64 ServicePointImpl sp = new ServicePointImpl(module, definition); 65 66 try 67 { 68 sp.getServiceInterface(); 69 unreachable(); 70 } 71 catch (ApplicationRuntimeException ex) 72 { 73 assertEquals("Unable to find interface foo.bar.Baz (for service test.zip.zap).", ex 74 .getMessage()); 75 assertSame(l, ex.getLocation()); 76 } 77 78 verifyControls(); 79 } 80 81 public void testResultNotAssignableToServiceInterface() 82 { 83 Location l = newLocation(); 84 85 MockControl modulec = newControl(Module.class); 86 Module module = (Module) modulec.getMock(); 87 88 ModuleDefinition moduleDef = createModuleDefinition("foo"); 89 ServicePointDefinitionImpl definition = new ServicePointDefinitionImpl(moduleDef, "bar", l, Visibility.PUBLIC, "java.util.List"); 90 definition.addImplementation(new ImplementationDefinitionImpl(moduleDef, l, null, "fred", true)); 91 ServicePointImpl sp = new ServicePointImpl(module, definition); 92 93 Object service = new ArrayList (); 94 95 MockControl factoryc = newControl(ServiceModelFactory.class); 96 ServiceModelFactory factory = (ServiceModelFactory) factoryc.getMock(); 97 98 MockControl modelc = newControl(ServiceModel.class); 99 ServiceModel model = (ServiceModel) modelc.getMock(); 100 101 module.getServiceModelFactory("fred"); 102 modulec.setReturnValue(factory); 103 104 factory.createServiceModelForService(sp); 105 factoryc.setReturnValue(model); 106 107 model.getService(); 108 modelc.setReturnValue(service); 109 110 module.getModuleId(); 111 modulec.setReturnValue("test"); 112 113 module.resolveType("java.util.List"); 114 modulec.setReturnValue(List .class); 115 116 replayControls(); 117 118 try 119 { 120 sp.getService(Map .class); 121 unreachable(); 122 } 123 catch (ApplicationRuntimeException ex) 124 { 125 assertEquals( 126 "Service test.bar does not implement the requested interface (java.util.Map). The declared service interface type is java.util.List.", 127 ex.getMessage()); 128 assertSame(l, ex.getLocation()); 129 } 130 } 131 } | Popular Tags |