refactored existing tests to use static inner classes to avoid potential name clashes between tests, added a new test
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@883668 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/ComponentLifeCycleTest.java b/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/ComponentLifeCycleTest.java
index 59e71f7..47fbf32 100644
--- a/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/ComponentLifeCycleTest.java
+++ b/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/ComponentLifeCycleTest.java
@@ -73,44 +73,44 @@
// ensure we executed all steps inside the component instance
e.step(6);
}
-}
-class ComponentInstance {
- private final Ensure m_ensure;
- public ComponentInstance(Ensure e) {
- m_ensure = e;
- m_ensure.step(1);
+ static class ComponentInstance {
+ private final Ensure m_ensure;
+ public ComponentInstance(Ensure e) {
+ m_ensure = e;
+ m_ensure.step(1);
+ }
+ public void init() {
+ m_ensure.step(2);
+ }
+ public void start() {
+ m_ensure.step(3);
+ }
+ public void stop() {
+ m_ensure.step(4);
+ }
+ public void destroy() {
+ m_ensure.step(5);
+ }
}
- public void init() {
- m_ensure.step(2);
- }
- public void start() {
- m_ensure.step(3);
- }
- public void stop() {
- m_ensure.step(4);
- }
- public void destroy() {
- m_ensure.step(5);
- }
-}
-class CustomComponentInstance {
- private final Ensure m_ensure;
- public CustomComponentInstance(Ensure e) {
- m_ensure = e;
- m_ensure.step(1);
- }
- public void a() {
- m_ensure.step(2);
- }
- public void b() {
- m_ensure.step(3);
- }
- public void c() {
- m_ensure.step(4);
- }
- public void d() {
- m_ensure.step(5);
+ static class CustomComponentInstance {
+ private final Ensure m_ensure;
+ public CustomComponentInstance(Ensure e) {
+ m_ensure = e;
+ m_ensure.step(1);
+ }
+ public void a() {
+ m_ensure.step(2);
+ }
+ public void b() {
+ m_ensure.step(3);
+ }
+ public void c() {
+ m_ensure.step(4);
+ }
+ public void d() {
+ m_ensure.step(5);
+ }
}
}
diff --git a/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/ConfigurationDependencyTest.java b/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/ConfigurationDependencyTest.java
index aaae382..67acbe3 100644
--- a/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/ConfigurationDependencyTest.java
+++ b/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/ConfigurationDependencyTest.java
@@ -73,61 +73,61 @@
// ensure we executed all steps inside the component instance
e.step(5);
}
-}
-class ConfigurationCreator {
- private volatile ConfigurationAdmin m_ca;
- private final Ensure m_ensure;
-
- public ConfigurationCreator(Ensure e) {
- m_ensure = e;
- }
-
- public void start() {
- try {
- m_ensure.step(1);
- org.osgi.service.cm.Configuration conf = m_ca.getConfiguration("test", null);
- Properties props = new Properties();
- props.put("testkey", "testvalue");
- conf.update(props);
+ static class ConfigurationCreator {
+ private volatile ConfigurationAdmin m_ca;
+ private final Ensure m_ensure;
+
+ public ConfigurationCreator(Ensure e) {
+ m_ensure = e;
}
- catch (IOException e) {
- Assert.fail("Could not create configuration: " + e.getMessage());
- }
- }
-}
-class ConfigurationConsumer implements ManagedService, Runnable {
- private final Ensure m_ensure;
-
- public ConfigurationConsumer(Ensure e) {
- m_ensure = e;
- }
-
- public void updated(Dictionary props) throws ConfigurationException {
- if (props != null) {
- m_ensure.step(2);
- if (!"testvalue".equals(props.get("testkey"))) {
- Assert.fail("Could not find the configured property.");
+ public void start() {
+ try {
+ m_ensure.step(1);
+ org.osgi.service.cm.Configuration conf = m_ca.getConfiguration("test", null);
+ Properties props = new Properties();
+ props.put("testkey", "testvalue");
+ conf.update(props);
+ }
+ catch (IOException e) {
+ Assert.fail("Could not create configuration: " + e.getMessage());
}
}
}
-
- public void run() {
- m_ensure.step(4);
- }
-}
-class ConfiguredServiceConsumer {
- private final Ensure m_ensure;
- private volatile Runnable m_runnable;
+ static class ConfigurationConsumer implements ManagedService, Runnable {
+ private final Ensure m_ensure;
- public ConfiguredServiceConsumer(Ensure e) {
- m_ensure = e;
+ public ConfigurationConsumer(Ensure e) {
+ m_ensure = e;
+ }
+
+ public void updated(Dictionary props) throws ConfigurationException {
+ if (props != null) {
+ m_ensure.step(2);
+ if (!"testvalue".equals(props.get("testkey"))) {
+ Assert.fail("Could not find the configured property.");
+ }
+ }
+ }
+
+ public void run() {
+ m_ensure.step(4);
+ }
}
-
- public void start() {
- m_ensure.step(3);
- m_runnable.run();
+
+ static class ConfiguredServiceConsumer {
+ private final Ensure m_ensure;
+ private volatile Runnable m_runnable;
+
+ public ConfiguredServiceConsumer(Ensure e) {
+ m_ensure = e;
+ }
+
+ public void start() {
+ m_ensure.step(3);
+ m_runnable.run();
+ }
}
}
diff --git a/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/MultipleServiceDependencyTest.java b/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/MultipleServiceDependencyTest.java
new file mode 100644
index 0000000..6ea11c2
--- /dev/null
+++ b/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/MultipleServiceDependencyTest.java
@@ -0,0 +1,102 @@
+package org.apache.felix.dependencymanager.test;
+
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+
+import java.util.Properties;
+
+import org.apache.felix.dependencymanager.DependencyManager;
+import org.apache.felix.dependencymanager.Logger;
+import org.apache.felix.dependencymanager.Service;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+
+@RunWith(JUnit4TestRunner.class)
+public class MultipleServiceDependencyTest {
+ @Configuration
+ public static Option[] configuration() {
+ return options(
+ provision(
+ mavenBundle().groupId("org.apache.felix").artifactId("org.osgi.compendium").versionAsInProject(),
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager").versionAsInProject()
+ )
+ );
+ }
+
+ @Test
+ public void testMultipleServiceRegistrationAndConsumption(BundleContext context) {
+ DependencyManager m = new DependencyManager(context, new Logger(context));
+ // helper class that ensures certain steps get executed in sequence
+ Ensure e = new Ensure();
+ // create a service provider and consumer
+ Service provider = m.createService().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
+ Service providerWithHighRank = m.createService().setImplementation(new ServiceProvider2(e)).setInterface(ServiceInterface.class.getName(), new Properties() {{ put(Constants.SERVICE_RANKING, Integer.valueOf(5)); }});
+ Service consumer = m.createService().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true));
+ m.add(provider);
+ m.add(providerWithHighRank);
+ m.add(consumer);
+ e.waitForStep(3, 1000);
+ m.remove(providerWithHighRank);
+ e.step(4);
+ e.waitForStep(5, 1000);
+ m.remove(provider);
+ m.remove(consumer);
+ e.waitForStep(6, 1000);
+ }
+
+ static interface ServiceInterface {
+ public void invoke();
+ }
+
+ static class ServiceProvider implements ServiceInterface {
+ private final Ensure m_ensure;
+ public ServiceProvider(Ensure e) {
+ m_ensure = e;
+ }
+ public void invoke() {
+ m_ensure.step(5);
+ }
+ }
+
+ static class ServiceProvider2 implements ServiceInterface {
+ private final Ensure m_ensure;
+ public ServiceProvider2(Ensure e) {
+ m_ensure = e;
+ }
+ public void invoke() {
+ m_ensure.step(2);
+ }
+ }
+
+ static class ServiceConsumer implements Runnable {
+ private volatile ServiceInterface m_service;
+ private final Ensure m_ensure;
+
+ public ServiceConsumer(Ensure e) {
+ m_ensure = e;
+ }
+
+ public void start() {
+ Thread t = new Thread(this);
+ t.start();
+ }
+
+ public void run() {
+ m_ensure.step(1);
+ m_service.invoke();
+ m_ensure.step(3);
+ m_ensure.waitForStep(4, 1000);
+ m_service.invoke();
+ }
+
+ public void stop() {
+ m_ensure.step(6);
+ }
+ }
+}
diff --git a/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/ServiceDependencyTest.java b/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/ServiceDependencyTest.java
index 39d4d59..ecf80c1 100644
--- a/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/ServiceDependencyTest.java
+++ b/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/ServiceDependencyTest.java
@@ -62,51 +62,51 @@
// ensure we executed all steps inside the component instance
e.step(6);
}
-}
-
-interface ServiceInterface {
- public void invoke();
-}
-
-class ServiceProvider implements ServiceInterface {
- private final Ensure m_ensure;
- public ServiceProvider(Ensure e) {
- m_ensure = e;
- }
- public void invoke() {
- m_ensure.step(2);
- }
-}
-
-class ServiceConsumer {
- private volatile ServiceInterface m_service;
- private final Ensure m_ensure;
-
- public ServiceConsumer(Ensure e) {
- m_ensure = e;
- }
- public void start() {
- m_ensure.step(1);
- m_service.invoke();
+ static interface ServiceInterface {
+ public void invoke();
}
-
- public void stop() {
- m_ensure.step(3);
- }
-}
-class ServiceConsumerCallbacks {
- private final Ensure m_ensure;
+ static class ServiceProvider implements ServiceInterface {
+ private final Ensure m_ensure;
+ public ServiceProvider(Ensure e) {
+ m_ensure = e;
+ }
+ public void invoke() {
+ m_ensure.step(2);
+ }
+ }
- public ServiceConsumerCallbacks(Ensure e) {
- m_ensure = e;
+ static class ServiceConsumer {
+ private volatile ServiceInterface m_service;
+ private final Ensure m_ensure;
+
+ public ServiceConsumer(Ensure e) {
+ m_ensure = e;
+ }
+
+ public void start() {
+ m_ensure.step(1);
+ m_service.invoke();
+ }
+
+ public void stop() {
+ m_ensure.step(3);
+ }
}
-
- public void add(ServiceInterface service) {
- m_ensure.step(4);
- }
- public void remove(ServiceInterface service) {
- m_ensure.step(5);
+
+ static class ServiceConsumerCallbacks {
+ private final Ensure m_ensure;
+
+ public ServiceConsumerCallbacks(Ensure e) {
+ m_ensure = e;
+ }
+
+ public void add(ServiceInterface service) {
+ m_ensure.step(4);
+ }
+ public void remove(ServiceInterface service) {
+ m_ensure.step(5);
+ }
}
}
diff --git a/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/TemporalServiceDependencyTest.java b/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/TemporalServiceDependencyTest.java
index 88db3cc..03937bd 100644
--- a/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/TemporalServiceDependencyTest.java
+++ b/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/TemporalServiceDependencyTest.java
@@ -71,53 +71,53 @@
// ensure we executed all steps inside the component instance
e.step(6);
}
-}
-interface TemporalServiceInterface {
- public void invoke();
-}
+ static interface TemporalServiceInterface {
+ public void invoke();
+ }
-class TemporalServiceProvider implements TemporalServiceInterface {
- private final Ensure m_ensure;
- public TemporalServiceProvider(Ensure e) {
- m_ensure = e;
+ static class TemporalServiceProvider implements TemporalServiceInterface {
+ private final Ensure m_ensure;
+ public TemporalServiceProvider(Ensure e) {
+ m_ensure = e;
+ }
+ public void invoke() {
+ m_ensure.step(2);
+ }
}
- public void invoke() {
- m_ensure.step(2);
- }
-}
-class TemporalServiceProvider2 implements TemporalServiceInterface {
- private final Ensure m_ensure;
- public TemporalServiceProvider2(Ensure e) {
- m_ensure = e;
+ static class TemporalServiceProvider2 implements TemporalServiceInterface {
+ private final Ensure m_ensure;
+ public TemporalServiceProvider2(Ensure e) {
+ m_ensure = e;
+ }
+ public void invoke() {
+ m_ensure.step(4);
+ }
}
- public void invoke() {
- m_ensure.step(4);
- }
-}
-class TemporalServiceConsumer implements Runnable {
- private volatile TemporalServiceInterface m_service;
- private final Ensure m_ensure;
+ static class TemporalServiceConsumer implements Runnable {
+ private volatile TemporalServiceInterface m_service;
+ private final Ensure m_ensure;
- public TemporalServiceConsumer(Ensure e) {
- m_ensure = e;
- }
-
- public void start() {
- m_ensure.step(1);
- Thread t = new Thread(this);
- t.start();
- }
-
- public void run() {
- m_service.invoke();
- m_ensure.waitForStep(3, 1000);
- m_service.invoke();
- }
-
- public void stop() {
- m_ensure.step(5);
+ public TemporalServiceConsumer(Ensure e) {
+ m_ensure = e;
+ }
+
+ public void start() {
+ m_ensure.step(1);
+ Thread t = new Thread(this);
+ t.start();
+ }
+
+ public void run() {
+ m_service.invoke();
+ m_ensure.waitForStep(3, 1000);
+ m_service.invoke();
+ }
+
+ public void stop() {
+ m_ensure.step(5);
+ }
}
}