felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r1195568 - in /felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test: FelixTestCase.java TestCapability.java TestResolver.java
Date Mon, 31 Oct 2011 16:57:59 GMT
Author: rickhall
Date: Mon Oct 31 16:57:59 2011
New Revision: 1195568

URL: http://svn.apache.org/viewvc?rev=1195568&view=rev
Log:
Refactor base test case to handle bundle cleanup.

Modified:
    felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/FelixTestCase.java
    felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/TestCapability.java
    felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/TestResolver.java

Modified: felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/FelixTestCase.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/FelixTestCase.java?rev=1195568&r1=1195567&r2=1195568&view=diff
==============================================================================
--- felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/FelixTestCase.java
(original)
+++ felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/FelixTestCase.java
Mon Oct 31 16:57:59 2011
@@ -20,6 +20,8 @@ package org.apache.felix.framework.test;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
 import junit.framework.TestCase;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -32,6 +34,34 @@ public abstract class FelixTestCase exte
 {
     private volatile BundleContext m_context;
     private volatile PackageAdmin m_pa = null;
+    private final Map<String, Bundle> m_bundles = new HashMap<String, Bundle>();
+
+    public void addBundle(String s, Bundle b)
+    {
+        m_bundles.put(s, b);
+    }
+
+    public Bundle getBundle(String s)
+    {
+        return m_bundles.get(s);
+    }
+
+    public void cleanupBundles()
+    {
+        for (Bundle b : m_bundles.values())
+        {
+            try
+            {
+                b.uninstall();
+            }
+            catch (Exception ex)
+            {
+                // Ummm?
+            }
+        }
+        m_bundles.clear();
+        refreshFramework();
+    }
 
     public BundleContext getBundleContext()
     {

Modified: felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/TestCapability.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/TestCapability.java?rev=1195568&r1=1195567&r2=1195568&view=diff
==============================================================================
--- felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/TestCapability.java
(original)
+++ felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/TestCapability.java
Mon Oct 31 16:57:59 2011
@@ -30,14 +30,10 @@ import org.osgi.framework.wiring.BundleW
 
 public class TestCapability extends FelixTestCase
 {
-    private List<Bundle> m_bundles = new ArrayList<Bundle>();
-
     public void testCapabilities() throws Exception
     {
         InputStream is = null;
 
-        final int A = 0, B = 1, C = 2, D = 3;
-
         // Scenario #1
         //
         // Try to resolve a bundle with an unsatisfied required capability.
@@ -45,11 +41,11 @@ public class TestCapability extends Feli
         try
         {
             is = this.getClass().getClassLoader().getResourceAsStream("capability.b002a.jar");
-            m_bundles.add(getBundleContext().installBundle("capability.b002a.jar", is));
+            addBundle("A", getBundleContext().installBundle("capability.b002a.jar", is));
 
             try
             {
-                m_bundles.get(A).start();
+                getBundle("A").start();
                 fail("Bundle should not resolve and start.");
             }
             catch (BundleException ex)
@@ -58,7 +54,7 @@ public class TestCapability extends Feli
         }
         finally
         {
-            cleanup();
+            cleanupBundles();
         }
 
         // Scenario #2
@@ -69,14 +65,14 @@ public class TestCapability extends Feli
         try
         {
             is = this.getClass().getClassLoader().getResourceAsStream("capability.b001.jar");
-            m_bundles.add(getBundleContext().installBundle("capability.b001.jar", is));
+            addBundle("A", getBundleContext().installBundle("capability.b001.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("capability.b002a.jar");
-            m_bundles.add(getBundleContext().installBundle("capability.b002a.jar", is));
+            addBundle("B", getBundleContext().installBundle("capability.b002a.jar", is));
 
             try
             {
-                m_bundles.get(B).start();
-                m_bundles.get(B).stop();
+                getBundle("B").start();
+                getBundle("B").stop();
             }
             catch (BundleException ex)
             {
@@ -84,24 +80,24 @@ public class TestCapability extends Feli
             }
 
             // Check that bundle B is wired to bundle A.
-            BundleWiring bw = m_bundles.get(B).adapt(BundleWiring.class);
+            BundleWiring bw = getBundle("B").adapt(BundleWiring.class);
             List<BundleWire> wires = bw.getRequiredWires(null);
             assertEquals("Bundle should have two wires.", 2, wires.size());
             assertEquals("Wrong provider.",
-                wires.get(0).getProviderWiring().getBundle(), m_bundles.get(A));
+                wires.get(0).getProviderWiring().getBundle(), getBundle("A"));
             assertEquals("Wrong provider.",
-                wires.get(1).getProviderWiring().getBundle(), m_bundles.get(A));
+                wires.get(1).getProviderWiring().getBundle(), getBundle("A"));
 
             // Refresh provider and make sure requirer is also refreshed.
-            refreshBundle(m_bundles.get(A));
+            refreshBundle(getBundle("A"));
             assertEquals("Provider should be installed.",
-                Bundle.INSTALLED, m_bundles.get(A).getState());
+                Bundle.INSTALLED, getBundle("A").getState());
             assertEquals("Requirer should be installed.",
-                Bundle.INSTALLED, m_bundles.get(B).getState());
+                Bundle.INSTALLED, getBundle("B").getState());
         }
         finally
         {
-            cleanup();
+            cleanupBundles();
         }
 
         // Scenario #3
@@ -112,14 +108,14 @@ public class TestCapability extends Feli
         try
         {
             is = this.getClass().getClassLoader().getResourceAsStream("capability.b001.jar");
-            m_bundles.add(getBundleContext().installBundle("capability.b001.jar", is));
+            addBundle("A", getBundleContext().installBundle("capability.b001.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("capability.b002b.jar");
-            m_bundles.add(getBundleContext().installBundle("capability.b002b.jar", is));
+            addBundle("B", getBundleContext().installBundle("capability.b002b.jar", is));
 
             try
             {
-                m_bundles.get(B).start();
-                m_bundles.get(B).stop();
+                getBundle("B").start();
+                getBundle("B").stop();
             }
             catch (BundleException ex)
             {
@@ -127,22 +123,22 @@ public class TestCapability extends Feli
             }
 
             // Check that bundle B is wired to bundle A.
-            BundleWiring bw = m_bundles.get(B).adapt(BundleWiring.class);
+            BundleWiring bw = getBundle("B").adapt(BundleWiring.class);
             List<BundleWire> wires = bw.getRequiredWires(null);
             assertEquals("Bundle should have one wire.", 1, wires.size());
             assertEquals("Wrong provider.",
-                wires.get(0).getProviderWiring().getBundle(), m_bundles.get(A));
+                wires.get(0).getProviderWiring().getBundle(), getBundle("A"));
 
             // Refresh provider and make sure requirer is also refreshed.
-            refreshBundle(m_bundles.get(A));
+            refreshBundle(getBundle("A"));
             assertEquals("Provider should be installed.",
-                Bundle.INSTALLED, m_bundles.get(A).getState());
+                Bundle.INSTALLED, getBundle("A").getState());
             assertEquals("Requirer should be installed.",
-                Bundle.INSTALLED, m_bundles.get(B).getState());
+                Bundle.INSTALLED, getBundle("B").getState());
         }
         finally
         {
-            cleanup();
+            cleanupBundles();
         }
     }
 
