Author: rickhall
Date: Tue Jun 15 16:10:38 2010
New Revision: 954946

URL: http://svn.apache.org/viewvc?rev=954946&view=rev
Log:
Add more virtual bundle test cases.

Modified:
    
felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/TestVirtualBundle.java
    
felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/Activator.java

Modified: 
felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/TestVirtualBundle.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/TestVirtualBundle.java?rev=954946&r1=954945&r2=954946&view=diff
==============================================================================
--- 
felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/TestVirtualBundle.java
 (original)
+++ 
felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/TestVirtualBundle.java
 Tue Jun 15 16:10:38 2010
@@ -141,6 +141,145 @@ public class TestVirtualBundle extends F
         }
     }
 
+    public void testVirtualBundleUninstall001() throws Exception
+    {
+        InputStream is = null;
+
+        try
+        {
+            // Install and start manager bundle, which will install a virtual 
bundle.
+            is = 
this.getClass().getClassLoader().getResourceAsStream("vb.b001.jar");
+            m_bundleA = getBundleContext().installBundle("vb.b001.jar", is);
+
+            int before = getBundleContext().getBundles().length;
+            try
+            {
+                m_bundleA.start();
+            }
+            catch (BundleException ex)
+            {
+                assertTrue("Manager should start", false);
+            }
+            assertEquals("A virtual bundle should have been installed.",
+                before + 1, getBundleContext().getBundles().length);
+
+            // Get the virtual bundle.
+            m_bundleB = getBundle("org.apache.felix.framework.vb.b002");
+            assertEquals(
+                "Virtual bundle should be INSTALLED", Bundle.INSTALLED, 
m_bundleB.getState());
+
+            // Uninstall the virtual bundle.
+            m_bundleB.uninstall();
+            assertEquals(
+                "Virtual bundle should be UNINSTALLED", Bundle.UNINSTALLED, 
m_bundleB.getState());
+
+            // Refresh the virtual bundle.
+            refreshAndWait();
+            m_bundleB = getBundle("org.apache.felix.framework.vb.b002");
+            assertNull("Virtual bundle shouldn't be installed", m_bundleB);
+
+            // Manager should still be active.
+            assertEquals(
+                "Manager should be ACTIVE", Bundle.ACTIVE, 
m_bundleA.getState());
+
+            // Install and start client bundle, which should fail.
+            is = 
this.getClass().getClassLoader().getResourceAsStream("vb.b003.jar");
+            m_bundleC = getBundleContext().installBundle("vb.b003.jar", is);
+            try
+            {
+                m_bundleC.start();
+            }
+            catch (BundleException ex)
+            {
+                // Expected
+            }
+            assertEquals(
+                "Client bundle shouldn't resolve", Bundle.INSTALLED, 
m_bundleC.getState());
+        }
+        finally
+        {
+            cleanup();
+        }
+    }
+
+    public void testVirtualBundleUninstall002() throws Exception
+    {
+        InputStream is = null;
+
+        try
+        {
+            // Install and start manager bundle, which will install a virtual 
bundle.
+            is = 
this.getClass().getClassLoader().getResourceAsStream("vb.b001.jar");
+            m_bundleA = getBundleContext().installBundle("vb.b001.jar", is);
+
+            int before = getBundleContext().getBundles().length;
+            try
+            {
+                m_bundleA.start();
+            }
+            catch (BundleException ex)
+            {
+                assertTrue("Manager should start", false);
+            }
+            assertEquals("A virtual bundle should have been installed.",
+                before + 1, getBundleContext().getBundles().length);
+
+            // Get the virtual bundle.
+            m_bundleB = getBundle("org.apache.felix.framework.vb.b002");
+            assertEquals(
+                "Virtual bundle should be INSTALLED", Bundle.INSTALLED, 
m_bundleB.getState());
+
+            // Get the virtual bundle.
+            m_bundleB = getBundle("org.apache.felix.framework.vb.b002");
+            assertEquals("Virtual bundle should be INSTALLED", 
Bundle.INSTALLED, m_bundleB.getState());
+
+            // Start the virtual bundle.
+            try
+            {
+                m_bundleB.start();
+                assertEquals("Virtual bundle should be ACTIVE", Bundle.ACTIVE, 
m_bundleB.getState());
+            }
+            catch (BundleException ex)
+            {
+            }
+
+            // Install and start client bundle, which should succeed.
+            is = 
this.getClass().getClassLoader().getResourceAsStream("vb.b003.jar");
+            m_bundleC = getBundleContext().installBundle("vb.b003.jar", is);
+            try
+            {
+                m_bundleC.start();
+                assertEquals("Client bundle should be ACTIVE", Bundle.ACTIVE, 
m_bundleC.getState());
+            }
+            catch (BundleException ex)
+            {
+                assertTrue("Client bundle should start: " + ex, false);
+            }
+
+            // Uninstall the virtual bundle.
+            m_bundleB.uninstall();
+            assertEquals(
+                "Virtual bundle should be UNINSTALLED", Bundle.UNINSTALLED, 
m_bundleB.getState());
+
+            // Refresh the virtual bundle.
+            refreshAndWait();
+            m_bundleB = getBundle("org.apache.felix.framework.vb.b002");
+            assertNull("Virtual bundle shouldn't be installed", m_bundleB);
+
+            // Manager should still be active.
+            assertEquals(
+                "Manager should be ACTIVE", Bundle.ACTIVE, 
m_bundleA.getState());
+
+            // Client bundle should still be installed.
+            assertEquals(
+                "Client bundle should be INSTALLED", Bundle.INSTALLED, 
m_bundleC.getState());
+        }
+        finally
+        {
+            cleanup();
+        }
+    }
+
     public void testManagerUninstall001() throws Exception
     {
         InputStream is = null;
@@ -299,6 +438,104 @@ public class TestVirtualBundle extends F
         }
     }
 
