Browse files

Make BlueprintTestCase independent of org.osgi.enterprise

  • Loading branch information...
1 parent 9074936 commit 32c26dd999bfbf3cda85028c16559e74d79b9841 @tdiesler tdiesler committed Oct 22, 2012
View
2 pom.xml
@@ -63,7 +63,7 @@
<version.javax.transaction.api>1.0.1.Final</version.javax.transaction.api>
<version.jbossas.720>7.2.0.Alpha1-SNAPSHOT</version.jbossas.720>
<version.jboss.arquillian.core>1.0.0.Final</version.jboss.arquillian.core>
- <version.jboss.arquillian.osgi>1.0.3.CR1</version.jboss.arquillian.osgi>
+ <version.jboss.arquillian.osgi>1.0.3.CR2-SNAPSHOT</version.jboss.arquillian.osgi>
<version.jboss.logging>3.1.2.GA</version.jboss.logging>
<version.jboss.logging.processor>1.1.0.Beta1</version.jboss.logging.processor>
<version.jboss.logmanager>1.4.0.Beta1</version.jboss.logmanager>
View
15 testsuite/example/src/main/java/org/jboss/test/osgi/BlueprintSupport.java
@@ -25,8 +25,14 @@
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.util.tracker.ServiceTracker;
/**
+ * Provide the org.apache.aries.blueprint bundle
+ *
* @author Thomas.Diesler@jboss.com
* @since 28-Jan-2012
*/
@@ -40,4 +46,13 @@ public static void provideBlueprint(BundleContext syscontext, Bundle bundle) thr
installSupportBundle(syscontext, getCoordinates(bundle, APACHE_ARIES_BLUEPRINT)).start();
}
}
+
+ public static BlueprintContainer getBlueprintContainer(Bundle bundle) throws Exception {
+ String objectclass = "(objectclass=" + BlueprintContainer.class.getName() + ")";
+ String symbolicname = "(osgi.blueprint.container.symbolicname=" + bundle.getSymbolicName() + ")";
+ Filter filter = FrameworkUtil.createFilter("(&" + objectclass + symbolicname + ")");
+ ServiceTracker tracker = new ServiceTracker(bundle.getBundleContext(), filter, null);
+ tracker.open();
+ return (BlueprintContainer) tracker.waitForService(10000);
+ }
}
View
39 testsuite/example/src/test/java/org/jboss/test/osgi/example/blueprint/BlueprintTestCase.java
@@ -51,8 +51,6 @@
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
-import org.osgi.framework.Filter;
-import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import org.osgi.resource.Resource;
import org.osgi.service.blueprint.container.BlueprintContainer;
@@ -62,7 +60,7 @@
/**
* A simple Blueprint Container test.
- *
+ *
* @author thomas.diesler@jboss.com
* @since 12-Jul-2009
*/
@@ -78,22 +76,22 @@
@ArquillianResource
BundleContext context;
- @ArquillianResource
- PackageAdmin packageAdmin;
-
@Deployment(name = BLUEPRINT_PROVIDER)
public static JavaArchive blueprintProvider() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, BLUEPRINT_PROVIDER);
archive.addClasses(JMXSupport.class, BlueprintSupport.class, AriesSupport.class, RepositorySupport.class);
archive.addClasses(BeanA.class, ServiceA.class, BeanB.class, ServiceB.class);
archive.addAsManifestResource(RepositorySupport.BUNDLE_VERSIONS_FILE);
archive.setManifest(new Asset() {
+ @Override
public InputStream openStream() {
OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
builder.addBundleSymbolicName(archive.getName());
builder.addBundleManifestVersion(2);
builder.addImportPackages(XRequirementBuilder.class, XRequirement.class, Repository.class, Resource.class);
- builder.addImportPackages(PackageAdmin.class, MBeanServer.class, ServiceTracker.class);
+ builder.addDynamicImportPackages(BlueprintContainer.class.getPackage().getName());
+ builder.addDynamicImportPackages(MBeanServer.class.getPackage().getName());
+ builder.addImportPackages(PackageAdmin.class, ServiceTracker.class);
builder.addExportPackages(ServiceA.class);
return builder.openStream();
}
@@ -106,6 +104,7 @@ public static JavaArchive testBundle() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, BLUEPRINT_BUNDLE);
archive.addAsResource("blueprint/blueprint-example.xml", "OSGI-INF/blueprint/blueprint-example.xml");
archive.setManifest(new Asset() {
+ @Override
public InputStream openStream() {
OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
builder.addBundleSymbolicName(archive.getName());
@@ -121,8 +120,7 @@ public InputStream openStream() {
@Test
@InSequence(0)
- public void addBlueprintSupport() throws BundleException {
- Bundle bundle = packageAdmin.getBundles(BLUEPRINT_PROVIDER, null)[0];
+ public void addBlueprintSupport(@ArquillianResource Bundle bundle) throws BundleException {
JMXSupport.provideMBeanServer(context, bundle);
BlueprintSupport.provideBlueprint(context, bundle);
}
@@ -134,31 +132,22 @@ public void testBlueprintContainerAvailable() throws Exception {
Bundle bundle = context.installBundle(BLUEPRINT_BUNDLE, input);
try {
bundle.start();
- BlueprintContainer container = getBlueprintContainer(bundle.getSymbolicName());
+ BlueprintContainer container = BlueprintSupport.getBlueprintContainer(bundle);
assertNotNull("BlueprintContainer available", container);
- ServiceReference sref = context.getServiceReference(ServiceA.class.getName());
- assertNotNull("ServiceA not null", sref);
- ServiceA serviceA = (ServiceA) context.getService(sref);
+ ServiceReference srefA = context.getServiceReference(ServiceA.class.getName());
+ assertNotNull("ServiceA not null", srefA);
+ ServiceA serviceA = (ServiceA) context.getService(srefA);
MBeanServer mbeanServer = serviceA.getMbeanServer();
assertNotNull("MBeanServer not null", mbeanServer);
- sref = context.getServiceReference(ServiceB.class.getName());
- assertNotNull("ServiceB not null", sref);
- ServiceB serviceB = (ServiceB) context.getService(sref);
+ ServiceReference srefB = context.getServiceReference(ServiceB.class.getName());
+ assertNotNull("ServiceB not null", srefB);
+ ServiceB serviceB = (ServiceB) context.getService(srefB);
BeanA beanA = serviceB.getBeanA();
assertNotNull("BeanA not null", beanA);
} finally {
bundle.uninstall();
}
}
-
- private BlueprintContainer getBlueprintContainer(String symbolicName) throws Exception {
- String objectclass = "(objectclass=" + BlueprintContainer.class.getName() + ")";
- String symbolicname = "(osgi.blueprint.container.symbolicname=" + symbolicName + ")";
- Filter filter = FrameworkUtil.createFilter("(&" + objectclass + symbolicname + ")");
- ServiceTracker tracker = new ServiceTracker(context, filter, null);
- tracker.open();
- return (BlueprintContainer) tracker.waitForService(10000);
- }
}

0 comments on commit 32c26dd

Please sign in to comment.