[jboss-cvs] JBossAS SVN: r100378 - in projects/jboss-osgi: trunk/testsuite/functional/scripts and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 3 17:24:32 EST 2010
Author: thomas.diesler at jboss.com
Date: 2010-02-03 17:24:32 -0500 (Wed, 03 Feb 2010)
New Revision: 100378
Added:
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi287/
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi287/OSGi287TestCase.java
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi287/bundleA/
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi287/bundleA/OSGi287BeanA.java
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi287/bundleB/
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi287/bundleB/OSGi287BeanB.java
projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi287/
projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi287/jbosgi287-bundleA.bnd
projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi287/jbosgi287-bundleB.bnd
Modified:
projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedBundle.java
projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml
Log:
[JBOSGI-287] Optional import loaded from system classloader
Modified: projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedBundle.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedBundle.java 2010-02-03 22:21:30 UTC (rev 100377)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedBundle.java 2010-02-03 22:24:32 UTC (rev 100378)
@@ -133,10 +133,10 @@
public OSGiBundle loadClass(String name) throws ClassNotFoundException
{
Class<?> clazz = bundle.loadClass(name);
- BundleContext context = bundle.getBundleContext();
- ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
- PackageAdmin packageAdmin = (PackageAdmin)context.getService(sref);
- Bundle providerBundle = packageAdmin.getBundle(clazz);
+ Bundle providerBundle = getPackageAdmin().getBundle(clazz);
+ if (providerBundle == null)
+ return null;
+
return getRuntime().getBundle(providerBundle.getBundleId());
}
@@ -186,4 +186,10 @@
}
}
+ private PackageAdmin getPackageAdmin()
+ {
+ BundleContext context = ((EmbeddedRuntime)getRuntime()).getSystemContext();
+ ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
+ return (PackageAdmin)context.getService(sref);
+ }
}
Modified: projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml 2010-02-03 22:21:30 UTC (rev 100377)
+++ projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml 2010-02-03 22:24:32 UTC (rev 100378)
@@ -27,6 +27,7 @@
[JBOSGI-214] Cannot repeatedly register service bound to an interface from the system classpath
[JBOSGI-284] Investigate version numbering scheme
[JBOSGI-286] Investigate classloading of javax.* classes
+ [JBOSGI-287] Optional import loaded from system classloader
-->
@@ -167,6 +168,10 @@
<!-- jbosgi286 -->
<bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jbosgi286-bundle.jar" files="${tests.resources.dir}/jbosgi286/jbosgi286-bundle.bnd" />
+ <!-- jbosgi287 -->
+ <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jbosgi287-bundleA.jar" files="${tests.resources.dir}/jbosgi287/jbosgi287-bundleA.bnd" />
+ <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jbosgi287-bundleB.jar" files="${tests.resources.dir}/jbosgi287/jbosgi287-bundleB.bnd" />
+
<!-- localization -->
<bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/localization-simple-host.jar" files="${tests.resources.dir}/localization/localization-simple-host.bnd" />
<bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/localization-simple-frag.jar" files="${tests.resources.dir}/localization/localization-simple-frag.bnd" />
Added: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi287/OSGi287TestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi287/OSGi287TestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi287/OSGi287TestCase.java 2010-02-03 22:24:32 UTC (rev 100378)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.jbosgi287;
+
+//$Id: OSGi284TestCase.java 100204 2010-02-01 10:14:11Z thomas.diesler at jboss.com $
+
+import static org.junit.Assert.*;
+
+import org.jboss.osgi.testing.OSGiBundle;
+import org.jboss.osgi.testing.OSGiRuntime;
+import org.jboss.osgi.testing.OSGiTest;
+import org.jboss.test.osgi.jbosgi287.bundleA.OSGi287BeanA;
+import org.jboss.test.osgi.jbosgi287.bundleB.OSGi287BeanB;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+
+/**
+ * [JBOSGI-287] Optional import loaded from system classloader
+ *
+ * https://jira.jboss.org/jira/browse/JBOSGI-287
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 01-Feb-2010
+ */
+public class OSGi287TestCase extends OSGiTest
+{
+ @Test
+ public void testUnresolvedOptionalImport() throws Exception
+ {
+ OSGiRuntime runtime = getDefaultRuntime();
+ try
+ {
+ // Bundle-SymbolicName: jbosgi287-bundleA
+ // Export-Package: org.jboss.test.osgi.jbosgi287.bundleA
+ // Import-Package: org.jboss.test.osgi.jbosgi287.bundleB;resolution:=optional
+ OSGiBundle bundleA = runtime.installBundle("jbosgi287-bundleA.jar");
+ OSGiBundle exporterA = bundleA.loadClass(OSGi287BeanA.class.getName());
+ assertEquals(Bundle.RESOLVED, bundleA.getState());
+ assertEquals(bundleA, exporterA);
+
+ try
+ {
+ bundleA.loadClass(OSGi287BeanB.class.getName());
+ fail("ClassNotFoundException expected");
+ }
+ catch (ClassNotFoundException ex)
+ {
+ // expected
+ }
+ }
+ finally
+ {
+ runtime.shutdown();
+ }
+ }
+
+ @Test
+ public void testResolvedOptionalImport() throws Exception
+ {
+ OSGiRuntime runtime = getDefaultRuntime();
+ try
+ {
+ // Bundle-SymbolicName: jbosgi287-bundleB
+ // Export-Package: org.jboss.test.osgi.jbosgi287.bundleB
+ OSGiBundle bundleB = runtime.installBundle("jbosgi287-bundleB.jar");
+
+ // Bundle-SymbolicName: jbosgi287-bundleA
+ // Export-Package: org.jboss.test.osgi.jbosgi287.bundleA
+ // Import-Package: org.jboss.test.osgi.jbosgi287.bundleB;resolution:=optional
+ OSGiBundle bundleA = runtime.installBundle("jbosgi287-bundleA.jar");
+
+ OSGiBundle exporterB = bundleB.loadClass(OSGi287BeanB.class.getName());
+ assertEquals(Bundle.RESOLVED, bundleB.getState());
+ assertEquals(bundleB, exporterB);
+
+ OSGiBundle exporterA = bundleA.loadClass(OSGi287BeanA.class.getName());
+ assertEquals(Bundle.RESOLVED, bundleA.getState());
+ assertEquals(bundleA, exporterA);
+
+ // Load B through A
+ exporterB = bundleA.loadClass(OSGi287BeanB.class.getName());
+ assertEquals(bundleB, exporterB);
+ }
+ finally
+ {
+ runtime.shutdown();
+ }
+ }
+
+
+ @Test
+ public void testResolvedOptionalImportReverse() throws Exception
+ {
+ OSGiRuntime runtime = getDefaultRuntime();
+ try
+ {
+ // Bundle-SymbolicName: jbosgi287-bundleA
+ // Export-Package: org.jboss.test.osgi.jbosgi287.bundleA
+ // Import-Package: org.jboss.test.osgi.jbosgi287.bundleB;resolution:=optional
+ OSGiBundle bundleA = runtime.installBundle("jbosgi287-bundleA.jar");
+
+ // Bundle-SymbolicName: jbosgi287-bundleB
+ // Export-Package: org.jboss.test.osgi.jbosgi287.bundleB
+ OSGiBundle bundleB = runtime.installBundle("jbosgi287-bundleB.jar");
+
+ OSGiBundle exporterA = bundleA.loadClass(OSGi287BeanA.class.getName());
+ assertEquals(Bundle.RESOLVED, bundleA.getState());
+ assertEquals(bundleA, exporterA);
+
+ OSGiBundle exporterB = bundleB.loadClass(OSGi287BeanB.class.getName());
+ assertEquals(Bundle.RESOLVED, bundleB.getState());
+ assertEquals(bundleB, exporterB);
+
+ // Load B through A
+ exporterB = bundleA.loadClass(OSGi287BeanB.class.getName());
+ assertEquals(bundleB, exporterB);
+ }
+ finally
+ {
+ runtime.shutdown();
+ }
+ }
+}
\ No newline at end of file
Added: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi287/bundleA/OSGi287BeanA.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi287/bundleA/OSGi287BeanA.java (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi287/bundleA/OSGi287BeanA.java 2010-02-03 22:24:32 UTC (rev 100378)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.jbosgi287.bundleA;
+
+//$Id: $
+
+
+public class OSGi287BeanA
+{
+ public OSGi287BeanA()
+ {
+ }
+}
Added: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi287/bundleB/OSGi287BeanB.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi287/bundleB/OSGi287BeanB.java (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi287/bundleB/OSGi287BeanB.java 2010-02-03 22:24:32 UTC (rev 100378)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.jbosgi287.bundleB;
+
+//$Id: $
+
+
+public class OSGi287BeanB
+{
+ public OSGi287BeanB()
+ {
+ }
+}
Added: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi287/jbosgi287-bundleA.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi287/jbosgi287-bundleA.bnd (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi287/jbosgi287-bundleA.bnd 2010-02-03 22:24:32 UTC (rev 100378)
@@ -0,0 +1,6 @@
+# bnd build -classpath target/test-classes -output target/test-libs/jbosgi287-bundleA.jar src/test/resources/jbosgi287/bundle.bnd
+
+Bundle-SymbolicName: jbosgi287-bundleA
+Export-Package: org.jboss.test.osgi.jbosgi287.bundleA
+Import-Package: org.jboss.test.osgi.jbosgi287.bundleB;resolution:=optional
+
Added: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi287/jbosgi287-bundleB.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi287/jbosgi287-bundleB.bnd (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi287/jbosgi287-bundleB.bnd 2010-02-03 22:24:32 UTC (rev 100378)
@@ -0,0 +1,5 @@
+# bnd build -classpath target/test-classes -output target/test-libs/jbosgi287-bundleB.jar src/test/resources/jbosgi287/jbosgi287-bundle.bnd
+
+Bundle-SymbolicName: jbosgi287-bundleB
+Export-Package: org.jboss.test.osgi.jbosgi287.bundleB
+
More information about the jboss-cvs-commits
mailing list