1 15 package org.apache.hivemind.impl; 16 17 import java.util.List ; 18 19 import hivemind.test.FrameworkTestCase; 20 21 import org.apache.hivemind.ApplicationRuntimeException; 22 import org.apache.hivemind.definition.Visibility; 23 import org.apache.hivemind.definition.impl.ConfigurationPointDefinitionImpl; 24 import org.apache.hivemind.internal.ConfigurationPoint; 25 import org.apache.hivemind.internal.Module; 26 import org.apache.hivemind.internal.ServicePoint; 27 import org.apache.hivemind.service.ClassFactory; 28 import org.easymock.MockControl; 29 30 35 public class TestVisibility extends FrameworkTestCase 36 { 37 public void testPublicConfigurationVisibleToOtherModule() 38 { 39 Module m = (Module) newMock(Module.class); 40 41 Module om = (Module) newMock(Module.class); 42 43 replayControls(); 44 45 ConfigurationPointDefinitionImpl cpd = new ConfigurationPointDefinitionImpl(createModuleDefinition("module")); 46 cpd.setVisibility(Visibility.PUBLIC); 47 ConfigurationPointImpl cp = new ConfigurationPointImpl(m, cpd); 48 49 assertEquals(true, cp.visibleToModule(om)); 50 51 verifyControls(); 52 } 53 54 public void testPublicConfigurationVisibleToApplication() 55 { 56 Module m = (Module) newMock(Module.class); 57 58 replayControls(); 59 60 ConfigurationPointDefinitionImpl cpd = new ConfigurationPointDefinitionImpl(createModuleDefinition("module")); 61 cpd.setVisibility(Visibility.PUBLIC); 62 ConfigurationPointImpl cp = new ConfigurationPointImpl(m, cpd); 63 64 assertEquals(true, cp.visibleToModule(null)); 65 66 verifyControls(); 67 } 68 69 public void testPrivateConfigurationInvisibleToOtherModule() 70 { 71 Module m = (Module) newMock(Module.class); 72 Module om = (Module) newMock(Module.class); 73 74 replayControls(); 75 76 ConfigurationPointDefinitionImpl cpd = new ConfigurationPointDefinitionImpl(createModuleDefinition("module")); 77 cpd.setVisibility(Visibility.PRIVATE); 78 ConfigurationPointImpl cp = new ConfigurationPointImpl(m, cpd); 79 80 assertEquals(false, cp.visibleToModule(om)); 81 82 verifyControls(); 83 } 84 85 public void testPrivateConfigurationInvisibleToApplication() 86 { 87 Module m = (Module) newMock(Module.class); 88 89 replayControls(); 90 91 ConfigurationPointDefinitionImpl cpd = new ConfigurationPointDefinitionImpl(createModuleDefinition("module")); 92 cpd.setVisibility(Visibility.PRIVATE); 93 ConfigurationPointImpl cp = new ConfigurationPointImpl(m, cpd); 94 95 assertEquals(false, cp.visibleToModule(null)); 96 97 verifyControls(); 98 } 99 100 public void testGetServiceNotVisibleToApplication() 101 { 102 RegistryInfrastructureImpl rf = new RegistryInfrastructureImpl(null, null); 103 104 MockControl spc = newControl(ServicePoint.class); 105 ServicePoint sp = (ServicePoint) spc.getMock(); 106 107 109 sp.getExtensionPointId(); 110 spc.setReturnValue("foo.bar.Baz"); 111 112 sp.getServiceInterfaceClassName(); 113 spc.setReturnValue(Runnable .class.getName()); 114 115 sp.visibleToModule(null); 116 spc.setReturnValue(false); 117 118 replayControls(); 119 120 rf.addServicePoint(sp); 121 122 try 123 { 124 rf.getService("foo.bar.Baz", Runnable .class, null); 125 126 unreachable(); 127 } 128 catch (ApplicationRuntimeException ex) 129 { 130 assertEquals(ImplMessages.serviceNotVisible("foo.bar.Baz", null), ex.getMessage()); 131 } 132 133 verifyControls(); 134 } 135 136 public void testGetServiceNotVisibleToModule() 137 { 138 RegistryInfrastructureImpl rf = new RegistryInfrastructureImpl(null, null); 139 140 MockControl spc = newControl(ServicePoint.class); 141 ServicePoint sp = (ServicePoint) spc.getMock(); 142 143 ModuleImpl m = new ModuleImpl(); 144 m.setModuleId("zip.zap.Zoom"); 145 146 148 sp.getExtensionPointId(); 149 spc.setReturnValue("foo.bar.Baz"); 150 151 sp.getServiceInterfaceClassName(); 152 spc.setReturnValue(Runnable .class.getName()); 153 154 sp.visibleToModule(m); 155 spc.setReturnValue(false); 156 157 replayControls(); 158 159 rf.addServicePoint(sp); 160 161 try 162 { 163 rf.getService("foo.bar.Baz", Runnable .class, m); 164 165 unreachable(); 166 } 167 catch (ApplicationRuntimeException ex) 168 { 169 assertEquals(ImplMessages.serviceNotVisible("foo.bar.Baz", m), ex.getMessage()); 170 } 171 172 verifyControls(); 173 } 174 175 public void testGetConfigurationNotVisibleToModule() 176 { 177 RegistryInfrastructureImpl rf = new RegistryInfrastructureImpl(null, null); 178 179 MockControl control = newControl(ConfigurationPoint.class); 180 ConfigurationPoint point = (ConfigurationPoint) control.getMock(); 181 182 ModuleImpl m = new ModuleImpl(); 183 m.setModuleId("zip.zap.Zoom"); 184 185 187 point.getExtensionPointId(); 188 control.setReturnValue("foo.bar.Baz"); 189 190 point.getConfigurationType(); 191 control.setReturnValue(List .class); 192 193 point.visibleToModule(m); 194 control.setReturnValue(false); 195 196 replayControls(); 197 198 rf.addConfigurationPoint(point); 199 200 try 201 { 202 rf.getConfiguration("foo.bar.Baz", m); 203 204 unreachable(); 205 } 206 catch (ApplicationRuntimeException ex) 207 { 208 assertEquals(ImplMessages.configurationNotVisible("foo.bar.Baz", m), ex.getMessage()); 209 } 210 211 verifyControls(); 212 } 213 214 220 public void testGetServiceMatchesPublicOnly() 221 { 222 MockControl spc1 = newControl(ServicePoint.class); 223 ServicePoint sp1 = (ServicePoint) spc1.getMock(); 224 225 MockControl spc2 = newControl(ServicePoint.class); 226 ServicePoint sp2 = (ServicePoint) spc2.getMock(); 227 228 ClassFactory service = (ClassFactory) newMock(ClassFactory.class); 229 230 232 sp1.getExtensionPointId(); 233 spc1.setReturnValue("foo.Private"); 234 235 sp1.getServiceInterfaceClassName(); 236 spc1.setReturnValue(ClassFactory.class.getName()); 237 238 sp2.getExtensionPointId(); 239 spc2.setReturnValue("foo.Public"); 240 241 sp2.getServiceInterfaceClassName(); 242 spc2.setReturnValue(ClassFactory.class.getName()); 243 244 sp1.visibleToModule(null); 245 spc1.setReturnValue(false); 246 247 sp2.visibleToModule(null); 248 spc2.setReturnValue(true); 249 250 sp2.getService(ClassFactory.class); 251 spc2.setReturnValue(service); 252 253 replayControls(); 254 255 RegistryInfrastructureImpl r = new RegistryInfrastructureImpl(null, null); 256 257 r.addServicePoint(sp1); 258 r.addServicePoint(sp2); 259 260 Object actual = r.getService(ClassFactory.class, null); 261 262 assertSame(service, actual); 263 264 verifyControls(); 265 } 266 267 public void testContributionToNonVisibleConfigurationPoint() 268 { 269 271 } 343 } | Popular Tags |