@@ -151,8 +147,6 @@ public class TestCapability extends Feli
     {
         InputStream is = null;
 
-        final int A = 0, B = 1, C = 2, D = 3;
-
         // Scenario #1
         //
         // Install a bundle with a generic requirement on a capability that has
@@ -162,16 +156,16 @@ public class TestCapability extends Feli
         try
         {
             is = this.getClass().getClassLoader().getResourceAsStream("capability.b003a.jar");
-            m_bundles.add(getBundleContext().installBundle("capability.b003a.jar", is));
+            addBundle("A", getBundleContext().installBundle("capability.b003a.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("capability.b004.jar");
-            m_bundles.add(getBundleContext().installBundle("capability.b004.jar", is));
+            addBundle("B", getBundleContext().installBundle("capability.b004.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("capability.b005.jar");
-            m_bundles.add(getBundleContext().installBundle("capability.b005.jar", is));
+            addBundle("C", getBundleContext().installBundle("capability.b005.jar", is));
 
             try
             {
-                m_bundles.get(C).start();
-                m_bundles.get(C).stop();
+                getBundle("C").start();
+                getBundle("C").stop();
             }
             catch (BundleException ex)
             {
@@ -179,35 +173,35 @@ public class TestCapability extends Feli
             }
 
             // Check that bundle B is wired to bundle A.
-            BundleWiring bw = m_bundles.get(B).adapt(BundleWiring.class);
+            BundleWiring bw = getBundle("B").adapt(BundleWiring.class);
             List<BundleWire> wires = bw.getRequiredWires(null);
             assertEquals("Bundle should have one wire.", 1, wires.size());
             assertEquals("Wrong provider.",
-                wires.get(0).getProviderWiring().getBundle(), m_bundles.get(A));
+                wires.get(0).getProviderWiring().getBundle(), getBundle("A"));
 
             // Check that bundle C is wired to bundles A and B.
-            bw = m_bundles.get(C).adapt(BundleWiring.class);
+            bw = getBundle("C").adapt(BundleWiring.class);
             wires = bw.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
             assertEquals("Bundle should have one package wire.", 1, wires.size());
             assertEquals("Wrong provider.",
-                wires.get(0).getProviderWiring().getBundle(), m_bundles.get(A));
+                wires.get(0).getProviderWiring().getBundle(), getBundle("A"));
             wires = bw.getRequiredWires("capability.b004");
             assertEquals("Bundle should have one capability wire.", 1, wires.size());
             assertEquals("Wrong provider.",
-                wires.get(0).getProviderWiring().getBundle(), m_bundles.get(B));
+                wires.get(0).getProviderWiring().getBundle(), getBundle("B"));
 
             // Refresh provider and make sure requirer is also refreshed.
-            refreshBundle(m_bundles.get(A));
+            refreshBundle(getBundle("A"));
             assertEquals("Provider should be installed.",
-                Bundle.INSTALLED, m_bundles.get(A).getState());
+                Bundle.INSTALLED, getBundle("A").getState());
             assertEquals("Requirer should be installed.",
-                Bundle.INSTALLED, m_bundles.get(B).getState());
+                Bundle.INSTALLED, getBundle("B").getState());
             assertEquals("Requirer should be installed.",
-                Bundle.INSTALLED, m_bundles.get(C).getState());
+                Bundle.INSTALLED, getBundle("C").getState());
         }
         finally
         {
-            cleanup();
+            cleanupBundles();
         }
 
         // Scenario #2
