felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r811033 - in /felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test: bnd.bnd src/org/apache/felix/framework/test/TestClassLoading.java
Date Thu, 03 Sep 2009 17:03:58 GMT
Author: rickhall
Date: Thu Sep  3 17:03:58 2009
New Revision: 811033

URL: http://svn.apache.org/viewvc?rev=811033&view=rev
Log:
Added test case for dynamic imports and getResources().

Modified:
    felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/bnd.bnd
    felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/TestClassLoading.java

Modified: felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/bnd.bnd
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/bnd.bnd?rev=811033&r1=811032&r2=811033&view=diff
==============================================================================
--- felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/bnd.bnd (original)
+++ felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/bnd.bnd Thu Sep  3 17:03:58
2009
@@ -1,6 +1,8 @@
 Private-Package: ${p}
 Include-Resource: \
+ src/resource/jbosgi142-bundleX.jar, src/resource/jbosgi142-bundleB.jar, src/resource/jbosgi142-bundleA.jar,
\
  classloading.b001.jar, classloading.b002.jar, classloading.b003.jar, \
+ classloading.b004.jar, \
  concurrency.b1.jar, \
  resolver.b001.jar, resolver.b002.jar, resolver.b003.jar, resolver.b004.jar, \
  resolver.b005.jar, resolver.b006.jar, resolver.b007.jar, resolver.b008.jar, \

Modified: felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/TestClassLoading.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/TestClassLoading.java?rev=811033&r1=811032&r2=811033&view=diff
==============================================================================
--- felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/TestClassLoading.java
(original)
+++ felix/sandbox/rickhall/bnd-test/org.apache.felix.framework.test/src/org/apache/felix/framework/test/TestClassLoading.java
Thu Sep  3 17:03:58 2009
@@ -19,6 +19,7 @@
 package org.apache.felix.framework.test;
 
 import java.io.InputStream;
+import java.util.Enumeration;
 import org.osgi.framework.Bundle;
 
 public class TestClassLoading extends FelixTestCase
@@ -101,6 +102,117 @@
         }
     }
 
+    public void testImportClassLoad() throws Exception
+    {
+        try
+        {
+            // Load some bundles that export some packages.
+            InputStream is = this.getClass().getClassLoader().getResourceAsStream("classloading.b002.jar");
+            m_bundleA = getBundleContext().installBundle("classloading.b002.jar", is);
+            is = this.getClass().getClassLoader().getResourceAsStream("classloading.b003.jar");
+            m_bundleB = getBundleContext().installBundle("classloading.b003.jar", is);
+
+            // Load a bundle that imports from bundle B.
+            is = this.getClass().getClassLoader().getResourceAsStream("classloading.b004.jar");
+            m_bundleC = getBundleContext().installBundle("classloading.b004.jar", is);
+
+            Class clazz;
+            try
+            {
+                clazz = m_bundleC.loadClass("org.apache.felix.framework.test.classloading.b003.CycleB");
+            }
+            catch (Exception ex)
+            {
+                assertTrue("Imported class should be visible.", false);
+            }
+            try
+            {
+                clazz = m_bundleB.loadClass("org.apache.felix.framework.test.classloading.b004.B004Class");
+                assertTrue("Importer's class should NOT be visible.", false);
+            }
+            catch (Exception ex)
+            {
+            }
+        }
+        finally
+        {
+            cleanup();
+        }
+    }
+
+    public void testImportClassLoad2() throws Exception
+    {
+        try
+        {
+            InputStream is = this.getClass().getClassLoader().getResourceAsStream("jbosgi142-bundleX.jar");
+            m_bundleA = getBundleContext().installBundle("jbosgi142-bundleX.jar", is);
+            m_bundleA.start();
+            is = this.getClass().getClassLoader().getResourceAsStream("jbosgi142-bundleA.jar");
+            m_bundleB = getBundleContext().installBundle("jbosgi142-bundleA.jar", is);
+            m_bundleB.start();
+            is = this.getClass().getClassLoader().getResourceAsStream("jbosgi142-bundleB.jar");
+            m_bundleC = getBundleContext().installBundle("jbosgi142-bundleB.jar", is);
+            m_bundleC.start();
+
+            Class clazz;
+            try
+            {
+                clazz = m_bundleC.loadClass("org.jboss.test.osgi.jbosgi142.bundleX.BeanX");
+            }
+            catch (Exception ex)
+            {
+                assertTrue("Imported class should be visible.", false);
+            }
+            try
+            {
+                clazz = m_bundleA.loadClass("org.jboss.test.osgi.jbosgi142.bundleA.BeanA");
+                assertTrue("Importer's class should NOT be visible.", false);
+            }
+            catch (Exception ex)
+            {
+                System.out.println(ex);
+            }
+        }
+        finally
+        {
+            cleanup();
+        }
+    }
+
+    public void testGetResourcesDynamic() throws Exception
+    {
+        try
+        {
+            // Load some bundles that export some packages.
+            InputStream is = this.getClass().getClassLoader().getResourceAsStream("classloading.b002.jar");
+            m_bundleA = getBundleContext().installBundle("classloading.b002.jar", is);
+            is = this.getClass().getClassLoader().getResourceAsStream("classloading.b003.jar");
+            m_bundleB = getBundleContext().installBundle("classloading.b003.jar", is);
+
+            // Load a bundle that imports from bundle B.
+            is = this.getClass().getClassLoader().getResourceAsStream("classloading.b004.jar");
+            m_bundleC = getBundleContext().installBundle("classloading.b004.jar", is);
+
+            Enumeration e;
+            try
+            {
+                e = m_bundleC.getResources("org/apache/felix/framework/test/classloading/b002/CycleAAA.class");
+                assertNotNull("Enumeration should not be null.", e);
+                assertEquals(true, e.hasMoreElements());
+                e.nextElement();
+                assertEquals(false, e.hasMoreElements());
+            }
+            catch (Exception ex)
+            {
+                assertTrue("Resource should be visible.", false);
+            }
+        }
+        finally
+        {
+            cleanup();
+        }
+    }
+
     private void cleanup()
     {
         if (m_bundleA != null)



Mime
View raw message