pax-exam 3.0.0 migration ...
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1532034 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/AdapterServiceTestWithPublisher.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/AdapterServiceTestWithPublisher.java
deleted file mode 100644
index fd42251..0000000
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/AdapterServiceTestWithPublisher.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.dm.test.bundle.annotation.publisher;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.felix.dm.annotation.api.AdapterService;
-import org.apache.felix.dm.annotation.api.Component;
-import org.apache.felix.dm.annotation.api.Init;
-import org.apache.felix.dm.annotation.api.LifecycleController;
-import org.apache.felix.dm.annotation.api.Property;
-import org.apache.felix.dm.annotation.api.ServiceDependency;
-import org.apache.felix.dm.annotation.api.Start;
-import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
-
-/**
- * Test an AdapterService which provides its interface using a @ServiceLifecycle.
- */
-public class AdapterServiceTestWithPublisher
-{
- public interface Provider
- {
- }
-
- public interface Provider2
- {
- }
-
- @Component
- public static class Consumer
- {
- @ServiceDependency(filter="(name=AdapterServiceTestWithPublisher)")
- Sequencer m_sequencer;
-
- @ServiceDependency(required=false, removed = "unbind")
- void bind(Map properties, Provider2 provider)
- {
- m_sequencer.step(1);
- // check ProviderImpl properties
- if ("bar".equals(properties.get("foo")))
- {
- m_sequencer.step(2);
- }
- // check extra ProviderImpl properties (returned by start method)
- if ("bar2".equals(properties.get("foo2")))
- {
- m_sequencer.step(3);
- }
- // check Provider2Impl properties
- if ("bar3".equals(properties.get("foo3")))
- {
- m_sequencer.step(4);
- }
- // check extra Provider2Impl properties (returned by start method)
- if ("bar4".equals(properties.get("foo4")))
- {
- m_sequencer.step(5);
- }
-
- }
-
- void unbind(Provider2 provider)
- {
- m_sequencer.step(6);
- }
- }
-
- @Component(properties={@Property(name="foo", value="bar")})
- public static class ProviderImpl implements Provider
- {
- @Start
- Map start()
- {
- // Add some extra service properties ... they will be appended to the one we have defined
- // in the @Service annotation.
- return new HashMap() {{ put("foo2", "bar2"); }};
- }
- }
-
- @AdapterService(properties={@Property(name="foo3", value="bar3")}, adapteeService=Provider.class)
- public static class Provider2Impl implements Provider2
- {
- @LifecycleController
- Runnable m_publisher; // injected and used to register our service
-
- @LifecycleController(start=false)
- Runnable m_unpublisher; // injected and used to unregister our service
-
- @ServiceDependency(filter="(name=AdapterServiceTestWithPublisher)")
- Sequencer m_sequencer;
-
- @Init
- void init()
- {
- // register service in 1 second
- Utils.schedule(m_publisher, 1000);
- // unregister the service in 2 seconds
- Utils.schedule(m_unpublisher, 2000);
- }
-
- @Start
- Map start()
- {
- // Add some extra service properties ... they will be appended to the one we have defined
- // in the @Service annotation.
- return new HashMap() {{ put("foo4", "bar4"); }};
- }
- }
-}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/FactoryConfigurationAdapterServiceTestWithPublisher.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/FactoryConfigurationAdapterServiceTestWithPublisher.java
deleted file mode 100644
index 9cff105..0000000
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/FactoryConfigurationAdapterServiceTestWithPublisher.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.dm.test.bundle.annotation.publisher;
-
-import java.io.IOException;
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Map;
-
-import org.apache.felix.dm.annotation.api.Component;
-import org.apache.felix.dm.annotation.api.FactoryConfigurationAdapterService;
-import org.apache.felix.dm.annotation.api.Init;
-import org.apache.felix.dm.annotation.api.LifecycleController;
-import org.apache.felix.dm.annotation.api.Property;
-import org.apache.felix.dm.annotation.api.ServiceDependency;
-import org.apache.felix.dm.annotation.api.Start;
-import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-
-/**
- * Test a FactoryConfigurationAdapterService which provides its interface using a @ServiceLifecycle.
- */
-public class FactoryConfigurationAdapterServiceTestWithPublisher
-{
- public interface Provider
- {
- }
-
- @Component
- public static class Consumer
- {
- @ServiceDependency(filter="(name=FactoryConfigurationAdapterServiceTestWithPublisher)")
- Sequencer m_sequencer;
-
- @ServiceDependency(required=false, removed = "unbind")
- void bind(Map properties, Provider provider)
- {
- m_sequencer.step(1);
- // check ProviderImpl properties
- if ("bar".equals(properties.get("foo")))
- {
- m_sequencer.step(2);
- }
- // check extra ProviderImpl properties (returned by start method)
- if ("bar2".equals(properties.get("foo2")))
- {
- m_sequencer.step(3);
- }
- // check Factory Configuration properties
- if ("bar3".equals(properties.get("foo3")))
- {
- m_sequencer.step(4);
- }
- }
-
- void unbind(Provider provider)
- {
- m_sequencer.step(5);
- }
- }
-
- @Component
- public static class Configurator
- {
- @ServiceDependency
- void bind(ConfigurationAdmin cm) throws IOException
- {
- Configuration cf = cm.createFactoryConfiguration("MyPid", null);
- cf.update(new Hashtable() {{ put("foo3", "bar3"); }});
- }
- }
-
- @FactoryConfigurationAdapterService(propagate=true, properties={@Property(name="foo", value="bar")}, factoryPid="MyPid", updated="updated")
- public static class ProviderImpl implements Provider
- {
- @LifecycleController
- Runnable m_publisher; // injected and used to register our service
-
- @LifecycleController(start=false)
- Runnable m_unpublisher; // injected and used to unregister our service
-
- @ServiceDependency(filter="(name=FactoryConfigurationAdapterServiceTestWithPublisher)")
- Sequencer m_sequencer;
-
- void updated(Dictionary conf) {
- }
-
- @Init
- void init()
- {
- // register service in 1 second
- Utils.schedule(m_publisher, 1000);
- // unregister the service in 2 seconds
- Utils.schedule(m_unpublisher, 2000);
- }
-
- @Start
- Map start()
- {
- // Add some extra service properties ... they will be appended to the one we have defined
- // in the @Service annotation.
- return new HashMap() {{ put("foo2", "bar2"); }};
- }
-
- }
-}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/FactoryServiceTestWthPublisher.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/FactoryServiceTestWthPublisher.java
deleted file mode 100644
index 488c425..0000000
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/FactoryServiceTestWthPublisher.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.dm.test.bundle.annotation.publisher;
-
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.felix.dm.annotation.api.Component;
-import org.apache.felix.dm.annotation.api.Init;
-import org.apache.felix.dm.annotation.api.LifecycleController;
-import org.apache.felix.dm.annotation.api.Property;
-import org.apache.felix.dm.annotation.api.ServiceDependency;
-import org.apache.felix.dm.annotation.api.Start;
-import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
-
-/**
- * A Service instantiated from a FactorySet, and which registers/unregisters its service,
- * using the @ServiceLifecycle annotation.
- */
-public class FactoryServiceTestWthPublisher
-{
- public interface Provider
- {
- }
-
- @Component
- public static class Consumer
- {
- @ServiceDependency(filter="(name=FactoryServiceTestWthPublisher)")
- Sequencer m_sequencer;
-
- @ServiceDependency(required=false, removed = "unbind")
- void bind(Map properties, Provider provider)
- {
- m_sequencer.step(1);
- if ("bar".equals(properties.get("foo")))
- {
- m_sequencer.step(2);
- }
- if ("bar2".equals(properties.get("foo2")))
- {
- m_sequencer.step(3);
- }
- if ("bar3".equals(properties.get("foo3")))
- {
- m_sequencer.step(4);
- }
- }
-
- void unbind(Provider provider)
- {
- m_sequencer.step(5);
- }
- }
-
- @Component(factorySet="MyFactory", properties={@Property(name="foo", value="bar")})
- public static class ProviderImpl implements Provider
- {
- @LifecycleController
- Runnable m_publisher; // injected and used to register our service
-
- @LifecycleController(start=false)
- Runnable m_unpublisher; // injected and used to unregister our service
-
- @ServiceDependency(filter="(name=FactoryServiceTestWthPublisher)")
- Sequencer m_sequencer;
-
- @Init
- void init()
- {
- // register service in 1 second
- Utils.schedule(m_publisher, 1000);
- // unregister the service in 2 seconds
- Utils.schedule(m_unpublisher, 2000);
- }
-
- @Start
- Map start()
- {
- // At this point, our service properties are the one specified in our @Service annotation + the one specified by our Factory.
- // We also append an extra service property here:
- return new HashMap() {{ put("foo3", "bar3"); }};
- }
- }
-
- @Component
- public static class ProviderImplFactory
- {
- @ServiceDependency(filter="(" + Component.FACTORY_NAME + "=MyFactory)")
- void bind(Set<Dictionary> m_providerImplFactory)
- {
- m_providerImplFactory.add(new Hashtable() {{ put("foo2", "bar2"); }});
- }
- }
-}
diff --git a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/PublisherAnnotationTest.java b/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/PublisherAnnotationTest.java
deleted file mode 100644
index 8ef1b27..0000000
--- a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/PublisherAnnotationTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.dm.test.annotation;
-
-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 static org.ops4j.pax.exam.CoreOptions.systemProperty;
-
-import org.apache.felix.dm.DependencyManager;
-import org.apache.felix.dm.test.Base;
-import org.apache.felix.dm.test.BundleGenerator;
-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;
-
-/**
- * Use case: Verify the @ServiceLifecycle annotation, which allows a component to activate/deactivate itself programatically.
- */
-@RunWith(JUnit4TestRunner.class)
-public class PublisherAnnotationTest extends AnnotationBase
-{
- @Configuration
- public static Option[] configuration()
- {
- return options(
- systemProperty(DMLOG_PROPERTY).value( "true" ),
- provision(
- mavenBundle().groupId("org.osgi").artifactId("org.osgi.compendium").version(Base.OSGI_SPEC_VERSION),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager").versionAsInProject(),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.configadmin").version("1.2.4"),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager.runtime").versionAsInProject()),
- provision(
- new BundleGenerator()
- .set(Constants.BUNDLE_SYMBOLICNAME, "PublisherAnnotationsTest")
- .set("Export-Package", "org.apache.felix.dm.test.bundle.annotation.sequencer")
- .set("Private-Package", "org.apache.felix.dm.test.bundle.annotation.publisher")
- .set("Import-Package", "*")
- .set("-plugin", "org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin")
- .build()));
- }
-
- /**
- * A Service that just registers/unregisters its service, using the @ServiceLifecycle annotation.
- */
- @Test
- public void testServiceWithPublisher(BundleContext context)
- {
- DependencyManager m = new DependencyManager(context);
- m.add(makeSequencer(m, "ServiceTestWthPublisher"));
- m_ensure.waitForStep(4, 10000);
- }
-
- /**
- * A Service instantiated from a FactorySet, and which registers/unregisters its service,
- * using the @ServiceLifecycle annotation.
- */
- @Test
- public void testFactoryServiceWithPublisher(BundleContext context)
- {
- DependencyManager m = new DependencyManager(context);
- m.add(makeSequencer(m, "FactoryServiceTestWthPublisher"));
- m_ensure.waitForStep(5, 10000);
- }
-
- /**
- * Test an AdapterService which provides its interface using a @ServiceLifecycle.
- */
- @Test
- public void testAdapterServiceWithPublisher(BundleContext context)
- {
- DependencyManager m = new DependencyManager(context);
- m.add(makeSequencer(m, "AdapterServiceTestWithPublisher"));
- m_ensure.waitForStep(6, 10000);
- }
-
- /**
- * Test a BundleAdapterService which provides its interface using a @ServiceLifecycle.
- */
- @Test
- public void testBundleAdapterServiceWithPublisher(BundleContext context)
- {
- DependencyManager m = new DependencyManager(context);
- m.add(makeSequencer(m, "BundleAdapterServiceTestWithPublisher"));
- m_ensure.waitForStep(5, 10000);
- }
-
- /**
- * Test a ResourceAdapterService which provides its interface using a @ServiceLifecycle.
- */
- @Test
- public void TestResourceAdapterServiceWithPublisher(BundleContext context)
- {
- DependencyManager m = new DependencyManager(context);
- m.add(makeSequencer(m, "ResourceAdapterServiceTestWithPublisher"));
- m_ensure.waitForStep(5, 10000);
- }
-
- /**
- * Test a FactoryConfigurationAdapterService which provides its interface using a @ServiceLifecycle.
- */
- @Test
- public void testFactoryAdapterServiceWithPublisher(BundleContext context)
- {
- DependencyManager m = new DependencyManager(context);
- m.add(makeSequencer(m, "FactoryConfigurationAdapterServiceTestWithPublisher"));
- m_ensure.waitForStep(5, 10000);
- }
-}
diff --git a/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/AdapterServiceTestWithPublisher.java b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/AdapterServiceTestWithPublisher.java
new file mode 100644
index 0000000..411d6d9
--- /dev/null
+++ b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/AdapterServiceTestWithPublisher.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.dependencymanager.test2.components;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.felix.dm.annotation.api.AdapterService;
+import org.apache.felix.dm.annotation.api.Component;
+import org.apache.felix.dm.annotation.api.Init;
+import org.apache.felix.dm.annotation.api.LifecycleController;
+import org.apache.felix.dm.annotation.api.Property;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
+import org.apache.felix.dm.annotation.api.Start;
+
+/**
+ * Test an AdapterService which provides its interface using a @ServiceLifecycle.
+ */
+public class AdapterServiceTestWithPublisher {
+ public static final String ENSURE = "AdapterServiceTestWithPublisher";
+
+ public interface Provider {
+ }
+
+ public interface Provider2 {
+ }
+
+ @Component
+ public static class Consumer {
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
+ volatile Ensure m_sequencer;
+
+ @ServiceDependency(required = false, removed = "unbind")
+ void bind(Map properties, Provider2 provider) {
+ m_sequencer.step(1);
+ // check ProviderImpl properties
+ if ("bar".equals(properties.get("foo"))) {
+ m_sequencer.step(2);
+ }
+ // check extra ProviderImpl properties (returned by start method)
+ if ("bar2".equals(properties.get("foo2"))) {
+ m_sequencer.step(3);
+ }
+ // check Provider2Impl properties
+ if ("bar3".equals(properties.get("foo3"))) {
+ m_sequencer.step(4);
+ }
+ // check extra Provider2Impl properties (returned by start method)
+ if ("bar4".equals(properties.get("foo4"))) {
+ m_sequencer.step(5);
+ }
+
+ }
+
+ void unbind(Provider2 provider) {
+ m_sequencer.step(6);
+ }
+ }
+
+ @Component(properties = {@Property(name = "foo", value = "bar")})
+ public static class ProviderImpl implements Provider {
+ @Start
+ Map start() {
+ // Add some extra service properties ... they will be appended to the one we have defined
+ // in the @Service annotation.
+ return new HashMap() {
+ {
+ put("foo2", "bar2");
+ }
+ };
+ }
+ }
+
+ @AdapterService(properties = {@Property(name = "foo3", value = "bar3")}, adapteeService = Provider.class)
+ public static class Provider2Impl implements Provider2 {
+ @LifecycleController
+ volatile Runnable m_publisher; // injected and used to register our service
+
+ @LifecycleController(start = false)
+ volatile Runnable m_unpublisher; // injected and used to unregister our service
+
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
+ volatile Ensure m_sequencer;
+
+ @Init
+ void init() {
+ // register service in 1 second
+ Utils.schedule(m_publisher, 1000);
+ // unregister the service in 2 seconds
+ Utils.schedule(m_unpublisher, 2000);
+ }
+
+ @Start
+ Map start() {
+ // Add some extra service properties ... they will be appended to the one we have defined
+ // in the @Service annotation.
+ return new HashMap() {
+ {
+ put("foo4", "bar4");
+ }
+ };
+ }
+ }
+}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/BundleAdapterServiceTestWithPublisher.java b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/BundleAdapterServiceTestWithPublisher.java
similarity index 60%
rename from dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/BundleAdapterServiceTestWithPublisher.java
rename to dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/BundleAdapterServiceTestWithPublisher.java
index e92b4f5..5f3a138 100644
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/BundleAdapterServiceTestWithPublisher.java
+++ b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/BundleAdapterServiceTestWithPublisher.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.dm.test.bundle.annotation.publisher;
+package org.apache.felix.dependencymanager.test2.components;
import java.util.HashMap;
import java.util.Map;
@@ -28,41 +28,35 @@
import org.apache.felix.dm.annotation.api.Property;
import org.apache.felix.dm.annotation.api.ServiceDependency;
import org.apache.felix.dm.annotation.api.Start;
-import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
import org.osgi.framework.Bundle;
/**
* Test a BundleAdapterService which provides its interface using a @ServiceLifecycle.
*/
-public class BundleAdapterServiceTestWithPublisher
-{
- public interface Provider
- {
+public class BundleAdapterServiceTestWithPublisher {
+ public static final String ENSURE = "BundleAdapterServiceTestWithPublisher";
+
+ public interface Provider {
}
@Component
- public static class Consumer
- {
- @ServiceDependency(filter="(name=BundleAdapterServiceTestWithPublisher)")
- Sequencer m_sequencer;
-
- @ServiceDependency(required=false, removed = "unbind")
- void bind(Map properties, Provider provider)
- {
+ public static class Consumer {
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
+ volatile Ensure m_sequencer;
+
+ @ServiceDependency(required = false, removed = "unbind")
+ void bind(Map properties, Provider provider) {
m_sequencer.step(1);
// check ProviderImpl properties
- if ("bar".equals(properties.get("foo")))
- {
+ if ("bar".equals(properties.get("foo"))) {
m_sequencer.step(2);
}
// check extra ProviderImpl properties (returned by start method)
- if ("bar2".equals(properties.get("foo2")))
- {
+ if ("bar2".equals(properties.get("foo2"))) {
m_sequencer.step(3);
}
// check properties propagated from bundle
- if ("org.apache.felix.dependencymanager".equals(properties.get("Bundle-SymbolicName")))
- {
+ if ("org.apache.felix.dependencymanager".equals(properties.get("Bundle-SymbolicName"))) {
m_sequencer.step(4);
} else {
Thread.dumpStack();
@@ -70,42 +64,40 @@
}
}
- void unbind(Provider provider)
- {
+ void unbind(Provider provider) {
m_sequencer.step(5);
}
}
-
- @BundleAdapterService(properties={@Property(name="foo", value="bar")},
- filter = "(Bundle-SymbolicName=org.apache.felix.dependencymanager)",
- stateMask = Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE,
- propagate = true)
- public static class ProviderImpl implements Provider
- {
+
+ @BundleAdapterService(properties = {@Property(name = "foo", value = "bar")}, filter = "(Bundle-SymbolicName=org.apache.felix.dependencymanager)", stateMask = Bundle.INSTALLED
+ | Bundle.RESOLVED | Bundle.ACTIVE, propagate = true)
+ public static class ProviderImpl implements Provider {
@LifecycleController
- Runnable m_publisher; // injected and used to register our service
-
- @LifecycleController(start=false)
- Runnable m_unpublisher; // injected and used to unregister our service
-
- @ServiceDependency(filter="(name=BundleAdapterServiceTestWithPublisher)")
- Sequencer m_sequencer;
+ volatile Runnable m_publisher; // injected and used to register our service
+
+ @LifecycleController(start = false)
+ volatile Runnable m_unpublisher; // injected and used to unregister our service
+
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
+ volatile Ensure m_sequencer;
@Init
- void init()
- {
+ void init() {
// register service in 1 second
Utils.schedule(m_publisher, 1000);
// unregister the service in 2 seconds
Utils.schedule(m_unpublisher, 2000);
}
-
+
@Start
- Map start()
- {
+ Map start() {
// Add some extra service properties ... they will be appended to the one we have defined
// in the @Service annotation.
- return new HashMap() {{ put("foo2", "bar2"); }};
+ return new HashMap() {
+ {
+ put("foo2", "bar2");
+ }
+ };
}
}
}
diff --git a/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ExtraAdapterServiceProperties.java b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ExtraAdapterServiceProperties.java
index ccba089..844d730 100644
--- a/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ExtraAdapterServiceProperties.java
+++ b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ExtraAdapterServiceProperties.java
@@ -32,6 +32,8 @@
* from it's start callback
*/
public class ExtraAdapterServiceProperties {
+ public final static String ENSURE = "ExtraAdapterServiceProperties";
+
public interface Provider {
}
@@ -58,7 +60,7 @@
@Component
public static class Consumer {
- @ServiceDependency(filter = "(name=testExtraAdapterServiceProperties)")
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
volatile Ensure m_sequencer;
private volatile Map m_properties;
diff --git a/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ExtraAspectServiceProperties.java b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ExtraAspectServiceProperties.java
index 7b2c7c6..3b0b40d 100644
--- a/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ExtraAspectServiceProperties.java
+++ b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ExtraAspectServiceProperties.java
@@ -32,6 +32,8 @@
* from it's start callback
*/
public class ExtraAspectServiceProperties {
+ public final static String ENSURE = "ExtraAspectServiceProperties";
+
public interface Provider {
}
@@ -53,7 +55,7 @@
@Component
public static class Consumer {
- @ServiceDependency(filter = "(name=testExtraAspectServiceProperties)")
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
volatile Ensure m_sequencer;
private volatile Map m_properties;
diff --git a/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ExtraFactoryServiceProperties.java b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ExtraFactoryServiceProperties.java
index a39b5f3..e233acd 100644
--- a/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ExtraFactoryServiceProperties.java
+++ b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ExtraFactoryServiceProperties.java
@@ -30,10 +30,13 @@
import org.apache.felix.dm.annotation.api.Start;
public class ExtraFactoryServiceProperties {
+ public final static String FACTORYSET = "ExtraFactoryServiceProperties.FACTORYSET";
+ public final static String ENSURE = "ExtraFactoryServiceProperties";
+
public interface Provider {
}
- @Component(properties = {@Property(name = "foo", value = "bar")}, factorySet = "MyFactory")
+ @Component(properties = {@Property(name = "foo", value = "bar")}, factorySet = FACTORYSET)
public static class ProviderImpl implements Provider {
@Start
Map<String, String> start() {
@@ -47,7 +50,7 @@
@Component
public static class ProviderImplFactory {
- @ServiceDependency
+ @ServiceDependency(filter = "(" + Component.FACTORY_NAME + "=" + FACTORYSET + ")")
volatile Set<Dictionary> m_factory;
@Start
@@ -62,7 +65,7 @@
@Component
public static class Consumer {
- @ServiceDependency(filter = "(name=testExtraFactoryServiceProperties)")
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
volatile Ensure m_sequencer;
private volatile Map m_properties;
diff --git a/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ExtraServiceProperties.java b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ExtraServiceProperties.java
index 530aa7a..5f931e4 100644
--- a/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ExtraServiceProperties.java
+++ b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ExtraServiceProperties.java
@@ -31,6 +31,8 @@
* from it's start callback
*/
public class ExtraServiceProperties {
+ public final static String ENSURE = "ExtraServiceProperties";
+
public interface Provider {
}
@@ -48,7 +50,7 @@
@Component
public static class Consumer {
- @ServiceDependency(filter = "(name=testExtraServiceProperties)")
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
volatile Ensure m_sequencer;
private volatile Map m_properties;
diff --git a/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/FactoryConfigurationAdapterServiceTestWithPublisher.java b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/FactoryConfigurationAdapterServiceTestWithPublisher.java
new file mode 100644
index 0000000..1dff92a
--- /dev/null
+++ b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/FactoryConfigurationAdapterServiceTestWithPublisher.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.dependencymanager.test2.components;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.apache.felix.dm.annotation.api.Component;
+import org.apache.felix.dm.annotation.api.FactoryConfigurationAdapterService;
+import org.apache.felix.dm.annotation.api.Init;
+import org.apache.felix.dm.annotation.api.LifecycleController;
+import org.apache.felix.dm.annotation.api.Property;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
+import org.apache.felix.dm.annotation.api.Start;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/**
+ * Test a FactoryConfigurationAdapterService which provides its interface using a @ServiceLifecycle.
+ */
+public class FactoryConfigurationAdapterServiceTestWithPublisher {
+ public final static String PID="FactoryConfigurationAdapterServiceTestWithPublisher.PID";
+ public final static String ENSURE = "FactoryConfigurationAdapterServiceTestWithPublisher";
+
+ public interface Provider {
+ }
+
+ @Component
+ public static class Consumer {
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
+ volatile Ensure m_sequencer;
+
+ @ServiceDependency(required = false, removed = "unbind")
+ void bind(Map properties, Provider provider) {
+ m_sequencer.step(1);
+ // check ProviderImpl properties
+ if ("bar".equals(properties.get("foo"))) {
+ m_sequencer.step(2);
+ }
+ // check extra ProviderImpl properties (returned by start method)
+ if ("bar2".equals(properties.get("foo2"))) {
+ m_sequencer.step(3);
+ }
+ // check Factory Configuration properties
+ if ("bar3".equals(properties.get("foo3"))) {
+ m_sequencer.step(4);
+ }
+ }
+
+ void unbind(Provider provider) {
+ m_sequencer.step(5);
+ }
+ }
+
+ @Component
+ public static class Configurator {
+ @ServiceDependency
+ void bind(ConfigurationAdmin cm) throws IOException {
+ Configuration cf = cm.createFactoryConfiguration(PID, null);
+ cf.update(new Hashtable() {
+ {
+ put("foo3", "bar3");
+ }
+ });
+ }
+ }
+
+ @FactoryConfigurationAdapterService(propagate = true, properties = {@Property(name = "foo", value = "bar")}, factoryPid = PID, updated = "updated")
+ public static class ProviderImpl implements Provider {
+ @LifecycleController
+ volatile Runnable m_publisher; // injected and used to register our service
+
+ @LifecycleController(start = false)
+ volatile Runnable m_unpublisher; // injected and used to unregister our service
+
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
+ volatile Ensure m_sequencer;
+
+ void updated(Dictionary conf) {
+ }
+
+ @Init
+ void init() {
+ // register service in 1 second
+ Utils.schedule(m_publisher, 1000);
+ // unregister the service in 2 seconds
+ Utils.schedule(m_unpublisher, 2000);
+ }
+
+ @Start
+ Map start() {
+ // Add some extra service properties ... they will be appended to the one we have defined
+ // in the @Service annotation.
+ return new HashMap() {
+ {
+ put("foo2", "bar2");
+ }
+ };
+ }
+
+ }
+}
diff --git a/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/FactoryServiceTestWthPublisher.java b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/FactoryServiceTestWthPublisher.java
new file mode 100644
index 0000000..31af18e
--- /dev/null
+++ b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/FactoryServiceTestWthPublisher.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.dependencymanager.test2.components;
+
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.felix.dm.annotation.api.Component;
+import org.apache.felix.dm.annotation.api.Init;
+import org.apache.felix.dm.annotation.api.LifecycleController;
+import org.apache.felix.dm.annotation.api.Property;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
+import org.apache.felix.dm.annotation.api.Start;
+
+/**
+ * A Service instantiated from a FactorySet, and which registers/unregisters its service,
+ * using the @ServiceLifecycle annotation.
+ */
+public class FactoryServiceTestWthPublisher {
+ public final static String FACTORY_SET = "FactoryServiceTestWthPublisher.FACTORYSET";
+ public final static String ENSURE = "FactoryServiceTestWthPublisher";
+
+ public interface Provider {
+ }
+
+ @Component
+ public static class Consumer {
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
+ volatile Ensure m_sequencer;
+
+ @ServiceDependency(required = false, removed = "unbind")
+ void bind(Map properties, Provider provider) {
+ System.out.println("BIND: " + provider + ", map=" + properties);
+ m_sequencer.step(1);
+ if ("bar".equals(properties.get("foo"))) {
+ m_sequencer.step(2);
+ }
+ if ("bar2".equals(properties.get("foo2"))) {
+ m_sequencer.step(3);
+ }
+ if ("bar3".equals(properties.get("foo3"))) {
+ m_sequencer.step(4);
+ }
+ }
+
+ void unbind(Provider provider) {
+ m_sequencer.step(5);
+ }
+ }
+
+ @Component(factorySet = FACTORY_SET, properties = {@Property(name = "foo", value = "bar")})
+ public static class ProviderImpl implements Provider {
+ @LifecycleController
+ volatile Runnable m_publisher; // injected and used to register our service
+
+ @LifecycleController(start = false)
+ volatile Runnable m_unpublisher; // injected and used to unregister our service
+
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
+ volatile Ensure m_sequencer;
+
+ @Init
+ void init() {
+ // register service in 1 second
+ Utils.schedule(m_publisher, 1000);
+ // unregister the service in 2 seconds
+ Utils.schedule(m_unpublisher, 2000);
+ }
+
+ @Start
+ Map start() {
+ // At this point, our service properties are the one specified in our @Service annotation + the one specified by our Factory.
+ // We also append an extra service property here:
+ return new HashMap() {
+ {
+ put("foo3", "bar3");
+ }
+ };
+ }
+ }
+
+ @Component
+ public static class ProviderImplFactory {
+ @ServiceDependency(filter = "(" + Component.FACTORY_NAME + "=" + FACTORY_SET + ")")
+ void bind(Set<Dictionary> m_providerImplFactory) {
+ m_providerImplFactory.add(new Hashtable() {
+ {
+ put("foo2", "bar2");
+ }
+ });
+ }
+ }
+}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/ResourceAdapterServiceTestWithPublisher.java b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ResourceAdapterServiceTestWithPublisher.java
similarity index 65%
rename from dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/ResourceAdapterServiceTestWithPublisher.java
rename to dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ResourceAdapterServiceTestWithPublisher.java
index 45a1f46..c62af10 100644
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/ResourceAdapterServiceTestWithPublisher.java
+++ b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ResourceAdapterServiceTestWithPublisher.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.dm.test.bundle.annotation.publisher;
+package org.apache.felix.dependencymanager.test2.components;
import java.net.URL;
import java.util.HashMap;
@@ -36,7 +36,6 @@
import org.apache.felix.dm.annotation.api.ResourceAdapterService;
import org.apache.felix.dm.annotation.api.ServiceDependency;
import org.apache.felix.dm.annotation.api.Start;
-import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
@@ -44,94 +43,76 @@
/**
* Test a ResourceAdapterService which provides its interface using a @ServiceLifecycle.
*/
-public class ResourceAdapterServiceTestWithPublisher
-{
- public interface Provider
- {
+public class ResourceAdapterServiceTestWithPublisher {
+ public static final String ENSURE = "ResourceAdapterServiceTestWithPublisher";
+
+ public interface Provider {
}
@Component
- public static class Consumer
- {
- @ServiceDependency(filter="(name=ResourceAdapterServiceTestWithPublisher)")
- Sequencer m_sequencer;
-
- @ServiceDependency(required=false, removed = "unbind")
- void bind(Map properties, Provider provider)
- {
+ public static class Consumer {
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
+ volatile Ensure m_sequencer;
+
+ @ServiceDependency(required = false, removed = "unbind")
+ void bind(Map properties, Provider provider) {
m_sequencer.step(1);
// check ProviderImpl properties
- if ("bar".equals(properties.get("foo")))
- {
+ if ("bar".equals(properties.get("foo"))) {
m_sequencer.step(2);
}
// check extra ProviderImpl properties (returned by start method)
- if ("bar2".equals(properties.get("foo2")))
- {
+ if ("bar2".equals(properties.get("foo2"))) {
m_sequencer.step(3);
}
// check properties propagated by the resource adapter
- if ("/path/to/test1.txt".equals(properties.get(ResourceHandler.PATH)))
- {
+ if ("/path/to/test1.txt".equals(properties.get(ResourceHandler.PATH))) {
m_sequencer.step(4);
}
- if ("localhost".equals(properties.get(ResourceHandler.HOST)))
- {
+ if ("localhost".equals(properties.get(ResourceHandler.HOST))) {
m_sequencer.step(5);
}
}
- void unbind(Provider provider)
- {
+ void unbind(Provider provider) {
m_sequencer.step(6);
}
}
-
+
@Component
- public static class ResourceProvider
- {
+ public static class ResourceProvider {
@Inject
private volatile BundleContext m_context;
private final Map m_handlers = new HashMap();
private URL[] m_resources;
-
+
public ResourceProvider() throws Exception {
- m_resources = new URL[] {
- new URL("file://localhost/path/to/test1.txt"),
- new URL("file://localhost/path/to/test2.txt"),
- new URL("file://localhost/path/to/README.doc")
- };
+ m_resources = new URL[]{new URL("file://localhost/path/to/test1.txt"),
+ new URL("file://localhost/path/to/test2.txt"), new URL("file://localhost/path/to/README.doc")};
}
-
+
/**
* Handles a new Resource consumer
* @param serviceProperties
* @param handler
*/
- @ServiceDependency(removed = "remove", required=false)
- public void add(Map serviceProperties, ResourceHandler handler)
- {
+ @ServiceDependency(removed = "remove", required = false)
+ public void add(Map serviceProperties, ResourceHandler handler) {
String filterString = (String) serviceProperties.get("filter");
Filter filter = null;
if (filterString != null) {
- try
- {
+ try {
filter = m_context.createFilter(filterString);
- }
- catch (InvalidSyntaxException e)
- {
+ } catch (InvalidSyntaxException e) {
Assert.fail("Could not create filter for resource handler: " + e);
return;
}
}
- synchronized (m_handlers)
- {
+ synchronized (m_handlers) {
m_handlers.put(handler, filter);
}
- for (int i = 0; i < m_resources.length; i++)
- {
- if (filter == null || filter.match(ResourceUtil.createProperties(m_resources[i])))
- {
+ for (int i = 0; i < m_resources.length; i++) {
+ if (filter == null || filter.match(ResourceUtil.createProperties(m_resources[i]))) {
handler.added(m_resources[i]);
}
}
@@ -141,22 +122,17 @@
* Remove a Resource consumer.bar
* @param handler
*/
- public void remove(ResourceHandler handler)
- {
+ public void remove(ResourceHandler handler) {
Filter filter;
- synchronized (m_handlers)
- {
+ synchronized (m_handlers) {
filter = (Filter) m_handlers.remove(handler);
}
removeResources(handler, filter);
}
- private void removeResources(ResourceHandler handler, Filter filter)
- {
- for (int i = 0; i < m_resources.length; i++)
- {
- if (filter == null || filter.match(ResourceUtil.createProperties(m_resources[i])))
- {
+ private void removeResources(ResourceHandler handler, Filter filter) {
+ for (int i = 0; i < m_resources.length; i++) {
+ if (filter == null || filter.match(ResourceUtil.createProperties(m_resources[i]))) {
handler.removed(m_resources[i]);
}
}
@@ -167,52 +143,48 @@
* provide our Resources anymore.
*/
@Destroy
- public void destroy()
- {
+ public void destroy() {
Entry[] handlers;
- synchronized (m_handlers)
- {
+ synchronized (m_handlers) {
handlers = (Entry[]) m_handlers.entrySet().toArray(new Entry[m_handlers.size()]);
}
- for (int i = 0; i < handlers.length; i++)
- {
+ for (int i = 0; i < handlers.length; i++) {
removeResources((ResourceHandler) handlers[i].getKey(), (Filter) handlers[i].getValue());
}
}
}
-
- @ResourceAdapterService(filter = "(&(path=/path/to/test1.txt)(host=localhost))",
- properties = {@Property(name="foo", value="bar")},
- propagate = true)
- public static class ProviderImpl implements Provider
- {
+
+ @ResourceAdapterService(filter = "(&(path=/path/to/test1.txt)(host=localhost))", properties = {@Property(name = "foo", value = "bar")}, propagate = true)
+ public static class ProviderImpl implements Provider {
@LifecycleController
- Runnable m_publisher; // injected and used to register our service
-
- @LifecycleController(start=false)
- Runnable m_unpublisher; // injected and used to unregister our service
-
- @ServiceDependency(filter="(name=ResourceAdapterServiceTestWithPublisher)")
- Sequencer m_sequencer;
-
+ volatile Runnable m_publisher; // injected and used to register our service
+
+ @LifecycleController(start = false)
+ volatile Runnable m_unpublisher; // injected and used to unregister our service
+
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
+ volatile Ensure m_sequencer;
+
// Injected by reflection
- URL m_resource;
+ volatile URL m_resource;
@Init
- void init()
- {
+ void init() {
// register service in 1 second
Utils.schedule(m_publisher, 1000);
// unregister the service in 2 seconds
Utils.schedule(m_unpublisher, 2000);
}
-
+
@Start
- Map start()
- {
+ Map start() {
// Add some extra service properties ... they will be appended to the one we have defined
// in the @Service annotation.
- return new HashMap() {{ put("foo2", "bar2"); }};
+ return new HashMap() {
+ {
+ put("foo2", "bar2");
+ }
+ };
}
}
}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/ServiceTestWthPublisher.java b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ServiceTestWthPublisher.java
similarity index 60%
rename from dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/ServiceTestWthPublisher.java
rename to dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ServiceTestWthPublisher.java
index bfdddb4..d834619 100644
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/ServiceTestWthPublisher.java
+++ b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ServiceTestWthPublisher.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.dm.test.bundle.annotation.publisher;
+package org.apache.felix.dependencymanager.test2.components;
import java.util.HashMap;
import java.util.Map;
@@ -27,70 +27,65 @@
import org.apache.felix.dm.annotation.api.Property;
import org.apache.felix.dm.annotation.api.ServiceDependency;
import org.apache.felix.dm.annotation.api.Start;
-import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
/**
* A Service that just registers/unregisters its service, using the @ServiceLifecycle annotation.
*/
-public class ServiceTestWthPublisher
-{
- public interface Provider
- {
+public class ServiceTestWthPublisher {
+ public final static String ENSURE = "ServiceTestWthPublisher";
+
+ public interface Provider {
}
@Component
- public static class Consumer
- {
- @ServiceDependency(filter="(name=ServiceTestWthPublisher)")
- Sequencer m_sequencer;
-
- @ServiceDependency(required=false, removed = "unbind")
- void bind(Map properties, Provider provider)
- {
+ public static class Consumer {
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
+ volatile Ensure m_sequencer;
+
+ @ServiceDependency(required = false, removed = "unbind")
+ void bind(Map properties, Provider provider) {
m_sequencer.step(1);
- if ("bar".equals(properties.get("foo")))
- {
+ if ("bar".equals(properties.get("foo"))) {
m_sequencer.step(2);
}
- if ("bar2".equals(properties.get("foo2")))
- {
+ if ("bar2".equals(properties.get("foo2"))) {
m_sequencer.step(3);
}
}
- void unbind(Provider provider)
- {
+ void unbind(Provider provider) {
m_sequencer.step(4);
}
}
-
- @Component(properties={@Property(name="foo", value="bar")})
- public static class ProviderImpl implements Provider
- {
+
+ @Component(properties = {@Property(name = "foo", value = "bar")})
+ public static class ProviderImpl implements Provider {
@LifecycleController
- Runnable m_publisher; // injected and used to register our service
-
- @LifecycleController(start=false)
- Runnable m_unpublisher; // injected and used to unregister our service
-
- @ServiceDependency(filter="(name=ServiceTestWthPublisher)")
- Sequencer m_sequencer;
+ volatile Runnable m_publisher; // injected and used to register our service
+
+ @LifecycleController(start = false)
+ volatile Runnable m_unpublisher; // injected and used to unregister our service
+
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
+ volatile Ensure m_sequencer;
@Init
- void init()
- {
+ void init() {
// register service in 1 second
Utils.schedule(m_publisher, 1000);
// unregister the service in 2 seconds
Utils.schedule(m_unpublisher, 2000);
}
-
+
@Start
- Map start()
- {
+ Map start() {
// Add some extra service properties ... they will be appended to the one we have defined
// in the @Service annotation.
- return new HashMap() {{ put("foo2", "bar2"); }};
+ return new HashMap() {
+ {
+ put("foo2", "bar2");
+ }
+ };
}
}
}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/Utils.java b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/Utils.java
similarity index 81%
rename from dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/Utils.java
rename to dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/Utils.java
index 0ec0cfb..aec4356 100644
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/publisher/Utils.java
+++ b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/Utils.java
@@ -16,21 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.dm.test.bundle.annotation.publisher;
+package org.apache.felix.dependencymanager.test2.components;
-public class Utils
-{
- public static void schedule(final Runnable task, final long n)
- {
+public class Utils {
+ public static void schedule(final Runnable task, final long n) {
Thread t = new Thread() {
- public void run()
- {
- try
- {
+ public void run() {
+ try {
sleep(n);
- }
- catch (InterruptedException e)
- {
+ } catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
diff --git a/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/ExtraServicePropertiesTest.java b/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/ExtraServicePropertiesTest.java
index b5f1060..1707d0a 100644
--- a/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/ExtraServicePropertiesTest.java
+++ b/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/ExtraServicePropertiesTest.java
@@ -19,6 +19,10 @@
package org.apache.felix.dependencymanager.test2.integration.annotations;
import org.apache.felix.dependencymanager.test2.components.Ensure;
+import org.apache.felix.dependencymanager.test2.components.ExtraAdapterServiceProperties;
+import org.apache.felix.dependencymanager.test2.components.ExtraAspectServiceProperties;
+import org.apache.felix.dependencymanager.test2.components.ExtraFactoryServiceProperties;
+import org.apache.felix.dependencymanager.test2.components.ExtraServiceProperties;
import org.apache.felix.dependencymanager.test2.integration.common.TestBase;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -36,7 +40,7 @@
@Test
public void testExtraServiceProperties() {
Ensure e = new Ensure();
- ServiceRegistration sr = register(e, "testExtraServiceProperties");
+ ServiceRegistration sr = register(e, ExtraServiceProperties.ENSURE);
e.waitForStep(2, 10000);
sr.unregister();
}
@@ -47,7 +51,7 @@
@Test
public void testExtraFactoryServiceProperties() {
Ensure e = new Ensure();
- ServiceRegistration sr = register(e, "testExtraFactoryServiceProperties");
+ ServiceRegistration sr = register(e, ExtraFactoryServiceProperties.ENSURE);
e.waitForStep(3, 10000);
sr.unregister();
}
@@ -58,7 +62,7 @@
@Test
public void testExtraAdapterServiceProperties() {
Ensure e = new Ensure();
- ServiceRegistration sr = register(e, "testExtraAdapterServiceProperties");
+ ServiceRegistration sr = register(e, ExtraAdapterServiceProperties.ENSURE);
e.waitForStep(3, 10000);
sr.unregister();
}
@@ -69,7 +73,7 @@
@Test
public void testExtraAspectServiceProperties() {
Ensure e = new Ensure();
- ServiceRegistration sr = register(e, "testExtraAspectServiceProperties");
+ ServiceRegistration sr = register(e, ExtraAspectServiceProperties.ENSURE);
e.waitForStep(3, 10000);
sr.unregister();
}
diff --git a/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/PublisherAnnotationTest.java b/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/PublisherAnnotationTest.java
new file mode 100644
index 0000000..84c0685
--- /dev/null
+++ b/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/PublisherAnnotationTest.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.dependencymanager.test2.integration.annotations;
+
+import org.apache.felix.dependencymanager.test2.components.AdapterServiceTestWithPublisher;
+import org.apache.felix.dependencymanager.test2.components.BundleAdapterServiceTestWithPublisher;
+import org.apache.felix.dependencymanager.test2.components.Ensure;
+import org.apache.felix.dependencymanager.test2.components.FactoryConfigurationAdapterServiceTestWithPublisher;
+import org.apache.felix.dependencymanager.test2.components.FactoryServiceTestWthPublisher;
+import org.apache.felix.dependencymanager.test2.components.ResourceAdapterServiceTestWithPublisher;
+import org.apache.felix.dependencymanager.test2.components.ServiceTestWthPublisher;
+import org.apache.felix.dependencymanager.test2.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceRegistration;
+
+@RunWith(PaxExam.class)
+public class PublisherAnnotationTest extends TestBase {
+ /**
+ * A Service that just registers/unregisters its service, using the @ServiceLifecycle annotation.
+ */
+ @Test
+ public void testServiceWithPublisher() {
+ Ensure e = new Ensure();
+ ServiceRegistration sr = register(e, ServiceTestWthPublisher.ENSURE);
+ e.waitForStep(4, 10000);
+ sr.unregister();
+ }
+
+ /**
+ * A Service instantiated from a FactorySet, and which registers/unregisters its service,
+ * using the @ServiceLifecycle annotation.
+ */
+ @Test
+ public void testFactoryServiceWithPublisher() {
+ Ensure e = new Ensure();
+ ServiceRegistration sr = register(e, FactoryServiceTestWthPublisher.ENSURE);
+ e.waitForStep(5, 10000);
+ sr.unregister();
+ }
+
+ /**
+ * Test an AdapterService which provides its interface using a @ServiceLifecycle.
+ */
+ @Test
+ public void testAdapterServiceWithPublisher() {
+ Ensure e = new Ensure();
+ ServiceRegistration sr = register(e, AdapterServiceTestWithPublisher.ENSURE);
+ e.waitForStep(6, 10000);
+ sr.unregister();
+ }
+
+ /**
+ * Test a BundleAdapterService which provides its interface using a @ServiceLifecycle.
+ */
+ @Test
+ public void testBundleAdapterServiceWithPublisher() {
+ Ensure e = new Ensure();
+ ServiceRegistration sr = register(e, BundleAdapterServiceTestWithPublisher.ENSURE);
+ e.waitForStep(5, 10000);
+ sr.unregister();
+ }
+
+ /**
+ * Test a ResourceAdapterService which provides its interface using a @ServiceLifecycle.
+ */
+ @Test
+ public void TestResourceAdapterServiceWithPublisher() {
+ Ensure e = new Ensure();
+ ServiceRegistration sr = register(e, ResourceAdapterServiceTestWithPublisher.ENSURE);
+ e.waitForStep(5, 10000);
+ sr.unregister();
+ }
+
+ /**
+ * Test a FactoryConfigurationAdapterService which provides its interface using a @ServiceLifecycle.
+ */
+ @Test
+ public void testFactoryAdapterServiceWithPublisher() {
+ Ensure e = new Ensure();
+ ServiceRegistration sr = register(e, FactoryConfigurationAdapterServiceTestWithPublisher.ENSURE);
+ e.waitForStep(5, 10000);
+ sr.unregister();
+ }
+}