@@ -221,18 +215,18 @@ public class TestCapability extends Feli
         try
         {
             is = this.getClass().getClassLoader().getResourceAsStream("capability.b003a.jar");
-            m_bundles.add(getBundleContext().installBundle("capability.b003a.jar", is));
+            addBundle("A", getBundleContext().installBundle("capability.b003a.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("capability.b003b.jar");
-            m_bundles.add(getBundleContext().installBundle("capability.b003b.jar", is));
+            addBundle("B", getBundleContext().installBundle("capability.b003b.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("capability.b004.jar");
-            m_bundles.add(getBundleContext().installBundle("capability.b004.jar", is));
+            addBundle("C", getBundleContext().installBundle("capability.b004.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("capability.b005.jar");
-            m_bundles.add(getBundleContext().installBundle("capability.b005.jar", is));
+            addBundle("D", getBundleContext().installBundle("capability.b005.jar", is));
 
             try
             {
-                m_bundles.get(D).start();
-                m_bundles.get(D).stop();
+                getBundle("D").start();
+                getBundle("D").stop();
             }
             catch (BundleException ex)
             {
@@ -240,52 +234,35 @@ public class TestCapability extends Feli
             }
 
             // Check that bundle C is wired to bundle A.
-            BundleWiring bw = m_bundles.get(C).adapt(BundleWiring.class);
+            BundleWiring bw = getBundle("C").adapt(BundleWiring.class);
             List<BundleWire> wires = bw.getRequiredWires(null);
             assertEquals("Bundle should have one wire.", 1, wires.size());
             assertEquals("Wrong provider.",
-                wires.get(0).getProviderWiring().getBundle(), m_bundles.get(A));
+                wires.get(0).getProviderWiring().getBundle(), getBundle("A"));
 
             // Check that bundle D is wired to bundles A and C.
-            bw = m_bundles.get(D).adapt(BundleWiring.class);
+            bw = getBundle("D").adapt(BundleWiring.class);
             wires = bw.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
             assertEquals("Bundle should have one package wire.", 1, wires.size());
             assertEquals("Wrong provider.",
-                wires.get(0).getProviderWiring().getBundle(), m_bundles.get(A));
+                wires.get(0).getProviderWiring().getBundle(), getBundle("A"));
             wires = bw.getRequiredWires("capability.b004");
             assertEquals("Bundle should have one capability wire.", 1, wires.size());
             assertEquals("Wrong provider.",
-                wires.get(0).getProviderWiring().getBundle(), m_bundles.get(C));
+                wires.get(0).getProviderWiring().getBundle(), getBundle("C"));
 
             // Refresh provider and make sure requirer is also refreshed.
-            refreshBundle(m_bundles.get(A));
+            refreshBundle(getBundle("A"));
             assertEquals("Provider should be installed.",
-                Bundle.INSTALLED, m_bundles.get(A).getState());
+                Bundle.INSTALLED, getBundle("A").getState());
             assertEquals("Requirer should be installed.",
-                Bundle.INSTALLED, m_bundles.get(C).getState());
+                Bundle.INSTALLED, getBundle("C").getState());
             assertEquals("Requirer should be installed.",
-                Bundle.INSTALLED, m_bundles.get(D).getState());
+                Bundle.INSTALLED, getBundle("D").getState());
         }
         finally
         {
-            cleanup();
-        }
-    }
-
-    private void cleanup()
-    {
-        for (Bundle bundle : m_bundles)
-        {
-            try
-            {
-                bundle.uninstall();
-            }
-            catch (Exception ex)
-            {
-                // Ummm?
-            }
+            cleanupBundles();
         }
-        m_bundles.clear();
-        refreshFramework();
     }
 }