+    public void testManagerReinstall() throws Exception
+    {
+        InputStream is = null;
+
+        try
+        {
+            // Install and start manager bundle, which will install a virtual 
bundle.
+            is = 
this.getClass().getClassLoader().getResourceAsStream("vb.b001.jar");
+            m_bundleA = getBundleContext().installBundle("vb.b001.jar", is);
+
+            int before = getBundleContext().getBundles().length;
+            try
+            {
+                m_bundleA.start();
+            }
+            catch (BundleException ex)
+            {
+                assertTrue("Manager should start", false);
+            }
+            assertEquals("A virtual bundle should have been installed.",
+                before + 1, getBundleContext().getBundles().length);
+
+            // Uninstall manager.
+            m_bundleA.uninstall();
+            assertEquals(
+                "Manager should be UNINSTALLED", Bundle.UNINSTALLED, 
m_bundleA.getState());
+
+            // Refresh the manager.
+            refreshAndWait();
+            m_bundleA = getBundle("org.apache.felix.framework.vb.b001");
+            assertNull("Manager shouldn't be installed", m_bundleA);
+
+            // Get the virtual bundle.
+            m_bundleB = getBundle("org.apache.felix.framework.vb.b002");
+            assertEquals(
+                "Virtual bundle should be INSTALLED", Bundle.INSTALLED, 
m_bundleB.getState());
+
+            // Start the virtual bundle, which should fail.
+            try
+            {
+                m_bundleB.start();
+            }
+            catch (BundleException ex)
+            {
+                // Expected
+            }
+            assertEquals(
+                "Virtual bundle shouldn't resolve", Bundle.INSTALLED, 
m_bundleB.getState());
+
+            // Reinstall and start manager bundle, which will reinstall the 
virtual
+            // bundle's content.
+            is = 
this.getClass().getClassLoader().getResourceAsStream("vb.b001.jar");
+            m_bundleA = getBundleContext().installBundle("vb.b001.jar", is);
+
+            before = getBundleContext().getBundles().length;
+            try
+            {
+                m_bundleA.start();
+            }
+            catch (BundleException ex)
+            {
+                assertTrue("Manager should start", false);
+            }
+            assertEquals("Another virtual bundle should not have been 
installed.",
+                before, getBundleContext().getBundles().length);
+
+            // Start the virtual bundle, which should succeed.
+            try
+            {
+                m_bundleB.start();
+            }
+            catch (BundleException ex)
+            {
+                assertTrue("Virtual bundle should start: " + ex, false);
+            }
+            assertEquals(
+                "Virtual bundle should start ", Bundle.ACTIVE, 
m_bundleB.getState());
+
+            // Install and start client bundle, which should succeed.
+            is = 
this.getClass().getClassLoader().getResourceAsStream("vb.b003.jar");
+            m_bundleC = getBundleContext().installBundle("vb.b003.jar", is);
+            try
+            {
+                m_bundleC.start();
+            }
+            catch (BundleException ex)
+            {
+                assertTrue("Client bundle should start: " + ex, false);
+            }
+            assertEquals(
+                "Client bundle should resolve", Bundle.ACTIVE, 
m_bundleC.getState());
+        }
+        finally
+        {
+            cleanup();
+        }
+    }
+
     private Bundle getBundle(String symName)
     {
 

Modified: 
felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/Activator.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/Activator.java?rev=954946&r1=954945&r2=954946&view=diff
==============================================================================
--- 
felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/Activator.java
 (original)
+++ 
felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/Activator.java
 Tue Jun 15 16:10:38 2010
@@ -59,20 +59,19 @@ public class Activator implements Bundle
                 Map headers = (mf == null) ? new HashMap() : 
mf.getMainAttributes();
                 // Create a case insensitive map of manifest attributes.
                 headers = new StringMap(headers, false);
-                try
+
+                // See if the virtual bundle is already installed.
+                Bundle vb = getBundle(bc, 
"org.apache.felix.framework.vb.b002");
+                if (vb == null)
                 {
                     fbc.installBundle(
                         "virtualbundle",
                         headers,
                         new JarVirtualModule(headers, jarFile));
                 }
-                catch (BundleException ex)
+                else
                 {
-                    if (ex.getType() != BundleException.DUPLICATE_BUNDLE_ERROR)
-                    {
-                        throw ex;
-                    }
-                    System.out.println("Virtual bundle needs to be 
reinstalled.");
+                    fbc.reinstallBundle(vb, new JarVirtualModule(headers, 
jarFile));
                 }
             }
             catch (IOException ex)


Reply via email to