1 17 package org.apache.servicemix.jbi.installation; 18 19 import javax.jbi.component.Bootstrap; 20 import javax.jbi.component.Component; 21 import javax.jbi.component.ComponentLifeCycle; 22 import javax.jbi.management.InstallerMBean; 23 import javax.jbi.management.LifeCycleMBean; 24 import javax.management.MBeanServerInvocationHandler ; 25 import javax.management.ObjectName ; 26 27 import org.easymock.MockControl; 28 29 30 35 public class InstallationTest extends AbstractManagementTest { 36 37 41 public void testLoadNewInstallerAndRestart() throws Exception { 42 ExtMockControl bootstrapMock = ExtMockControl.createControl(Bootstrap.class); 43 Bootstrap bootstrap = (Bootstrap) bootstrapMock.getMock(); 44 Bootstrap1.setDelegate(bootstrap); 45 46 bootstrap.init(null); 48 bootstrapMock.setMatcher(MockControl.ALWAYS_MATCHER); 49 bootstrap.getExtensionMBeanName(); 50 bootstrapMock.setReturnValue(null); 51 bootstrapMock.replay(); 52 startContainer(true); 54 String installJarUrl = createInstallerArchive("component1").getAbsolutePath(); 55 ObjectName installerName = getInstallationService().loadNewInstaller(installJarUrl); 56 assertNotNull(Bootstrap1.getInstallContext()); 57 assertTrue(Bootstrap1.getInstallContext().isInstall()); 58 InstallerMBean installer = (InstallerMBean) MBeanServerInvocationHandler.newProxyInstance(container.getMBeanServer(), installerName, InstallerMBean.class, false); 59 assertFalse(installer.isInstalled()); 60 shutdownContainer(); 61 bootstrapMock.verify(); 63 64 bootstrapMock.reset(); 66 bootstrapMock.replay(); 67 startContainer(false); 69 bootstrapMock.verify(); 71 } 72 73 77 public void testLoadNewInstallerAndLoadNewInstaller() throws Exception { 78 ExtMockControl bootstrapMock = ExtMockControl.createControl(Bootstrap.class); 79 Bootstrap bootstrap = (Bootstrap) bootstrapMock.getMock(); 80 Bootstrap1.setDelegate(bootstrap); 81 82 bootstrap.init(null); 84 bootstrapMock.setMatcher(MockControl.ALWAYS_MATCHER); 85 bootstrap.getExtensionMBeanName(); 86 bootstrapMock.setReturnValue(null); 87 bootstrapMock.replay(); 88 startContainer(true); 90 String installJarUrl = createInstallerArchive("component1").getAbsolutePath(); 91 ObjectName installerName = getInstallationService().loadNewInstaller(installJarUrl); 92 assertNotNull(Bootstrap1.getInstallContext()); 93 assertTrue(Bootstrap1.getInstallContext().isInstall()); 94 InstallerMBean installer = (InstallerMBean) MBeanServerInvocationHandler.newProxyInstance(container.getMBeanServer(), installerName, InstallerMBean.class, false); 95 assertFalse(installer.isInstalled()); 96 bootstrapMock.verify(); 98 99 bootstrapMock.reset(); 101 bootstrapMock.replay(); 102 try { 104 getInstallationService().loadNewInstaller(installJarUrl); 105 fail("Expected an exception"); 106 } catch (Exception e) { 107 } 109 bootstrapMock.verify(); 111 } 112 113 117 public void testInstallAndRestart() throws Exception { 118 ExtMockControl bootstrapMock = ExtMockControl.createControl(Bootstrap.class); 120 Bootstrap bootstrap = (Bootstrap) bootstrapMock.getMock(); 121 Bootstrap1.setDelegate(bootstrap); 122 ExtMockControl componentMock = ExtMockControl.createControl(Component.class); 123 Component component = (Component) componentMock.getMock(); 124 Component1.setDelegate(component); 125 126 bootstrapMock.reset(); 128 bootstrap.init(null); 129 bootstrapMock.setMatcher(MockControl.ALWAYS_MATCHER); 130 bootstrap.onInstall(); 131 bootstrap.getExtensionMBeanName(); 132 bootstrapMock.setReturnValue(null); 133 bootstrap.cleanUp(); 134 bootstrapMock.replay(); 135 componentMock.reset(); 137 componentMock.replay(); 138 startContainer(true); 140 String installJarUrl = createInstallerArchive("component1").getAbsolutePath(); 141 ObjectName installerName = getInstallationService().loadNewInstaller(installJarUrl); 142 InstallerMBean installer = (InstallerMBean) MBeanServerInvocationHandler.newProxyInstance(container.getMBeanServer(), installerName, InstallerMBean.class, false); 143 assertFalse(installer.isInstalled()); 144 ObjectName lifecycleName = installer.install(); 145 LifeCycleMBean lifecycleMBean = (LifeCycleMBean) MBeanServerInvocationHandler.newProxyInstance(container.getMBeanServer(), lifecycleName, LifeCycleMBean.class, false); 146 assertEquals(LifeCycleMBean.SHUTDOWN, lifecycleMBean.getCurrentState()); 147 bootstrapMock.verify(); 149 componentMock.verify(); 150 151 bootstrapMock.reset(); 153 bootstrapMock.replay(); 154 componentMock.reset(); 156 componentMock.replay(); 157 container.getInstallationService().unloadInstaller("component1", false); 159 bootstrapMock.verify(); 161 componentMock.verify(); 162 163 bootstrapMock.reset(); 165 bootstrapMock.replay(); 166 componentMock.reset(); 168 componentMock.replay(); 169 shutdownContainer(); 171 bootstrapMock.verify(); 173 componentMock.verify(); 174 175 bootstrapMock.reset(); 177 bootstrap.init(null); 178 bootstrapMock.setMatcher(MockControl.ALWAYS_MATCHER); 179 bootstrap.getExtensionMBeanName(); 180 bootstrapMock.setReturnValue(null); 181 bootstrapMock.replay(); 182 componentMock.reset(); 184 componentMock.replay(); 185 startContainer(false); 187 lifecycleMBean = (LifeCycleMBean) MBeanServerInvocationHandler.newProxyInstance(container.getMBeanServer(), lifecycleName, LifeCycleMBean.class, false); 188 assertEquals(LifeCycleMBean.SHUTDOWN, lifecycleMBean.getCurrentState()); 189 bootstrapMock.verify(); 191 componentMock.verify(); 192 } 193 194 198 public void testInstallStartAndRestart() throws Exception { 199 ExtMockControl bootstrapMock = ExtMockControl.createControl(Bootstrap.class); 201 Bootstrap bootstrap = (Bootstrap) bootstrapMock.getMock(); 202 Bootstrap1.setDelegate(bootstrap); 203 ExtMockControl componentMock = ExtMockControl.createControl(Component.class); 204 Component component = (Component) componentMock.getMock(); 205 Component1.setDelegate(component); 206 ExtMockControl lifecycleMock = ExtMockControl.createControl(ComponentLifeCycle.class); 207 ComponentLifeCycle lifecycle = (ComponentLifeCycle) lifecycleMock.getMock(); 208 209 bootstrapMock.reset(); 211 bootstrap.init(null); 212 bootstrapMock.setMatcher(MockControl.ALWAYS_MATCHER); 213 bootstrap.onInstall(); 214 bootstrap.getExtensionMBeanName(); 215 bootstrapMock.setReturnValue(null); 216 bootstrap.cleanUp(); 217 bootstrapMock.replay(); 218 componentMock.reset(); 220 componentMock.replay(); 221 lifecycleMock.reset(); 223 lifecycleMock.replay(); 224 startContainer(true); 226 String installJarUrl = createInstallerArchive("component1").getAbsolutePath(); 227 ObjectName installerName = getInstallationService().loadNewInstaller(installJarUrl); 228 InstallerMBean installer = (InstallerMBean) MBeanServerInvocationHandler.newProxyInstance(container.getMBeanServer(), installerName, InstallerMBean.class, false); 229 assertFalse(installer.isInstalled()); 230 ObjectName lifecycleName = installer.install(); 231 LifeCycleMBean lifecycleMBean = (LifeCycleMBean) MBeanServerInvocationHandler.newProxyInstance(container.getMBeanServer(), lifecycleName, LifeCycleMBean.class, false); 232 assertEquals(LifeCycleMBean.SHUTDOWN, lifecycleMBean.getCurrentState()); 233 bootstrapMock.verify(); 235 componentMock.verify(); 236 lifecycleMock.verify(); 237 238 bootstrapMock.reset(); 240 bootstrapMock.replay(); 241 componentMock.reset(); 243 component.getLifeCycle(); 244 componentMock.setReturnValue(lifecycle); 245 componentMock.replay(); 246 lifecycleMock.reset(); 248 lifecycle.init(null); 249 lifecycleMock.setMatcher(MockControl.ALWAYS_MATCHER); 250 lifecycle.start(); 251 lifecycleMock.replay(); 252 lifecycleMBean.start(); 254 assertEquals(LifeCycleMBean.STARTED, lifecycleMBean.getCurrentState()); 255 bootstrapMock.verify(); 257 componentMock.verify(); 258 lifecycleMock.verify(); 259 260 bootstrapMock.reset(); 262 bootstrapMock.replay(); 263 componentMock.reset(); 265 componentMock.replay(); 266 lifecycleMock.reset(); 268 lifecycle.stop(); 269 lifecycle.shutDown(); 270 lifecycleMock.replay(); 271 shutdownContainer(); 273 bootstrapMock.verify(); 275 componentMock.verify(); 276 lifecycleMock.verify(); 277 278 bootstrapMock.reset(); 280 bootstrap.init(null); 281 bootstrapMock.setMatcher(MockControl.ALWAYS_MATCHER); 282 bootstrap.getExtensionMBeanName(); 283 bootstrapMock.setReturnValue(null); 284 bootstrapMock.replay(); 285 componentMock.reset(); 287 component.getLifeCycle(); 288 componentMock.setDefaultReturnValue(lifecycle); 289 componentMock.replay(); 290 lifecycleMock.reset(); 292 lifecycle.getExtensionMBeanName(); 293 lifecycleMock.setDefaultReturnValue(null); 294 lifecycle.init(null); 295 lifecycleMock.setMatcher(MockControl.ALWAYS_MATCHER); 296 lifecycle.start(); 297 lifecycleMock.replay(); 298 startContainer(false); 300 lifecycleMBean = (LifeCycleMBean) MBeanServerInvocationHandler.newProxyInstance(container.getMBeanServer(), lifecycleName, LifeCycleMBean.class, false); 301 assertEquals(LifeCycleMBean.STARTED, lifecycleMBean.getCurrentState()); 302 bootstrapMock.verify(); 304 componentMock.verify(); 305 lifecycleMock.verify(); 306 } 307 308 313 public void testInstallAndReloadInstaller() throws Exception { 314 ExtMockControl bootstrapMock = ExtMockControl.createControl(Bootstrap.class); 316 Bootstrap bootstrap = (Bootstrap) bootstrapMock.getMock(); 317 Bootstrap1.setDelegate(bootstrap); 318 ExtMockControl componentMock = ExtMockControl.createControl(Component.class); 319 Component component = (Component) componentMock.getMock(); 320 Component1.setDelegate(component); 321 ExtMockControl lifecycleMock = ExtMockControl.createControl(ComponentLifeCycle.class); 322 ComponentLifeCycle lifecycle = (ComponentLifeCycle) lifecycleMock.getMock(); 323 324 bootstrapMock.reset(); 326 bootstrap.init(null); 327 bootstrapMock.setMatcher(MockControl.ALWAYS_MATCHER); 328 bootstrap.onInstall(); 329 bootstrap.getExtensionMBeanName(); 330 bootstrapMock.setReturnValue(null); 331 bootstrap.cleanUp(); 332 bootstrapMock.replay(); 333 componentMock.reset(); 335 component.getLifeCycle(); 336 componentMock.setDefaultReturnValue(lifecycle); 337 componentMock.replay(); 338 lifecycleMock.reset(); 340 lifecycleMock.replay(); 341 startContainer(true); 343 String installJarUrl = createInstallerArchive("component1").getAbsolutePath(); 344 ObjectName installerName = getInstallationService().loadNewInstaller(installJarUrl); 345 InstallerMBean installer = (InstallerMBean) MBeanServerInvocationHandler.newProxyInstance(container.getMBeanServer(), installerName, InstallerMBean.class, false); 346 assertFalse(installer.isInstalled()); 347 ObjectName lifecycleName = installer.install(); 348 LifeCycleMBean lifecycleMBean = (LifeCycleMBean) MBeanServerInvocationHandler.newProxyInstance(container.getMBeanServer(), lifecycleName, LifeCycleMBean.class, false); 349 assertEquals(LifeCycleMBean.SHUTDOWN, lifecycleMBean.getCurrentState()); 350 bootstrapMock.verify(); 352 componentMock.verify(); 353 354 bootstrapMock.reset(); 356 bootstrapMock.replay(); 357 componentMock.reset(); 359 componentMock.replay(); 360 container.getInstallationService().unloadInstaller("component1", false); 362 bootstrapMock.verify(); 364 componentMock.verify(); 365 366 bootstrapMock.reset(); 368 bootstrapMock.replay(); 369 componentMock.reset(); 371 componentMock.replay(); 372 installerName = container.getInstallationService().loadInstaller("component1"); 374 assertNotNull(installerName); 375 bootstrapMock.verify(); 377 componentMock.verify(); 378 } 379 380 384 public void testInstallAndReinstall() throws Exception { 385 ExtMockControl bootstrapMock = ExtMockControl.createControl(Bootstrap.class); 387 Bootstrap bootstrap = (Bootstrap) bootstrapMock.getMock(); 388 Bootstrap1.setDelegate(bootstrap); 389 ExtMockControl componentMock = ExtMockControl.createControl(Component.class); 390 Component component = (Component) componentMock.getMock(); 391 Component1.setDelegate(component); 392 393 bootstrapMock.reset(); 395 bootstrap.init(null); 396 bootstrapMock.setMatcher(MockControl.ALWAYS_MATCHER); 397 bootstrap.onInstall(); 398 bootstrap.getExtensionMBeanName(); 399 bootstrapMock.setReturnValue(null); 400 bootstrap.cleanUp(); 401 bootstrapMock.replay(); 402 componentMock.reset(); 404 componentMock.replay(); 405 startContainer(true); 407 String installJarUrl = createInstallerArchive("component1").getAbsolutePath(); 408 ObjectName installerName = getInstallationService().loadNewInstaller(installJarUrl); 409 InstallerMBean installer = (InstallerMBean) MBeanServerInvocationHandler.newProxyInstance(container.getMBeanServer(), installerName, InstallerMBean.class, false); 410 assertFalse(installer.isInstalled()); 411 ObjectName lifecycleName = installer.install(); 412 LifeCycleMBean lifecycleMBean = (LifeCycleMBean) MBeanServerInvocationHandler.newProxyInstance(container.getMBeanServer(), lifecycleName, LifeCycleMBean.class, false); 413 assertEquals(LifeCycleMBean.SHUTDOWN, lifecycleMBean.getCurrentState()); 414 bootstrapMock.verify(); 416 componentMock.verify(); 417 418 bootstrapMock.reset(); 420 bootstrap.onUninstall(); 421 bootstrap.cleanUp(); 422 bootstrapMock.replay(); 423 componentMock.reset(); 425 componentMock.replay(); 426 container.getInstallationService().unloadInstaller("component1", true); 428 bootstrapMock.verify(); 430 componentMock.verify(); 431 432 bootstrapMock.reset(); 434 bootstrap.init(null); 435 bootstrapMock.setMatcher(MockControl.ALWAYS_MATCHER); 436 bootstrap.getExtensionMBeanName(); 437 bootstrapMock.setReturnValue(null); 438 bootstrap.onInstall(); 439 bootstrap.cleanUp(); 440 bootstrapMock.replay(); 441 componentMock.reset(); 443 componentMock.replay(); 444 startContainer(true); 446 installJarUrl = createInstallerArchive("component1").getAbsolutePath(); 447 installerName = getInstallationService().loadNewInstaller(installJarUrl); 448 installer = (InstallerMBean) MBeanServerInvocationHandler.newProxyInstance(container.getMBeanServer(), installerName, InstallerMBean.class, false); 449 assertFalse(installer.isInstalled()); 450 lifecycleName = installer.install(); 451 lifecycleMBean = (LifeCycleMBean) MBeanServerInvocationHandler.newProxyInstance(container.getMBeanServer(), lifecycleName, LifeCycleMBean.class, false); 452 assertEquals(LifeCycleMBean.SHUTDOWN, lifecycleMBean.getCurrentState()); 453 bootstrapMock.verify(); 455 componentMock.verify(); 456 457 bootstrapMock.reset(); 459 bootstrapMock.replay(); 460 componentMock.reset(); 462 componentMock.replay(); 463 shutdownContainer(); 465 bootstrapMock.verify(); 467 componentMock.verify(); 468 } 469 470 } 471 | Popular Tags |