Permalink
Browse files

Make JMX test cases independent of org.osgi.enterprise

  • Loading branch information...
1 parent 32c26dd commit 5ab42eb223ed5bd1aa22f2d0745807851ff171b0 @tdiesler tdiesler committed Oct 22, 2012
@@ -21,17 +21,17 @@
*/
package org.jboss.test.osgi;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.ServiceReference;
-
-import javax.management.MBeanServer;
import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+
/**
+ * Provide the org.apache.aries.jmx bundle
+ *
* @author thomas.diesler@jboss.com
* @since 26-Jan-2012
*/
@@ -40,18 +40,16 @@
public static final String APACHE_ARIES_JMX = "org.apache.aries.jmx:org.apache.aries.jmx";
public static final String JBOSS_OSGI_JMX = "org.jboss.osgi.jmx:jbosgi-jmx";
- public static MBeanServer provideMBeanServer(BundleContext syscontext, Bundle bundle) throws BundleException {
+ public static void provideMBeanServer(BundleContext syscontext, Bundle bundle) throws BundleException {
AriesSupport.provideAriesUtil(syscontext, bundle);
if (getPackageAdmin(syscontext).getBundles("jbosgi-jmx", null) == null) {
installSupportBundle(syscontext, getCoordinates(bundle, APACHE_ARIES_JMX)).start();
installSupportBundle(syscontext, getCoordinates(bundle, JBOSS_OSGI_JMX)).start();
}
- ServiceReference sref = syscontext.getServiceReference(MBeanServer.class.getName());
- return (MBeanServer) syscontext.getService(sref);
}
public static <T> T getMBeanProxy(MBeanServerConnection server, ObjectName name, Class<T> interf)
{
- return (T) MBeanServerInvocationHandler.newProxyInstance(server, name, interf, false);
+ return MBeanServerInvocationHandler.newProxyInstance(server, name, interf, false);
}
}
@@ -28,24 +28,30 @@
import org.osgi.service.jndi.JNDIContextManager;
/**
+ * Provide the org.apache.aries.jndi bundle
+ *
* @author David Bosschaert
* @author Thomas.Diesler@jboss.com
*/
public class NamingSupport extends RepositorySupport {
+
+ public static final String CONTEXT_MANAGER_SERVICE = "org.osgi.service.jndi.JNDIContextManager";
public static final String APACHE_ARIES_JNDI = "org.apache.aries.jndi:org.apache.aries.jndi";
- public static JNDIContextManager provideJNDIIntegration(BundleContext syscontext, Bundle bundle) throws BundleException {
- BundleContext context = bundle.getBundleContext();
- ServiceReference sref = context.getServiceReference(JNDIContextManager.class.getName());
+ public static void provideJNDIIntegration(BundleContext syscontext, Bundle bundle) throws BundleException {
+ ServiceReference sref = syscontext.getServiceReference(CONTEXT_MANAGER_SERVICE);
if (sref == null) {
AriesSupport.provideAriesUtil(syscontext, bundle);
-
- // Version 0.3.1 of Aries JNDI depends on Aries Blueprint.
+ AriesSupport.provideAriesProxy(syscontext, bundle);
+ // Version 1.0.0 depends on Blueprint
BlueprintSupport.provideBlueprint(syscontext, bundle);
-
installSupportBundle(syscontext, getCoordinates(bundle, APACHE_ARIES_JNDI)).start();
- sref = context.getServiceReference(JNDIContextManager.class.getName());
}
+ }
+
+ public static JNDIContextManager getContextManager(Bundle bundle) {
+ BundleContext context = bundle.getBundleContext();
+ ServiceReference sref = context.getServiceReference(JNDIContextManager.class.getName());
return (JNDIContextManager) context.getService(sref);
}
}
@@ -33,43 +33,44 @@
/**
* Add support for injected PackageAdmin
- *
+ *
* @author thomas.diesler@jboss.com
* @since 07-Jun-2011
*/
@RunWith(Arquillian.class)
public class PackageAdminTestCase {
- @ArquillianResource
- Bundle bundle;
+ private static final String BUNDLE_A = "packageadmin-bundle";
@ArquillianResource
PackageAdmin packageAdmin;
@Deployment
public static JavaArchive create() {
- final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "package-admin-bundle");
+ final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, BUNDLE_A);
archive.setManifest(new Asset() {
+ @Override
public InputStream openStream() {
OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
builder.addBundleSymbolicName(archive.getName());
builder.addBundleManifestVersion(2);
+ builder.addImportPackages(PackageAdmin.class);
return builder.openStream();
}
});
return archive;
}
@Test
- public void testPackageAdmin() throws Exception {
+ public void testPackageAdmin(@ArquillianResource Bundle bundle) throws Exception {
Assert.assertNotNull("PackageAdmin injected", packageAdmin);
- Bundle[] bundles = packageAdmin.getBundles("package-admin-bundle", null);
+ Bundle[] bundles = packageAdmin.getBundles(BUNDLE_A, null);
Assert.assertNotNull("Bundles not null", bundles);
Assert.assertEquals("One bundle found", 1, bundles.length);
- Assert.assertEquals("package-admin-bundle", bundle.getSymbolicName());
+ Assert.assertEquals(BUNDLE_A, bundle.getSymbolicName());
Assert.assertEquals(bundle, bundles[0]);
}
}
@@ -56,7 +56,7 @@
/**
* Test {@link BundleStateMBean} functionality
- *
+ *
* @author thomas.diesler@jboss.com
* @since 15-Feb-2010
*/
@@ -68,9 +68,6 @@
@ArquillianResource
BundleContext context;
- @ArquillianResource
- PackageAdmin packageAdmin;
-
@Deployment(name = JMX_PROVIDER)
public static JavaArchive jmxProvider() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, JMX_PROVIDER);
@@ -82,8 +79,9 @@ public InputStream openStream() {
OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
builder.addBundleSymbolicName(archive.getName());
builder.addBundleManifestVersion(2);
- builder.addImportPackages(BundleStateMBean.class, MBeanServer.class, TabularData.class);
builder.addImportPackages(XRequirementBuilder.class, XRequirement.class, Repository.class, Resource.class);
+ builder.addImportPackages(PackageAdmin.class, MBeanServer.class, TabularData.class);
+ builder.addDynamicImportPackages(BundleStateMBean.class.getPackage().getName());
return builder.openStream();
}
});
@@ -92,8 +90,7 @@ public InputStream openStream() {
@Test
@InSequence(0)
- public void addJMXSupport() throws BundleException {
- Bundle bundle = packageAdmin.getBundles(JMX_PROVIDER, null)[0];
+ public void addJMXSupport(@ArquillianResource Bundle bundle) throws BundleException {
JMXSupport.provideMBeanServer(context, bundle);
}
@@ -104,7 +101,7 @@ public void testBundleStateMBean() throws Exception {
ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
MBeanServer server = (MBeanServer) context.getService(sref);
- ObjectName oname = ObjectName.getInstance(BundleStateMBean.OBJECTNAME);
+ ObjectName oname = ObjectName.getInstance("osgi.core:type=bundleState,version=1.5");
BundleStateMBean bundleState = JMXSupport.getMBeanProxy(server, oname, BundleStateMBean.class);
assertNotNull("BundleStateMBean not null", bundleState);
@@ -59,7 +59,7 @@
/**
* A test that deployes a bundle that registeres an MBean
- *
+ *
* @author thomas.diesler@jboss.com
* @since 12-Feb-2009
*/
@@ -75,9 +75,6 @@
@ArquillianResource
BundleContext context;
- @ArquillianResource
- PackageAdmin packageAdmin;
-
@Deployment(name = JMX_PROVIDER)
public static JavaArchive jmxProvider() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, JMX_PROVIDER);
@@ -91,7 +88,7 @@ public InputStream openStream() {
builder.addBundleSymbolicName(archive.getName());
builder.addBundleManifestVersion(2);
builder.addImportPackages(XRequirementBuilder.class, XRequirement.class, Repository.class, Resource.class);
- builder.addImportPackages(MBeanServer.class, ServiceTracker.class);
+ builder.addImportPackages(PackageAdmin.class, MBeanServer.class, ServiceTracker.class);
builder.addExportPackages(FooMBean.class);
return builder.openStream();
}
@@ -103,6 +100,7 @@ public InputStream openStream() {
public static JavaArchive testBundle() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, JMX_BUNDLE);
archive.setManifest(new Asset() {
+ @Override
public InputStream openStream() {
OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
builder.addBundleSymbolicName(archive.getName());
@@ -118,8 +116,7 @@ public InputStream openStream() {
@Test
@InSequence(0)
- public void addJMXSupport() throws BundleException {
- Bundle bundle = packageAdmin.getBundles(JMX_PROVIDER, null)[0];
+ public void addJMXSupport(@ArquillianResource Bundle bundle) throws BundleException {
JMXSupport.provideMBeanServer(context, bundle);
}
Oops, something went wrong.

0 comments on commit 5ab42eb

Please sign in to comment.