added integration tests for annotated adapter services
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@912255 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/AdapterTest.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/AdapterTest.java
new file mode 100644
index 0000000..dca7eac
--- /dev/null
+++ b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/AdapterTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.adapter;
+
+import java.util.Map;
+
+import org.apache.felix.dm.annotation.api.Service;
+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;
+
+@Service
+public class AdapterTest
+{
+ @ServiceDependency
+ Sequencer m_sequencer;
+ private Map<String, String> m_serviceProperties;
+
+ @ServiceDependency
+ void bind(Map<String, String> serviceProperties, ServiceInterface3 service)
+ {
+ m_serviceProperties = serviceProperties;
+ service.run3();
+ }
+
+ @Start
+ void start() {
+ // The adapter service must inherit from adaptee service properties ...
+ if ("value1".equals(m_serviceProperties.get("param1")) // adaptee properties
+ && "value2".equals(m_serviceProperties.get("param2"))) // adapter properties
+ {
+ m_sequencer.step(4);
+ }
+ }
+}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/ServiceInterface.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/ServiceInterface.java
new file mode 100644
index 0000000..04eb958
--- /dev/null
+++ b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/ServiceInterface.java
@@ -0,0 +1,24 @@
+/*
+ * 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.adapter;
+
+public interface ServiceInterface
+{
+ public void run();
+}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/ServiceInterface2.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/ServiceInterface2.java
new file mode 100644
index 0000000..23d9bdb
--- /dev/null
+++ b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/ServiceInterface2.java
@@ -0,0 +1,6 @@
+package org.apache.felix.dm.test.bundle.annotation.adapter;
+
+public interface ServiceInterface2
+{
+ public void run2();
+}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/ServiceInterface3.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/ServiceInterface3.java
new file mode 100644
index 0000000..ff79c87
--- /dev/null
+++ b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/ServiceInterface3.java
@@ -0,0 +1,6 @@
+package org.apache.felix.dm.test.bundle.annotation.adapter;
+
+public interface ServiceInterface3
+{
+ public void run3();
+}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/ServiceProvider.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/ServiceProvider.java
new file mode 100644
index 0000000..31c72d0
--- /dev/null
+++ b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/ServiceProvider.java
@@ -0,0 +1,40 @@
+/*
+ * 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.adapter;
+
+import org.apache.felix.dm.annotation.api.Param;
+import org.apache.felix.dm.annotation.api.Service;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
+import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
+
+@Service(properties = { @Param(name = "param1", value = "value1") })
+public class ServiceProvider implements ServiceInterface
+{
+ @ServiceDependency
+ protected Sequencer m_sequencer;
+
+ @ServiceDependency
+ protected ServiceInterface2 m_serviceInterface2;
+
+ public void run()
+ {
+ m_sequencer.step(1);
+ m_serviceInterface2.run2();
+ }
+}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/ServiceProvider2.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/ServiceProvider2.java
new file mode 100644
index 0000000..8d69eb5
--- /dev/null
+++ b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/ServiceProvider2.java
@@ -0,0 +1,35 @@
+/*
+ * 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.adapter;
+
+import org.apache.felix.dm.annotation.api.Service;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
+import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
+
+@Service
+public class ServiceProvider2 implements ServiceInterface2
+{
+ @ServiceDependency
+ protected Sequencer m_sequencer;
+
+ public void run2()
+ {
+ m_sequencer.step(2);
+ }
+}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/ServiceProviderAdapter.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/ServiceProviderAdapter.java
new file mode 100644
index 0000000..3bca23f
--- /dev/null
+++ b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/ServiceProviderAdapter.java
@@ -0,0 +1,40 @@
+/*
+ * 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.adapter;
+
+import org.apache.felix.dm.annotation.api.AdapterService;
+import org.apache.felix.dm.annotation.api.Param;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
+import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
+
+@AdapterService(adapteeService = ServiceInterface.class, adapterProperties={@Param(name="param2", value="value2")})
+public class ServiceProviderAdapter implements ServiceInterface3
+{
+ // This is the adapted service
+ protected ServiceInterface m_adaptee;
+
+ @ServiceDependency
+ protected Sequencer m_sequencer;
+
+ public void run3()
+ {
+ m_adaptee.run();
+ m_sequencer.step(3);
+ }
+}
diff --git a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AdapterAnnotationTest.java b/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AdapterAnnotationTest.java
new file mode 100644
index 0000000..894dd00
--- /dev/null
+++ b/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AdapterAnnotationTest.java
@@ -0,0 +1,71 @@
+/*
+* 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 java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.felix.dm.DependencyManager;
+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;
+
+/**
+ * Use case: Verify Aspect Annotations usage.
+ */
+@RunWith(JUnit4TestRunner.class)
+public class AdapterAnnotationTest extends AnnotationBase
+{
+ @Configuration
+ public static Option[] configuration()
+ {
+ return options(
+ provision(
+ mavenBundle().groupId("org.osgi").artifactId("org.osgi.compendium").version("4.1.0"),
+ 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, "AdapterTest")
+ .set("Export-Package", "org.apache.felix.dm.test.bundle.annotation.sequencer")
+ .set("Private-Package", "org.apache.felix.dm.test.bundle.annotation.adapter")
+ .set("Import-Package", "*")
+ .set("-plugin", "org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin")
+ .build()));
+ }
+
+ @Test
+ public void testAnnotatedAdapter(BundleContext context)
+ {
+ DependencyManager m = new DependencyManager(context);
+ // Provide the Sequencer to the adapeter bundle service (see main/src/.../adapter/*.java).
+ m.add(m.createService().setImplementation(this).setInterface(Sequencer.class.getName(), null));
+ m_ensure.waitForStep(4, 10000);
+ }
+}