Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove dependency on org.osgi.enterprise from the runtime

  • Loading branch information...
commit 4c44a3ae88621623f2346bb02cc25be6058e4bc3 1 parent 5ab42eb
@tdiesler tdiesler authored
View
2  testsuite/example/pom.xml
@@ -254,9 +254,9 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
+ <argLine>${surefire.system.args} ${surefire.security.args}</argLine>
<excludes>
<exclude>**/cdi/*TestCase.java</exclude>
- <exclude>**/configadmin/*TestCase.java</exclude>
<exclude>**/ear/*TestCase.java</exclude>
<exclude>**/ejb3/*TestCase.java</exclude>
<exclude>**/http/*TestCase.java</exclude>
View
3  testsuite/example/src/main/java/org/jboss/test/osgi/BlueprintSupport.java
@@ -32,7 +32,7 @@
/**
* Provide the org.apache.aries.blueprint bundle
- *
+ *
* @author Thomas.Diesler@jboss.com
* @since 28-Jan-2012
*/
@@ -42,6 +42,7 @@
public static void provideBlueprint(BundleContext syscontext, Bundle bundle) throws BundleException {
AriesSupport.provideAriesProxy(syscontext, bundle);
+ ConfigurationAdminSupport.provideConfigurationAdmin(syscontext, bundle);
if (getPackageAdmin(syscontext).getBundles("org.apache.aries.blueprint", null) == null) {
installSupportBundle(syscontext, getCoordinates(bundle, APACHE_ARIES_BLUEPRINT)).start();
}
View
7 testsuite/example/src/main/java/org/jboss/test/osgi/ConfigurationAdminSupport.java
@@ -25,6 +25,7 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ConfigurationAdmin;
/**
* Provide the org.apache.felix.configadmin bundle
@@ -43,4 +44,10 @@ public static void provideConfigurationAdmin(BundleContext syscontext, Bundle bu
installSupportBundle(syscontext, getCoordinates(bundle, APACHE_FELIX_CONFIGURATION_ADMIN)).start();
}
}
+
+ public static ConfigurationAdmin getConfigurationAdmin(Bundle bundle) {
+ BundleContext context = bundle.getBundleContext();
+ ServiceReference sref = context.getServiceReference(ConfigurationAdmin.class.getName());
+ return (ConfigurationAdmin) context.getService(sref);
+ }
}
View
25 testsuite/example/src/main/java/org/jboss/test/osgi/FrameworkUtils.java
@@ -25,13 +25,11 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-import org.junit.Assert;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.FrameworkListener;
import org.osgi.framework.ServiceReference;
import org.osgi.service.startlevel.StartLevel;
-import org.osgi.util.tracker.ServiceTracker;
/**
@@ -56,6 +54,7 @@ public static void changeStartLevel(final BundleContext context, final int level
if (level != startLevel.getStartLevel()) {
final CountDownLatch latch = new CountDownLatch(1);
context.addFrameworkListener(new FrameworkListener() {
+ @Override
public void frameworkEvent(FrameworkEvent event) {
if (event.getType() == FrameworkEvent.STARTLEVEL_CHANGED && level == startLevel.getStartLevel()) {
latch.countDown();
@@ -67,26 +66,4 @@ public void frameworkEvent(FrameworkEvent event) {
throw new TimeoutException("Timeout changing start level");
}
}
-
- public static <T> T waitForService(BundleContext context, Class<T> clazz) {
- return waitForService(context, clazz, 5000, TimeUnit.MILLISECONDS);
- }
-
- @SuppressWarnings("unchecked")
- public static <T> T waitForService(BundleContext context, Class<T> clazz, long timeout, TimeUnit unit) {
- ServiceTracker tracker = new ServiceTracker(context, clazz.getName(), null);
- tracker.open();
- T service = null;
- long start = System.currentTimeMillis();
- do {
- try {
- service = (T) tracker.waitForService(unit.toMillis(timeout));
- } catch (InterruptedException intEx) {
- // service will be null
- }
- } while (System.currentTimeMillis() - start < unit.toMillis(timeout));
- tracker.close();
- Assert.assertNotNull("Service registered: " + clazz.getName(), service);
- return service;
- }
}
View
3  testsuite/example/src/test/java/org/jboss/test/osgi/example/blueprint/BlueprintTestCase.java
@@ -40,6 +40,7 @@
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.test.osgi.AriesSupport;
import org.jboss.test.osgi.BlueprintSupport;
+import org.jboss.test.osgi.ConfigurationAdminSupport;
import org.jboss.test.osgi.JMXSupport;
import org.jboss.test.osgi.RepositorySupport;
import org.jboss.test.osgi.example.blueprint.bundle.BeanA;
@@ -79,7 +80,7 @@
@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(JMXSupport.class, BlueprintSupport.class, AriesSupport.class, ConfigurationAdminSupport.class, RepositorySupport.class);
archive.addClasses(BeanA.class, ServiceA.class, BeanB.class, ServiceB.class);
archive.addAsManifestResource(RepositorySupport.BUNDLE_VERSIONS_FILE);
archive.setManifest(new Asset() {
View
48 testsuite/example/src/test/java/org/jboss/test/osgi/example/configadmin/ConfigurationAdminTestCase.java
@@ -29,12 +29,16 @@
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.osgi.metadata.OSGiManifestBuilder;
+import org.jboss.osgi.repository.XRequirementBuilder;
+import org.jboss.osgi.resolver.MavenCoordinates;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.Asset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.jboss.test.osgi.FrameworkUtils;
+import org.jboss.test.osgi.ConfigurationAdminSupport;
+import org.jboss.test.osgi.RepositorySupport;
import org.jboss.test.osgi.example.api.ConfiguredService;
import org.junit.Assert;
import org.junit.Test;
@@ -42,14 +46,15 @@
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
+import org.osgi.resource.Resource;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.cm.ManagedService;
+import org.osgi.service.repository.Repository;
/**
* A test that shows how an OSGi {@link ManagedService} can be configured through the {@link ConfigurationAdmin}.
- *
+ *
* @author Thomas.Diesler@jboss.com
* @author David Bosschaert
* @since 11-Dec-2010
@@ -57,21 +62,25 @@
@RunWith(Arquillian.class)
public class ConfigurationAdminTestCase {
- static final String PID_A = ConfigurationAdminTestCase.class.getSimpleName() + "-pid-a";
+ static final String PID_A = "ConfigurationAdmin-PID-A";
@ArquillianResource
- Bundle bundle;
+ BundleContext context;
@Deployment
- public static JavaArchive createdeployment() {
+ public static JavaArchive deployment() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "osgi-configadmin");
- archive.addClasses(FrameworkUtils.class, ConfiguredService.class);
+ archive.addClasses(RepositorySupport.class, ConfigurationAdminSupport.class);
+ archive.addClasses(ConfiguredService.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(ConfigurationAdmin.class);
+ builder.addImportPackages(XRequirementBuilder.class, MavenCoordinates.class, Repository.class, Resource.class);
+ builder.addDynamicImportPackages(ConfigurationAdmin.class.getPackage().getName());
return builder.openStream();
}
});
@@ -79,11 +88,18 @@ public InputStream openStream() {
}
@Test
- public void testManagedService() throws Exception {
+ @InSequence(0)
+ public void addConfigurationAdminSupport(@ArquillianResource Bundle bundle) throws Exception {
+ ConfigurationAdminSupport.provideConfigurationAdmin(context, bundle);
+ bundle.start();
+ }
+
+ @Test
+ @InSequence(1)
+ public void testManagedService(@ArquillianResource Bundle bundle) throws Exception {
// Get the {@link Configuration} for the given PID
- BundleContext context = bundle.getBundleContext();
- ConfigurationAdmin configAdmin = getConfigurationAdmin(context);
+ ConfigurationAdmin configAdmin = ConfigurationAdminSupport.getConfigurationAdmin(bundle);
Configuration config = configAdmin.getConfiguration(PID_A);
Assert.assertNotNull("Config not null", config);
Assert.assertNull("Config is empty, but was: " + config.getProperties(), config.getProperties());
@@ -97,10 +113,11 @@ public void testManagedService() throws Exception {
ConfiguredService service = new ConfiguredService();
Dictionary<String, String> serviceProps = new Hashtable<String, String>();
serviceProps.put(Constants.SERVICE_PID, PID_A);
- context.registerService(new String[] { ConfiguredService.class.getName(), ManagedService.class.getName() }, service, serviceProps);
+ String[] clazzes = new String[] { ConfiguredService.class.getName(), ManagedService.class.getName() };
+ bundle.getBundleContext().registerService(clazzes, service, serviceProps);
// Wait a little for the update event
- Assert.assertTrue(service.awaitUpdate(3, TimeUnit.SECONDS));
+ Assert.assertTrue("Service updated", service.awaitUpdate(3, TimeUnit.SECONDS));
// Verify service property
Assert.assertEquals("bar", service.getProperties().get("foo"));
@@ -108,9 +125,4 @@ public void testManagedService() throws Exception {
config.delete();
}
}
-
- private ConfigurationAdmin getConfigurationAdmin(BundleContext context) {
- ServiceReference sref = context.getServiceReference(ConfigurationAdmin.class.getName());
- return (ConfigurationAdmin) context.getService(sref);
- }
}
View
8 testsuite/example/src/test/java/org/jboss/test/osgi/example/jndi/NamingSpecTestCase.java
@@ -43,6 +43,7 @@
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.test.osgi.AriesSupport;
import org.jboss.test.osgi.BlueprintSupport;
+import org.jboss.test.osgi.ConfigurationAdminSupport;
import org.jboss.test.osgi.NamingSupport;
import org.jboss.test.osgi.RepositorySupport;
import org.jboss.test.osgi.example.jndi.bundle.JNDITestActivator;
@@ -83,7 +84,7 @@
@Deployment(name = JNDI_PROVIDER)
public static JavaArchive jndiProvider() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, JNDI_PROVIDER);
- archive.addClasses(RepositorySupport.class, NamingSupport.class, AriesSupport.class, BlueprintSupport.class);
+ archive.addClasses(RepositorySupport.class, NamingSupport.class, AriesSupport.class, BlueprintSupport.class, ConfigurationAdminSupport.class);
archive.addClasses(JNDITestService.class, JNDITestActivator.class);
archive.addAsManifestResource(RepositorySupport.BUNDLE_VERSIONS_FILE);
archive.setManifest(new Asset() {
@@ -92,6 +93,7 @@ public InputStream openStream() {
OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
builder.addBundleSymbolicName(archive.getName());
builder.addBundleManifestVersion(2);
+ builder.addBundleActivator(JNDITestActivator.class);
builder.addImportPackages(XRequirementBuilder.class, MavenCoordinates.class, Repository.class, Resource.class);
builder.addImportPackages(PackageAdmin.class, Context.class, InitialContextFactory.class);
builder.addDynamicImportPackages(JNDIContextManager.class.getPackage().getName());
@@ -134,7 +136,6 @@ public void testContextManager(@ArquillianResource Bundle bundle) throws Excepti
}
@Test
- @Ignore
@InSequence(1)
public void testContextManagerOwnerContext(@ArquillianResource Bundle bundle) throws Exception {
@@ -168,7 +169,6 @@ public void testContextManagerValueBinding(@ArquillianResource Bundle bundle) th
}
@Test
- @Ignore
@InSequence(1)
public void testContextManagerReferenceBinding(@ArquillianResource Bundle bundle) throws Exception {
@@ -298,7 +298,6 @@ public void testTraditionalAPIOwnerContext(@ArquillianResource Bundle bundle) th
}
@Test
- @Ignore
@InSequence(1)
public void testTraditionalAPIValueBinding(@ArquillianResource Bundle bundle) throws Exception {
@@ -318,7 +317,6 @@ public void testTraditionalAPIValueBinding(@ArquillianResource Bundle bundle) th
}
@Test
- @Ignore
@InSequence(1)
public void testTraditionalAPIReferenceBinding(@ArquillianResource Bundle bundle) throws Exception {
View
10 testsuite/example/src/test/java/org/jboss/test/osgi/example/repository/RepositoryTestCase.java
@@ -48,8 +48,8 @@
import org.osgi.service.repository.RepositoryContent;
/**
- * Test that the EventAdmin can be installed through the Repository bundle.
- *
+ * Test that a bundle can be installed through the Repository bundle.
+ *
* @author thomas.diesler@jboss.com
* @since 19-Jan-2012
*/
@@ -80,7 +80,7 @@ public InputStream openStream() {
public void testRepositoryService() throws Exception {
XRepository repo = getRepository();
- MavenCoordinates coordinates = MavenCoordinates.parse("org.apache.felix:org.apache.felix.eventadmin:1.2.6");
+ MavenCoordinates coordinates = MavenCoordinates.parse("org.osgi:org.osgi.enterprise:4.2.0");
XRequirement req = XRequirementBuilder.create(coordinates).getRequirement();
assertNotNull("Requirement not null", req);
@@ -90,15 +90,13 @@ public void testRepositoryService() throws Exception {
Capability cap = caps.iterator().next();
XResource resource = (XResource) cap.getResource();
XIdentityCapability xcap = resource.getIdentityCapability();
- assertEquals("org.apache.felix.eventadmin", xcap.getSymbolicName());
+ assertEquals("osgi.enterprise", xcap.getSymbolicName());
InputStream content = ((RepositoryContent) xcap.getResource()).getContent();
try {
Bundle bundle = context.installBundle(xcap.getSymbolicName(), content);
try {
bundle.start();
Assert.assertEquals(Bundle.ACTIVE, bundle.getState());
- ServiceReference sref = context.getServiceReference("org.osgi.service.event.EventAdmin");
- assertNotNull("EventAdmin service not null", sref);
} finally {
bundle.uninstall();
}
View
4 testsuite/example/src/test/resources/jboss-osgi-framework.properties
@@ -12,9 +12,7 @@ org.osgi.framework.system.packages.extra=\
org.slf4j;version=1.6
# Bundles that need to be installed with the Framework automatically
-org.jboss.osgi.auto.install=\
- file://${test.archive.directory}/bundles/jboss-annotations-api_1.1_spec.jar,\
- file://${test.archive.directory}/bundles/jboss-servlet-api_3.0_spec.jar
+#org.jboss.osgi.auto.install=\
# Bundles that need to be started automatically
org.jboss.osgi.auto.start=\
View
4 testsuite/example/src/test/resources/tst.policy
@@ -0,0 +1,4 @@
+grant {
+ permission java.security.AllPermission;
+};
+
View
1  testsuite/pom.xml
@@ -34,6 +34,7 @@
<!-- Properties -->
<properties>
<surefire.system.args>-ea -Xmx512m</surefire.system.args>
+ <surefire.security.args>-Djava.security.manager -Djava.security.policy=${basedir}/src/test/resources/tst.policy</surefire.security.args>
<jboss.osgi.framework.properties>jboss-osgi-framework.properties</jboss.osgi.framework.properties>
</properties>
Please sign in to comment.
Something went wrong with that request. Please try again.