pax-exam 3.0.0 migration ...
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1531752 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factoryconfadapter/ServiceClient.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factoryconfadapter/ServiceClient.java
deleted file mode 100644
index 8bafe0f..0000000
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factoryconfadapter/ServiceClient.java
+++ /dev/null
@@ -1,56 +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.factoryconfadapter;
-
-import java.util.Map;
-
-import org.apache.felix.dm.annotation.api.Component;
-import org.apache.felix.dm.annotation.api.ServiceDependency;
-
-@Component
-public class ServiceClient
-{
- @ServiceDependency(changed="changeServiceProvider")
- void addServiceProvider(Map props, ServiceInterface si) {
- // props should contain foo=bar, foo2=bar2
- if (! "bar".equals(props.get("foo")))
- {
- throw new IllegalArgumentException("configuration does not contain foo=bar: " + props);
- }
- if (! "bar2".equals(props.get("foo2")))
- {
- throw new IllegalArgumentException("configuration does not contain foo2=bar2: " + props);
- }
- si.doService();
- }
-
- void changeServiceProvider(Map props, ServiceInterface si)
- {
- // props should contain foo=bar, foo2=bar2_modified
- if (! "bar".equals(props.get("foo")))
- {
- throw new IllegalArgumentException("configuration does not contain foo=bar: " + props);
- }
- if (! "bar2_modified".equals(props.get("foo2")))
- {
- throw new IllegalArgumentException("configuration does not contain foo2=bar2: " + props);
- }
- si.doService();
- }
-}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factoryconfadapter/ServiceInterface.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factoryconfadapter/ServiceInterface.java
deleted file mode 100644
index 68d05fe..0000000
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factoryconfadapter/ServiceInterface.java
+++ /dev/null
@@ -1,24 +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.factoryconfadapter;
-
-public interface ServiceInterface
-{
- public void doService();
-}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factoryconfadapter/ServiceProvider.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factoryconfadapter/ServiceProvider.java
deleted file mode 100644
index 73e0b58..0000000
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factoryconfadapter/ServiceProvider.java
+++ /dev/null
@@ -1,141 +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.factoryconfadapter;
-
-import java.util.Dictionary;
-
-import org.apache.felix.dm.DependencyManager;
-import org.apache.felix.dm.annotation.api.FactoryConfigurationAdapterService;
-import org.apache.felix.dm.annotation.api.Inject;
-import org.apache.felix.dm.annotation.api.Property;
-import org.apache.felix.dm.annotation.api.Registered;
-import org.apache.felix.dm.annotation.api.ServiceDependency;
-import org.apache.felix.dm.annotation.api.Start;
-import org.apache.felix.dm.annotation.api.Stop;
-import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
-import org.osgi.framework.BundleContext;
-
-/**
- * This service is instantiated when a factory configuration is created from ConfigAdmin
- */
-@FactoryConfigurationAdapterService(factoryPid = "FactoryPidTest", properties = { @Property(name = "foo", value = "bar") }, propagate = true)
-public class ServiceProvider implements ServiceInterface
-{
- @ServiceDependency
- private Sequencer m_sequencer;
-
- private volatile boolean m_started;
-
- // Check auto config injections
- @Inject
- BundleContext m_bc;
- BundleContext m_bcNotInjected;
-
- @Inject
- DependencyManager m_dm;
- DependencyManager m_dmNotInjected;
-
- @Inject
- org.apache.felix.dm.Component m_component;
- org.apache.felix.dm.Component m_componentNotInjected;
-
- // Either initial config, or an updated config
- protected void updated(Dictionary conf)
- {
- if (m_started)
- {
- // conf should contain foo2=bar2_modified
- if (! "bar2_modified".equals(conf.get("foo2")))
- {
- m_sequencer.throwable(new Exception("configuration does not contain foo=bar"));
- }
- m_sequencer.step(4);
- }
- else
- {
- // conf should contain foo2=bar2
- if (! "bar2".equals(conf.get("foo2")))
- {
- throw new IllegalArgumentException("configuration does not contain foo2=bar2: " + conf);
- }
- }
- }
-
- @Start
- void start()
- {
- checkInjectedFields();
- m_started = true;
- m_sequencer.step(1);
- }
-
- @Registered
- void registered()
- {
- m_sequencer.step(3);
- }
-
- // The ServiceClient is invoking our service
- public void doService()
- {
- m_sequencer.step(); /* 2 or 5 */
- }
-
- @Stop
- void stop()
- {
- m_sequencer.step(6);
- }
-
- private void checkInjectedFields()
- {
- if (m_bc == null)
- {
- m_sequencer.throwable(new Exception("Bundle Context not injected"));
- return;
- }
- if (m_bcNotInjected != null)
- {
- m_sequencer.throwable(new Exception("Bundle Context must not be injected"));
- return;
- }
-
- if (m_dm == null)
- {
- m_sequencer.throwable(new Exception("DependencyManager not injected"));
- return;
- }
- if (m_dmNotInjected != null)
- {
- m_sequencer.throwable(new Exception("DependencyManager must not be injected"));
- return;
- }
-
- if (m_component == null)
- {
- m_sequencer.throwable(new Exception("Component not injected"));
- return;
- }
- if (m_componentNotInjected != null)
- {
- m_sequencer.throwable(new Exception("Component must not be injected"));
- return;
- }
- }
-}
diff --git a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/FactoryConfigurationAdapterAnnotationTest.java b/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/FactoryConfigurationAdapterAnnotationTest.java
deleted file mode 100644
index 0165434..0000000
--- a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/FactoryConfigurationAdapterAnnotationTest.java
+++ /dev/null
@@ -1,101 +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 java.io.IOException;
-import java.util.Hashtable;
-
-import junit.framework.Assert;
-
-import org.apache.felix.dm.DependencyManager;
-import org.apache.felix.dm.test.Base;
-import org.apache.felix.dm.test.BundleGenerator;
-import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
-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;
-import org.osgi.service.cm.ConfigurationAdmin;
-
-/**
- * Use case: Verify that an annotated Configuration Factory Adapter Service is properly created when a factory configuration
- * is created from Config Admin.
- */
-@RunWith(JUnit4TestRunner.class)
-public class FactoryConfigurationAdapterAnnotationTest 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.configadmin").version("1.2.8"),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager").versionAsInProject(),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager.runtime").versionAsInProject()),
- provision(
- new BundleGenerator()
- .set(Constants.BUNDLE_SYMBOLICNAME, "FactoryConfigurationAdapterTest")
- .set("Export-Package", "org.apache.felix.dm.test.bundle.annotation.sequencer")
- .set("Private-Package", "org.apache.felix.dm.test.bundle.annotation.factoryconfadapter")
- .set("Import-Package", "*")
- .set("-plugin", "org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin")
- .build()));
- }
-
- @Test
- public void testFactoryConfigurationAdapterAnnotation(BundleContext context) throws Throwable
- {
- DependencyManager m = new DependencyManager(context);
- // Provide the Sequencer to the adapter bundle service (see main/src/.../factoryconfadapter/*.java).
- m.add(m.createComponent().setImplementation(this).setInterface(Sequencer.class.getName(), null));
- ConfigurationAdmin cm = (ConfigurationAdmin) context.getService(context.getServiceReference(ConfigurationAdmin.class.getName()));
- try
- {
- // Create a factory configuration in order to instantiate the ServiceProvider
- org.osgi.service.cm.Configuration cf = cm.createFactoryConfiguration("FactoryPidTest", null);
- cf.update(new Hashtable() {{ put("foo2", "bar2"); }});
- // Wait for the ServiceProvider activation.
- m_ensure.waitForStep(2, 10000);
- // Update conf
- cf.update(new Hashtable() {{ put("foo2", "bar2_modified"); }});
- // Wait for effective update
- m_ensure.waitForStep(4, 10000);
- // Remove configuration.
- cf.delete();
- // Check if ServiceProvider has been stopped.
- m_ensure.waitForStep(6, 1000);
- m_ensure.ensure();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- Assert.fail("can't create factory configuration");
- }
- }
-}
diff --git a/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/FactoryConfigurationAdapterAnnotation.java b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/FactoryConfigurationAdapterAnnotation.java
new file mode 100644
index 0000000..6b12e5c
--- /dev/null
+++ b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/FactoryConfigurationAdapterAnnotation.java
@@ -0,0 +1,156 @@
+/*
+* 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.Map;
+
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.annotation.api.Component;
+import org.apache.felix.dm.annotation.api.FactoryConfigurationAdapterService;
+import org.apache.felix.dm.annotation.api.Inject;
+import org.apache.felix.dm.annotation.api.Property;
+import org.apache.felix.dm.annotation.api.Registered;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
+import org.apache.felix.dm.annotation.api.Start;
+import org.apache.felix.dm.annotation.api.Stop;
+import org.osgi.framework.BundleContext;
+
+public class FactoryConfigurationAdapterAnnotation {
+ public interface ServiceInterface {
+ public void doService();
+ }
+
+ @Component
+ public static class ServiceClient {
+ @ServiceDependency(changed = "changeServiceProvider")
+ void addServiceProvider(Map props, ServiceInterface si) {
+ // props should contain foo=bar, foo2=bar2
+ if (!"bar".equals(props.get("foo"))) {
+ throw new IllegalArgumentException("configuration does not contain foo=bar: " + props);
+ }
+ if (!"bar2".equals(props.get("foo2"))) {
+ throw new IllegalArgumentException("configuration does not contain foo2=bar2: " + props);
+ }
+ si.doService();
+ }
+
+ void changeServiceProvider(Map props, ServiceInterface si) {
+ // props should contain foo=bar, foo2=bar2_modified
+ if (!"bar".equals(props.get("foo"))) {
+ throw new IllegalArgumentException("configuration does not contain foo=bar: " + props);
+ }
+ if (!"bar2_modified".equals(props.get("foo2"))) {
+ throw new IllegalArgumentException("configuration does not contain foo2=bar2: " + props);
+ }
+ si.doService();
+ }
+ }
+
+ /**
+ * This service is instantiated when a factory configuration is created from ConfigAdmin
+ */
+ @FactoryConfigurationAdapterService(factoryPid = "FactoryPidTest", properties = {@Property(name = "foo", value = "bar")}, propagate = true)
+ public static class ServiceProvider implements ServiceInterface {
+ @ServiceDependency(filter="(name=test.FactoryConfigurationAdapterAnnotationTest)")
+ private volatile Ensure m_sequencer;
+
+ private volatile boolean m_started;
+
+ // Check auto config injections
+ @Inject
+ volatile BundleContext m_bc;
+ BundleContext m_bcNotInjected;
+
+ @Inject
+ volatile DependencyManager m_dm;
+ DependencyManager m_dmNotInjected;
+
+ @Inject
+ volatile org.apache.felix.dm.Component m_component;
+ org.apache.felix.dm.Component m_componentNotInjected;
+
+ // Either initial config, or an updated config
+ protected void updated(Dictionary conf) {
+ if (m_started) {
+ // conf should contain foo2=bar2_modified
+ if (!"bar2_modified".equals(conf.get("foo2"))) {
+ m_sequencer.throwable(new Exception("configuration does not contain foo=bar"));
+ }
+ m_sequencer.step(4);
+ } else {
+ // conf should contain foo2=bar2
+ if (!"bar2".equals(conf.get("foo2"))) {
+ throw new IllegalArgumentException("configuration does not contain foo2=bar2: " + conf);
+ }
+ }
+ }
+
+ @Start
+ void start() {
+ checkInjectedFields();
+ m_started = true;
+ m_sequencer.step(1);
+ }
+
+ @Registered
+ void registered() {
+ m_sequencer.step(3);
+ }
+
+ // The ServiceClient is invoking our service
+ public void doService() {
+ m_sequencer.step(); /* 2 or 5 */
+ }
+
+ @Stop
+ void stop() {
+ m_sequencer.step(6);
+ }
+
+ private void checkInjectedFields() {
+ if (m_bc == null) {
+ m_sequencer.throwable(new Exception("Bundle Context not injected"));
+ return;
+ }
+ if (m_bcNotInjected != null) {
+ m_sequencer.throwable(new Exception("Bundle Context must not be injected"));
+ return;
+ }
+
+ if (m_dm == null) {
+ m_sequencer.throwable(new Exception("DependencyManager not injected"));
+ return;
+ }
+ if (m_dmNotInjected != null) {
+ m_sequencer.throwable(new Exception("DependencyManager must not be injected"));
+ return;
+ }
+
+ if (m_component == null) {
+ m_sequencer.throwable(new Exception("Component not injected"));
+ return;
+ }
+ if (m_componentNotInjected != null) {
+ m_sequencer.throwable(new Exception("Component must not be injected"));
+ return;
+ }
+ }
+ }
+}
diff --git a/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/FactoryConfigurationAdapterAnnotationTest.java b/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/FactoryConfigurationAdapterAnnotationTest.java
new file mode 100644
index 0000000..312b17b
--- /dev/null
+++ b/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/FactoryConfigurationAdapterAnnotationTest.java
@@ -0,0 +1,75 @@
+/*
+* 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 java.io.IOException;
+import java.util.Hashtable;
+
+import junit.framework.Assert;
+
+import org.apache.felix.dependencymanager.test2.components.Ensure;
+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;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/**
+ * Use case: Verify that an annotated Configuration Factory Adapter Service is properly created when a factory configuration
+ * is created from Config Admin.
+ */
+@RunWith(PaxExam.class)
+public class FactoryConfigurationAdapterAnnotationTest extends TestBase {
+ @Test
+ public void testFactoryConfigurationAdapterAnnotation() throws Throwable {
+ Ensure e = new Ensure();
+ ServiceRegistration sr = register(e, "test.FactoryConfigurationAdapterAnnotationTest");
+ ConfigurationAdmin cm = (ConfigurationAdmin) context.getService(context
+ .getServiceReference(ConfigurationAdmin.class.getName()));
+ try {
+ // Create a factory configuration in order to instantiate the ServiceProvider
+ org.osgi.service.cm.Configuration cf = cm.createFactoryConfiguration("FactoryPidTest", null);
+ cf.update(new Hashtable() {
+ {
+ put("foo2", "bar2");
+ }
+ });
+ // Wait for the ServiceProvider activation.
+ e.waitForStep(2, 10000);
+ // Update conf
+ cf.update(new Hashtable() {
+ {
+ put("foo2", "bar2_modified");
+ }
+ });
+ // Wait for effective update
+ e.waitForStep(4, 10000);
+ // Remove configuration.
+ cf.delete();
+ // Check if ServiceProvider has been stopped.
+ e.waitForStep(6, 1000);
+ e.ensure();
+ sr.unregister();
+ } catch (IOException err) {
+ err.printStackTrace();
+ Assert.fail("can't create factory configuration");
+ }
+ }
+}