Title: [899] trunk/core/src/test/java/org/servicemix/jbi/installation/InstallationTest.java: Add junit tests for management / lifecycle.
Revision
899
Author
gnt
Date
2005-11-22 12:51:23 -0500 (Tue, 22 Nov 2005)

Log Message

Add junit tests for management / lifecycle.
Currently the tests fails.

Modified Paths

Diff

Modified: trunk/core/src/test/java/org/servicemix/jbi/installation/InstallationTest.java (898 => 899)

--- trunk/core/src/test/java/org/servicemix/jbi/installation/InstallationTest.java	2005-11-22 17:47:44 UTC (rev 898)
+++ trunk/core/src/test/java/org/servicemix/jbi/installation/InstallationTest.java	2005-11-22 17:51:23 UTC (rev 899)
@@ -116,7 +116,7 @@
      * Installer should not be persistent across restart
      * @throws Exception
      */
-    public void testInstallerNotPersistentAcrossRestart() throws Exception {
+    public void testLoadNewInstallerAndRestart() throws Exception {
         ExtMockControl bootstrapMock = ExtMockControl.createControl(Bootstrap.class);
         Bootstrap bootstrap = (Bootstrap) bootstrapMock.getMock();
         Bootstrap1.setDelegate(bootstrap);
@@ -147,10 +147,48 @@
     }
 
     /**
+     * Installer should not be persistent across restart
+     * @throws Exception
+     */
+    public void testLoadNewInstallerAndLoadNewInstaller() throws Exception {
+        ExtMockControl bootstrapMock = ExtMockControl.createControl(Bootstrap.class);
+        Bootstrap bootstrap = (Bootstrap) bootstrapMock.getMock();
+        Bootstrap1.setDelegate(bootstrap);
+        
+        // configure bootstrap
+        bootstrap.init(null);
+        bootstrapMock.setMatcher(MockControl.ALWAYS_MATCHER);
+        bootstrapMock.replay();
+        // test component installation
+        startContainer(true);
+        String installJarUrl = createInstallerArchive("component1").getAbsolutePath();
+        ObjectName installerName = getInstallationService().loadNewInstaller(installJarUrl);
+        assertNotNull(Bootstrap1.getInstallContext());
+        assertTrue(Bootstrap1.getInstallContext().isInstall());
+        InstallerMBean installer = (InstallerMBean) MBeanServerInvocationHandler.newProxyInstance(container.getMBeanServer(), installerName, InstallerMBean.class, false);
+        assertFalse(installer.isInstalled());
+        // check mocks
+        bootstrapMock.verify();
+        
+        // configure bootstrap
+        bootstrapMock.reset();
+        bootstrapMock.replay();
+        // test load new installer
+        try {
+            getInstallationService().loadNewInstaller(installJarUrl);
+            fail("Expected an exception");
+        } catch (Exception e) {
+            // ok, this should fail
+        }
+        // check mocks
+        bootstrapMock.verify();
+    }
+
+    /**
      * Installer is created, component installed and server restarted
      * @throws Exception
      */
-    public void testInstallerInstallAndRestart() throws Exception {
+    public void testInstallAndRestart() throws Exception {
         // Create mocks
         ExtMockControl bootstrapMock = ExtMockControl.createControl(Bootstrap.class);
         Bootstrap bootstrap = (Bootstrap) bootstrapMock.getMock();
@@ -222,10 +260,10 @@
     }
 
     /**
-     * Installer is created, component installed and server restarted
+     * Installer is created, component installed, started and server restarted
      * @throws Exception
      */
-    public void testInstallerInstallStartAndRestart() throws Exception {
+    public void testInstallStartAndRestart() throws Exception {
         // Create mocks
         ExtMockControl bootstrapMock = ExtMockControl.createControl(Bootstrap.class);
         Bootstrap bootstrap = (Bootstrap) bootstrapMock.getMock();
@@ -293,6 +331,8 @@
         componentMock.replay();
         // configure lifecycle
         lifecycleMock.reset();
+        lifecycle.stop();
+        lifecycle.shutDown();
         lifecycleMock.replay();
         // shutdown container
         shutdownContainer();
@@ -306,9 +346,14 @@
         bootstrapMock.replay();
         // configure component
         componentMock.reset();
+        component.getLifeCycle();
+        componentMock.setReturnValue(lifecycle);
         componentMock.replay();
         // configure lifecycle
         lifecycleMock.reset();
+        lifecycle.init(null);
+        lifecycleMock.setMatcher(MockControl.ALWAYS_MATCHER);
+        lifecycle.start();
         lifecycleMock.replay();
         // start container
         startContainer(false);
@@ -319,4 +364,5 @@
         componentMock.verify();
         lifecycleMock.verify();
     }
+
 }

Reply via email to