Modified: felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/TestResolver.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/TestResolver.java?rev=1195568&r1=1195567&r2=1195568&view=diff
==============================================================================
--- felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/TestResolver.java
(original)
+++ felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/TestResolver.java
Mon Oct 31 16:57:59 2011
@@ -26,11 +26,6 @@ import org.osgi.service.packageadmin.Pac
 
 public class TestResolver extends FelixTestCase
 {
-    private Bundle m_bundleA = null;
-    private Bundle m_bundleB = null;
-    private Bundle m_bundleC = null;
-    private Bundle m_bundleD = null;
-
     public void testResolverUses() throws Exception
     {
         InputStream is = null;
@@ -46,15 +41,15 @@ public class TestResolver extends FelixT
         try
         {
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b001.jar");
-            m_bundleA = getBundleContext().installBundle("resolver.b001.jar", is);
+            addBundle("A", getBundleContext().installBundle("resolver.b001.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b002.jar");
-            m_bundleB = getBundleContext().installBundle("resolver.b002.jar", is);
+            addBundle("B", getBundleContext().installBundle("resolver.b002.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b003.jar");
-            m_bundleC = getBundleContext().installBundle("resolver.b003.jar", is);
+            addBundle("C", getBundleContext().installBundle("resolver.b003.jar", is));
 
             try
             {
-                m_bundleC.start();
+                getBundle("C").start();
             }
             catch (BundleException ex)
             {
@@ -63,7 +58,7 @@ public class TestResolver extends FelixT
         }
         finally
         {
-            cleanup();
+            cleanupBundles();
         }
 
         // Scenario #2
@@ -78,23 +73,23 @@ public class TestResolver extends FelixT
         try
         {
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b001.jar");
-            m_bundleA = getBundleContext().installBundle("resolver.b001.jar", is);
+            addBundle("A", getBundleContext().installBundle("resolver.b001.jar", is));
             try
             {
-                m_bundleA.start();
+                getBundle("A").start();
             }
             catch (BundleException ex)
             {
                 fail("Bundle should resolve and start.");
             }
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b002.jar");
-            m_bundleB = getBundleContext().installBundle("resolver.b002.jar", is);
+            addBundle("B", getBundleContext().installBundle("resolver.b002.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b003.jar");
-            m_bundleC = getBundleContext().installBundle("resolver.b003.jar", is);
+            addBundle("C", getBundleContext().installBundle("resolver.b003.jar", is));
 
             try
             {
-                m_bundleC.start();
+                getBundle("C").start();
                 fail("Bundle should not resolve!");
             }
             catch (BundleException ex)
@@ -104,7 +99,7 @@ public class TestResolver extends FelixT
         }
         finally
         {
-            cleanup();
+            cleanupBundles();
         }
     }
 
@@ -122,15 +117,15 @@ public class TestResolver extends FelixT
         try
         {
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b006.jar");
-            m_bundleA = getBundleContext().installBundle("resolver.b006.jar", is);
+            addBundle("A", getBundleContext().installBundle("resolver.b006.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b007.jar");
-            m_bundleB = getBundleContext().installBundle("resolver.b007.jar", is);
+            addBundle("B", getBundleContext().installBundle("resolver.b007.jar", is));
 
-            m_bundleA.start();
+            getBundle("A").start();
 
             // Verify that bundle 6 has no wires to bundle 7.
             PackageAdmin pa = getPackageAdmin();
-            ExportedPackage[] eps = pa.getExportedPackages(m_bundleB);
+            ExportedPackage[] eps = pa.getExportedPackages(getBundle("B"));
             if (eps != null)
             {
                 for (int i = 0; i < eps.length; i++)
@@ -138,7 +133,7 @@ public class TestResolver extends FelixT
                     Bundle[] importers = eps[i].getImportingBundles();
                     for (int j = 0; (importers != null) && (j < importers.length);
j++)
                     {
-                        if (importers[j].equals(m_bundleA))
+                        if (importers[j].equals(getBundle("A")))
                         {
                             throw new Exception("No wires should exist!");
                         }
@@ -148,7 +143,7 @@ public class TestResolver extends FelixT
         }
         finally
         {
-            cleanup();
+            cleanupBundles();
         }
     }
 /*
@@ -169,7 +164,7 @@ public class TestResolver extends FelixT
         try
         {
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b004.jar");
-            m_bundleA = getBundleContext().installBundle("resolver.b004.jar", is);
+            addBundle(getBundleContext().installBundle("resolver.b004.jar", is));
 
             m_bundleA.start();
 
@@ -194,7 +189,7 @@ public class TestResolver extends FelixT
             // Install a system bundle extension that exports Felix
             // framework package.
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b005.jar");
-            m_bundleB = getBundleContext().installBundle("resolver.b005.jar", is);
+            addBundle(getBundleContext().installBundle("resolver.b005.jar", is));
             // Now attempt to load the framework class, which should succeed.
             m_bundleA.loadClass("org.apache.felix.framework.Felix");
         }
@@ -226,15 +221,15 @@ public class TestResolver extends FelixT
         try
         {
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b008.jar");
-            m_bundleA = getBundleContext().installBundle("resolver.b008.jar", is);
+            addBundle("A", getBundleContext().installBundle("resolver.b008.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b009.jar");
-            m_bundleB = getBundleContext().installBundle("resolver.b009.jar", is);
+            addBundle("B", getBundleContext().installBundle("resolver.b009.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b010.jar");
-            m_bundleC = getBundleContext().installBundle("resolver.b010.jar", is);
+            addBundle("C", getBundleContext().installBundle("resolver.b010.jar", is));
 
             try
             {
-                m_bundleA.start();
+                getBundle("A").start();
                 assertTrue("Bundle should not resolve.", false);
             }
             catch (BundleException ex)
@@ -243,11 +238,12 @@ public class TestResolver extends FelixT
                 // resolve.
             }
             // Verify the bundle's state is still resolved.
-            assertEquals("Bundle state should be installed.", Bundle.INSTALLED, m_bundleA.getState());
+            assertEquals("Bundle state should be installed.",
+                Bundle.INSTALLED, getBundle("A").getState());
         }
         finally
         {
-            cleanup();
+            cleanupBundles();
         }
     }
 
@@ -265,28 +261,29 @@ public class TestResolver extends FelixT
         try
         {
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b011.jar");
-            m_bundleA = getBundleContext().installBundle("resolver.b011.jar", is);
+            addBundle("A", getBundleContext().installBundle("resolver.b011.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b012.jar");
-            m_bundleB = getBundleContext().installBundle("resolver.b012.jar", is);
+            addBundle("B", getBundleContext().installBundle("resolver.b012.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b013.jar");
-            m_bundleC = getBundleContext().installBundle("resolver.b013.jar", is);
+            addBundle("C", getBundleContext().installBundle("resolver.b013.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b014.jar");
-            m_bundleD = getBundleContext().installBundle("resolver.b014.jar", is);
+            addBundle("D", getBundleContext().installBundle("resolver.b014.jar", is));
 
             try
             {
-                m_bundleD.start();
+                getBundle("D").start();
             }
             catch (BundleException ex)
             {
                 assertTrue("Bundle should resolve: " + ex, false);
             }
             // Verify the bundle's state is active.
-            assertEquals("Bundle state should be active.", Bundle.ACTIVE, m_bundleD.getState());
+            assertEquals("Bundle state should be active.",
+                Bundle.ACTIVE, getBundle("D").getState());
         }
         finally
         {
-            cleanup();
+            cleanupBundles();
         }
     }
 
@@ -303,18 +300,19 @@ public class TestResolver extends FelixT
         try
         {
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b015.jar");
-            m_bundleA = getBundleContext().installBundle("resolver.b015.jar", is);
+            addBundle("A", getBundleContext().installBundle("resolver.b015.jar", is));
 
             try
             {
-                m_bundleA.start();
+                getBundle("A").start();
             }
             catch (BundleException ex)
             {
                 assertTrue("Bundle should resolve: " + ex, false);
             }
             // Verify the bundle's state is active.
-            assertEquals("Bundle state should be active.", Bundle.ACTIVE, m_bundleA.getState());
+            assertEquals("Bundle state should be active.",
+                Bundle.ACTIVE, getBundle("A").getState());
 
             PackageAdmin pa = getPackageAdmin();
 
@@ -330,7 +328,7 @@ public class TestResolver extends FelixT
             assertNotNull("No importer for javax.swing", importers);
             assertEquals("Only one bundle should be importing javax.swing", 1, eps.length);
             assertEquals("Bundle should be importing of javax.swing",
-                m_bundleA.getBundleId(), importers[0].getBundleId());
+                getBundle("A").getBundleId(), importers[0].getBundleId());
 
             // Get exporter of org.apache.felix.framework.test.resolver.b015.
             eps = pa.getExportedPackages("org.apache.felix.framework.test.resolver.b015");
@@ -338,14 +336,14 @@ public class TestResolver extends FelixT
             assertNotNull("There should be a package exporter", eps);
             assertEquals("There should be only one package exporter", 1, eps.length);
             assertEquals("The test bundle should be the package exporter",
-                m_bundleA.getBundleId(), eps[0].getExportingBundle().getBundleId());
+                getBundle("A").getBundleId(), eps[0].getExportingBundle().getBundleId());
             // No one should be importing org.apache.felix.framework.test.resolver.b015.
             importers = eps[0].getImportingBundles();
             assertEquals("No one should be importing package", 0, importers.length);
         }
         finally
         {
-            cleanup();
+            cleanupBundles();
         }
     }
 
@@ -361,90 +359,37 @@ public class TestResolver extends FelixT
         try
         {
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b016a.jar");
-            m_bundleA = getBundleContext().installBundle("resolver.b016a.jar", is);
+            addBundle("A", getBundleContext().installBundle("resolver.b016a.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b016b.jar");
-            m_bundleB = getBundleContext().installBundle("resolver.b016b.jar", is);
+            addBundle("B", getBundleContext().installBundle("resolver.b016b.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b017.jar");
-            m_bundleC = getBundleContext().installBundle("resolver.b017.jar", is);
+            addBundle("C", getBundleContext().installBundle("resolver.b017.jar", is));
             is = this.getClass().getClassLoader().getResourceAsStream("resolver.b018.jar");
-            m_bundleD = getBundleContext().installBundle("resolver.b018.jar", is);
+            addBundle("D", getBundleContext().installBundle("resolver.b018.jar", is));
 
             assertTrue("Bundle should resolve",
-                getPackageAdmin().resolveBundles(new Bundle[] { m_bundleA }));
+                getPackageAdmin().resolveBundles(new Bundle[] { getBundle("A") }));
             assertEquals("Bundle state should be resolved.",
-                Bundle.RESOLVED, m_bundleA.getState());
+                Bundle.RESOLVED, getBundle("A").getState());
 
             assertTrue("Bundle should resolve",
-                getPackageAdmin().resolveBundles(new Bundle[] { m_bundleB }));
+                getPackageAdmin().resolveBundles(new Bundle[] { getBundle("B") }));
             assertEquals("Bundle state should be resolved.",
-                Bundle.RESOLVED, m_bundleB.getState());
+                Bundle.RESOLVED, getBundle("B").getState());
 
             assertTrue("Bundle should resolve",
-                getPackageAdmin().resolveBundles(new Bundle[] { m_bundleC }));
+                getPackageAdmin().resolveBundles(new Bundle[] { getBundle("C") }));
             assertEquals("Bundle state should be resolved.",
-                Bundle.RESOLVED, m_bundleC.getState());
+                Bundle.RESOLVED, getBundle("C").getState());
 
             assertFalse("Bundle should not resolve",
-                getPackageAdmin().resolveBundles(new Bundle[] { m_bundleD }));
+                getPackageAdmin().resolveBundles(new Bundle[] { getBundle("D") }));
             assertEquals("Bundle state should be installed.",
-                Bundle.INSTALLED, m_bundleD.getState());
+                Bundle.INSTALLED, getBundle("D").getState());
         }
         finally
         {
-            cleanup();
-        }
-    }
-
-    private void cleanup()
-    {
-        if (m_bundleA != null)
-        {
-            try
-            {
-                m_bundleA.uninstall();
-            }
-            catch (Exception ex)
-            {
-                // Ummm?
-            }
-            m_bundleA = null;
-        }
-        if (m_bundleB != null)
-        {
-            try
-            {
-                m_bundleB.uninstall();
-            }
-            catch (Exception ex)
-            {
-                // Ummm?
-            }
-            m_bundleB = null;
-        }
-        if (m_bundleC != null)
-        {
-            try
-            {
-                m_bundleC.uninstall();
-            }
-            catch (Exception ex)
-            {
-                // Ummm?
-            }
-            m_bundleC = null;
-        }
-        if (m_bundleD != null)
-        {
-            try
-            {
-                m_bundleD.uninstall();
-            }
-            catch (Exception ex)
-            {
-                // Ummm?
-            }
-            m_bundleD = null;
+            cleanupBundles();
         }
-        refreshFramework();
     }
 }



Mime
View raw message