pax exam 3.0.0 migration ...
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1531687 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
deleted file mode 100644
index cbddf0a..0000000
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/adapter/AdapterTest.java
+++ /dev/null
@@ -1,225 +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.adapter;
-
-import java.util.Hashtable;
-import java.util.Map;
-
-import org.apache.felix.dm.DependencyManager;
-import org.apache.felix.dm.annotation.api.AdapterService;
-import org.apache.felix.dm.annotation.api.Component;
-import org.apache.felix.dm.annotation.api.Inject;
-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.annotation.api.Stop;
-import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-
-public class AdapterTest
-{
- public interface S1
- {
- public void run();
- }
-
- public interface S2
- {
- public void run2();
- }
-
- public interface S3
- {
- public void run3();
- }
-
- @Component
- public static class S3Consumer
- {
- @ServiceDependency
- Sequencer m_sequencer;
- private Map<String, String> m_serviceProperties;
- private volatile S3 m_s3;
-
- @ServiceDependency
- void bind(Map<String, String> serviceProperties, S3 s3)
- {
- m_serviceProperties = serviceProperties;
- m_s3 = s3;
- }
-
- @Start
- void start() {
- // The adapter service must inherit from adaptee service properties ...
- if ("value1".equals(m_serviceProperties.get("param1")) // adaptee properties
- && "true".equals(m_serviceProperties.get("adapter"))) // adapter properties
- {
- m_s3.run3();
- }
- }
- }
-
- @AdapterService(adapteeService = S1.class,
- properties={@Property(name="adapter", value="true")})
- public static class S1ToS3AdapterAutoConfig implements S3
- {
- // This is the adapted service
- protected S1 m_s1;
-
- @ServiceDependency(filter="(name=AdapterAutoConfig)")
- protected Sequencer m_sequencer;
-
- // 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;
-
- public void run3()
- {
- checkInjectedFields();
- m_s1.run();
- m_sequencer.step(3);
- }
-
- 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;
- }
- }
- }
-
- @AdapterService(adapteeService = S1.class,
- properties={@Property(name="adapter", value="true")},
- field="m_s1")
- public static class S1ToS3AdapterAutoConfigField implements S3
- {
- // This is the adapted service
- protected S1 m_s1;
-
- @ServiceDependency(filter="(name=AdapterAutoConfigField)")
- protected Sequencer m_sequencer;
-
- public void run3()
- {
- m_s1.run();
- m_sequencer.step(3);
- }
- }
-
- @AdapterService(adapteeService = S1.class,
- properties={@Property(name="adapter", value="true")},
- added="bind",
- removed="removed")
- public static class S1ToS3AdapterCallback implements S3
- {
- // This is the adapted service
- protected Object m_s1;
-
- @ServiceDependency(filter="(name=AdapterCallback)")
- protected Sequencer m_sequencer;
-
- void bind(S1 s1)
- {
- m_s1 = s1;
- }
-
- public void run3()
- {
- ((S1) m_s1).run();
- }
-
- @Stop
- void stop()
- {
- m_sequencer.step(3);
- }
-
- void removed(S1 s1)
- {
- m_sequencer.step(4);
- }
- }
-
- @Component(properties = { @Property(name = "param1", value = "value1") })
- public static class S1Impl implements S1
- {
- @ServiceDependency
- protected Sequencer m_sequencer;
-
- @ServiceDependency
- protected S2 m_s2;
-
- public void run()
- {
- m_sequencer.step(1);
- m_s2.run2();
- }
- }
-
- @Component
- public static class S2Impl implements S2
- {
- @ServiceDependency
- protected Sequencer m_sequencer;
-
- public void run2()
- {
- m_sequencer.step(2);
- }
- }
-}
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
deleted file mode 100644
index c0cdadb..0000000
--- a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AdapterAnnotationTest.java
+++ /dev/null
@@ -1,102 +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.Component;
-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 Aspect Annotations usage.
- */
-@RunWith(JUnit4TestRunner.class)
-public class AdapterAnnotationTest 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.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()));
- }
-
- /**
- * Check if an adapter gets injected with its adaptee using default auto config mode.
- */
- @Test
- public void testAnnotatedAdapterAutoConfig(BundleContext context)
- {
- DependencyManager m = new DependencyManager(context);
- // Provide the Sequencer to the org.apache.felix.dm.test.bundle.annotation.adapter.AdapterTest bundle
- m.add(makeSequencer(m, "AdapterAutoConfig"));
- m_ensure.waitForStep(3, 10000);
- }
-
- /**
- * Check if an adapter gets injected with its adaptee in a named class field.
- */
- @Test
- public void testAnnotatedAdapterAutoConfigField(BundleContext context) throws Throwable
- {
- DependencyManager m = new DependencyManager(context);
- // Provide the Sequencer to the org.apache.felix.dm.test.bundle.annotation.adapter.AdapterTest bundle
- m.add(makeSequencer(m, "AdapterAutoConfigField"));
- m_ensure.waitForStep(3, 10000);
- m_ensure.ensure();
- }
-
- /**
- * Check if an adapter gets injected with its adaptee in a callback method.
- */
- @Test
- public void testAnnotatedAdapterCallback(BundleContext context)
- {
- DependencyManager m = new DependencyManager(context);
- // Provide the Sequencer to the org.apache.felix.dm.test.bundle.annotation.adapter.AdapterTest bundle
- Component sequencer = makeSequencer(m, "AdapterCallback");
- m.add(sequencer);
- m_ensure.waitForStep(2, 10000);
- m.remove(sequencer);
- m_ensure.waitForStep(4, 10000);
- }
-}
diff --git a/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/AdapterAnnotation.java b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/AdapterAnnotation.java
new file mode 100644
index 0000000..c87aa28
--- /dev/null
+++ b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/AdapterAnnotation.java
@@ -0,0 +1,188 @@
+/*
+ * 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.Map;
+
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.annotation.api.AdapterService;
+import org.apache.felix.dm.annotation.api.Component;
+import org.apache.felix.dm.annotation.api.Inject;
+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.annotation.api.Stop;
+import org.osgi.framework.BundleContext;
+
+public class AdapterAnnotation {
+ public interface S1 {
+ public void run();
+ }
+
+ public interface S2 {
+ public void run2();
+ }
+
+ public interface S3 {
+ public void run3();
+ }
+
+ @Component
+ public static class S3Consumer {
+ private volatile Map<String, String> m_serviceProperties;
+ private volatile S3 m_s3;
+
+ @ServiceDependency
+ void bind(Map<String, String> serviceProperties, S3 s3) {
+ m_serviceProperties = serviceProperties;
+ m_s3 = s3;
+ }
+
+ @Start
+ void start() {
+ // The adapter service must inherit from adaptee service properties ...
+ if ("value1".equals(m_serviceProperties.get("param1")) // adaptee properties
+ && "true".equals(m_serviceProperties.get("adapter"))) // adapter properties
+ {
+ m_s3.run3();
+ }
+ }
+ }
+
+ @AdapterService(adapteeService = S1.class, properties = {@Property(name = "adapter", value = "true")})
+ public static class S1ToS3AdapterAutoConfig implements S3 {
+ // This is the adapted service
+ protected volatile S1 m_s1;
+
+ @ServiceDependency(filter = "(name=adapter.autoConfig)")
+ protected volatile Ensure m_sequencer;
+
+ // 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;
+
+ public void run3() {
+ checkInjectedFields();
+ m_s1.run();
+ m_sequencer.step(3);
+ }
+
+ 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;
+ }
+ }
+ }
+
+ @AdapterService(adapteeService = S1.class, properties = {@Property(name = "adapter", value = "true")}, field = "m_s1")
+ public static class S1ToS3AdapterAutoConfigField implements S3 {
+ // This is the adapted service
+ protected volatile S1 m_s1;
+
+ @ServiceDependency(filter = "(name=adapter.autoConfig.field)")
+ protected volatile Ensure m_sequencer;
+
+ public void run3() {
+ m_s1.run();
+ m_sequencer.step(3);
+ }
+ }
+
+ @AdapterService(adapteeService = S1.class, properties = {@Property(name = "adapter", value = "true")}, added = "bind", removed = "removed")
+ public static class S1ToS3AdapterCallback implements S3 {
+ // This is the adapted service
+ protected Object m_s1;
+
+ @ServiceDependency(filter = "(name=adapter.callback)")
+ protected Ensure m_sequencer;
+
+ void bind(S1 s1) {
+ m_s1 = s1;
+ }
+
+ public void run3() {
+ ((S1) m_s1).run();
+ }
+
+ @Stop
+ void stop() {
+ m_sequencer.step(3);
+ }
+
+ void removed(S1 s1) {
+ m_sequencer.step(4);
+ }
+ }
+
+ @Component(properties = {@Property(name = "param1", value = "value1")})
+ public static class S1Impl implements S1 {
+ @ServiceDependency
+ protected Ensure m_sequencer;
+
+ @ServiceDependency
+ protected S2 m_s2;
+
+ public void run() {
+ m_sequencer.step(1);
+ m_s2.run2();
+ }
+ }
+
+ @Component
+ public static class S2Impl implements S2 {
+ @ServiceDependency
+ protected Ensure m_sequencer;
+
+ public void run2() {
+ m_sequencer.step(2);
+ }
+ }
+}
diff --git a/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/SimpleAnnotations.java b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/SimpleAnnotations.java
index e1e2db9..68c2bff 100644
--- a/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/SimpleAnnotations.java
+++ b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/SimpleAnnotations.java
@@ -29,7 +29,6 @@
import org.apache.felix.dm.annotation.api.Start;
import org.apache.felix.dm.annotation.api.Stop;
import org.apache.felix.dm.annotation.api.Unregistered;
-import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.log.LogService;
diff --git a/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/AdapterAnnotationTest.java b/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/AdapterAnnotationTest.java
new file mode 100644
index 0000000..6322b57
--- /dev/null
+++ b/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/AdapterAnnotationTest.java
@@ -0,0 +1,69 @@
+/*
+* 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.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;
+
+/**
+ * Use case: Verify Aspect Annotations usage.
+ */
+@RunWith(PaxExam.class)
+public class AdapterAnnotationTest extends TestBase {
+ /**
+ * Check if an adapter gets injected with its adaptee using default auto config mode.
+ * @throws Throwable
+ */
+ @Test
+ public void testAnnotatedAdapterAutoConfig() throws Throwable {
+ Ensure e = new Ensure();
+ ServiceRegistration er = register(e, "adapter.autoConfig");
+ e.waitForStep(3, 10000);
+ e.ensure();
+ er.unregister();
+ }
+
+ /**
+ * Check if an adapter gets injected with its adaptee in a named class field.
+ */
+ @Test
+ public void testAnnotatedAdapterAutoConfigField() throws Throwable {
+ Ensure e = new Ensure();
+ ServiceRegistration er = register(e, "adapter.autoConfig.field");
+ e.waitForStep(3, 10000);
+ e.ensure();
+ er.unregister();
+ }
+
+ /**
+ * Check if an adapter gets injected with its adaptee in a callback method.
+ */
+ @Test
+ public void testAnnotatedAdapterCallback() {
+ Ensure e = new Ensure();
+ ServiceRegistration er = register(e, "adapter.callback");
+ e.waitForStep(2, 10000);
+ er.unregister();
+ e.waitForStep(4, 10000);
+ }
+}