Skip to content

Commit

Permalink
Provision framework statically with configadmin, scr
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Diesler committed Sep 12, 2013
1 parent 5171160 commit 9ed99b1
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 146 deletions.
2 changes: 1 addition & 1 deletion testsuite/functional/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.metatype</artifactId>
<artifactId>org.apache.felix.configadmin</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
2 changes: 2 additions & 0 deletions testsuite/functional/scripts/assembly-bundles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
<outputFileNameMapping>${artifact.artifactId}${dashClassifier?}.${artifact.extension}
</outputFileNameMapping>
<includes>
<include>*:org.apache.felix.configadmin:jar</include>
<include>*:org.apache.felix.log:jar</include>
<include>*:org.apache.felix.scr:jar</include>
<include>*:jbosgi-repository-bundle:jar</include>
<include>*:jbosgi-provision-bundle:jar</include>
<include>*:jboss-osgi-logging:jar</include>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,18 @@
*/
package org.jboss.test.osgi.ds.sub.d1;

import java.util.Dictionary;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

import org.jboss.test.osgi.ds.support.AbstractComponent;
import org.osgi.service.cm.ManagedService;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;

@Component(service = { ServiceD1.class, ManagedService.class })
public class ServiceD1 extends AbstractComponent implements ManagedService {
@Component(service = { ServiceD1.class })
public class ServiceD1 extends AbstractComponent {

static AtomicInteger INSTANCE_COUNT = new AtomicInteger();
final String name = getClass().getSimpleName() + "#" + INSTANCE_COUNT.incrementAndGet();
Expand All @@ -60,11 +58,6 @@ public CountDownLatch getDeactivateLatch() {
return deactivateLatch;
}

@Override
public void updated(Dictionary<String, ?> properties) {
LOGGER.infof("config updated: %s", properties);
}

public String doStuff(String msg) {
assertValid();
String fooval = config.get("foo");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,9 @@
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.logging.Logger;
import org.jboss.osgi.metadata.OSGiManifestBuilder;
import org.jboss.osgi.provision.ProvisionerSupport;
import org.jboss.osgi.provision.XResourceProvisioner;
import org.jboss.osgi.repository.XRepository;
import org.jboss.osgi.resolver.XResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.Asset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
Expand All @@ -52,12 +47,9 @@
import org.junit.runner.RunWith;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.namespace.IdentityNamespace;
import org.osgi.resource.Resource;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.repository.Repository;
import org.osgi.util.tracker.ServiceTracker;

/**
Expand All @@ -83,33 +75,21 @@ public static JavaArchive dsProvider() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "reference-tests");
archive.addClasses(FrameworkUtils.class, ConfigurationAdminSupport.class);
archive.addPackage(AbstractComponent.class.getPackage());
archive.addAsResource("repository/felix.scr.feature.xml");
archive.addAsResource("repository/felix.configadmin.feature.xml");
archive.setManifest(new Asset() {
@Override
public InputStream openStream() {
OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
builder.addBundleSymbolicName(archive.getName());
builder.addBundleManifestVersion(2);
builder.addExportPackages(AbstractComponent.class);
builder.addImportPackages(XRepository.class, Repository.class, XResource.class, Resource.class, XResourceProvisioner.class);
builder.addImportPackages(ServiceTracker.class, Logger.class);
builder.addDynamicImportPackages(ConfigurationAdmin.class, ServiceD1.class, ServiceD.class);
builder.addImportPackages(ServiceTracker.class, ConfigurationAdmin.class, Logger.class);
builder.addDynamicImportPackages(ServiceD1.class, ServiceD.class);
return builder.openStream();
}
});
return archive;
}

@Test
@InSequence(0)
public void addDeclarativeServicesSupport() throws Exception {
ProvisionerSupport provisioner = new ProvisionerSupport(context);
provisioner.populateRepository(getClass().getClassLoader(), "felix.scr.feature");
provisioner.populateRepository(getClass().getClassLoader(), "felix.configadmin.feature");
provisioner.installCapabilities(IdentityNamespace.IDENTITY_NAMESPACE, "felix.configadmin.feature", "felix.scr.feature");
}

@Test
public void testServiceAccess() throws Exception {
Bundle bundleD1 = context.installBundle(BUNDLE_D1, deployer.getDeployment(BUNDLE_D1));
Expand All @@ -135,7 +115,7 @@ public void testServiceAccess() throws Exception {
configProps.put("foo", "bar");
config.update(configProps);

latch.await(2000, TimeUnit.MILLISECONDS);
latch.await(4000, TimeUnit.MILLISECONDS);

try {
srvD1.doStuff("Hello");
Expand All @@ -144,10 +124,7 @@ public void testServiceAccess() throws Exception {
// expected
}

srvD = FrameworkUtils.waitForService(context, ServiceD.class);
Assert.assertEquals("ServiceD#2:ServiceD1#2:bar:Hello", srvD.doStuff("Hello"));

srvD1 = srvD.getServiceD1();
srvD1 = FrameworkUtils.waitForService(context, ServiceD1.class);
Assert.assertEquals("ServiceD1#2:bar:Hello", srvD1.doStuff("Hello"));

} finally {
Expand Down Expand Up @@ -190,7 +167,7 @@ public InputStream openStream() {
builder.addBundleManifestVersion(2);
builder.addManifestHeader("Service-Component", "OSGI-INF/org.jboss.test.osgi.ds.sub.d1.ServiceD1.xml");
builder.addExportPackages(ServiceD1.class);
builder.addImportPackages(AbstractComponent.class, ComponentContext.class, ConfigurationAdmin.class, Logger.class);
builder.addImportPackages(AbstractComponent.class, ComponentContext.class, Logger.class);
return builder.openStream();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.logging.Logger;
import org.jboss.osgi.metadata.OSGiManifestBuilder;
import org.jboss.osgi.provision.ProvisionerSupport;
import org.jboss.osgi.provision.XResourceProvisioner;
import org.jboss.osgi.repository.XRepository;
import org.jboss.osgi.resolver.XResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.Asset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
Expand All @@ -47,11 +42,7 @@
import org.junit.runner.RunWith;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.namespace.IdentityNamespace;
import org.osgi.resource.Resource;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.repository.Repository;
import org.osgi.util.tracker.ServiceTracker;

/**
Expand All @@ -77,15 +68,13 @@ public static JavaArchive dsProvider() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "reference-tests");
archive.addClasses(FrameworkUtils.class);
archive.addPackage(AbstractComponent.class.getPackage());
archive.addAsResource("repository/felix.scr.feature.xml");
archive.setManifest(new Asset() {
@Override
public InputStream openStream() {
OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
builder.addBundleSymbolicName(archive.getName());
builder.addBundleManifestVersion(2);
builder.addExportPackages(AbstractComponent.class);
builder.addImportPackages(XRepository.class, Repository.class, XResource.class, Resource.class, XResourceProvisioner.class);
builder.addImportPackages(ServiceTracker.class, Logger.class);
builder.addDynamicImportPackages(ServiceB1.class, ServiceB.class);
return builder.openStream();
Expand All @@ -94,14 +83,6 @@ public InputStream openStream() {
return archive;
}

@Test
@InSequence(0)
public void addDeclarativeServicesSupport() throws Exception {
ProvisionerSupport provisioner = new ProvisionerSupport(context);
provisioner.populateRepository(getClass().getClassLoader(), "felix.scr.feature");
provisioner.installCapabilities(IdentityNamespace.IDENTITY_NAMESPACE, "felix.scr.feature");
}

@Test
public void testServiceAccess() throws Exception {
Bundle bundleB1 = context.installBundle(BUNDLE_B1, deployer.getDeployment(BUNDLE_B1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.logging.Logger;
import org.jboss.osgi.metadata.OSGiManifestBuilder;
import org.jboss.osgi.provision.ProvisionerSupport;
import org.jboss.osgi.provision.XResourceProvisioner;
import org.jboss.osgi.repository.XRepository;
import org.jboss.osgi.resolver.XResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.Asset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
Expand All @@ -48,11 +43,7 @@
import org.junit.runner.RunWith;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.namespace.IdentityNamespace;
import org.osgi.resource.Resource;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.repository.Repository;
import org.osgi.util.tracker.ServiceTracker;

/**
Expand All @@ -79,15 +70,13 @@ public static JavaArchive dsProvider() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "reference-tests");
archive.addClasses(FrameworkUtils.class);
archive.addPackage(AbstractComponent.class.getPackage());
archive.addAsResource("repository/felix.scr.feature.xml");
archive.setManifest(new Asset() {
@Override
public InputStream openStream() {
OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
builder.addBundleSymbolicName(archive.getName());
builder.addBundleManifestVersion(2);
builder.addExportPackages(AbstractComponent.class);
builder.addImportPackages(XRepository.class, Repository.class, XResource.class, Resource.class, XResourceProvisioner.class);
builder.addImportPackages(ServiceTracker.class, Logger.class);
builder.addDynamicImportPackages(ServiceC1.class, ServiceC.class);
return builder.openStream();
Expand All @@ -96,14 +85,6 @@ public InputStream openStream() {
return archive;
}

@Test
@InSequence(0)
public void addDeclarativeServicesSupport() throws Exception {
ProvisionerSupport provisioner = new ProvisionerSupport(context);
provisioner.populateRepository(getClass().getClassLoader(), "felix.scr.feature");
provisioner.installCapabilities(IdentityNamespace.IDENTITY_NAMESPACE, "felix.scr.feature");
}

@Test
public void testServiceAccess() throws Exception {
Bundle bundleC1 = context.installBundle(BUNDLE_C1, deployer.getDeployment(BUNDLE_C1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.logging.Logger;
import org.jboss.osgi.metadata.OSGiManifestBuilder;
import org.jboss.osgi.provision.ProvisionerSupport;
import org.jboss.osgi.provision.XResourceProvisioner;
import org.jboss.osgi.repository.XRepository;
import org.jboss.osgi.resolver.XResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.Asset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
Expand All @@ -48,10 +43,7 @@
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.namespace.IdentityNamespace;
import org.osgi.resource.Resource;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.repository.Repository;
import org.osgi.util.tracker.ServiceTracker;

/**
Expand All @@ -77,15 +69,13 @@ public static JavaArchive dsProvider() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "reference-tests");
archive.addClasses(FrameworkUtils.class);
archive.addPackage(AbstractComponent.class.getPackage());
archive.addAsResource("repository/felix.scr.feature.xml");
archive.setManifest(new Asset() {
@Override
public InputStream openStream() {
OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
builder.addBundleSymbolicName(archive.getName());
builder.addBundleManifestVersion(2);
builder.addExportPackages(AbstractComponent.class);
builder.addImportPackages(XRepository.class, Repository.class, XResource.class, Resource.class, XResourceProvisioner.class);
builder.addImportPackages(ServiceTracker.class, Logger.class);
builder.addDynamicImportPackages(ServiceA1.class, ServiceA.class);
return builder.openStream();
Expand All @@ -94,14 +84,6 @@ public InputStream openStream() {
return archive;
}

@Test
@InSequence(0)
public void addDeclarativeServicesSupport() throws Exception {
ProvisionerSupport provisioner = new ProvisionerSupport(context);
provisioner.populateRepository(getClass().getClassLoader(), "felix.scr.feature");
provisioner.installCapabilities(IdentityNamespace.IDENTITY_NAMESPACE, "felix.scr.feature");
}

@Test
public void testServiceAccess() throws Exception {
Bundle bundleA1 = context.installBundle(BUNDLE_A1, deployer.getDeployment(BUNDLE_A1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ org.osgi.framework.system.packages.extra=\
# Bundles that need to be started automatically
org.jboss.osgi.auto.start=\
file://${test.archive.directory}/bundles/org.apache.felix.log.jar,\
file://${test.archive.directory}/bundles/org.apache.felix.configadmin.jar,\
file://${test.archive.directory}/bundles/org.apache.felix.scr.jar,\
file://${test.archive.directory}/bundles/jboss-osgi-logging.jar,\
file://${test.archive.directory}/bundles/jbosgi-repository-bundle.jar,\
file://${test.archive.directory}/bundles/jbosgi-provision-bundle.jar

This file was deleted.

This file was deleted.

0 comments on commit 9ed99b1

Please sign in to comment.