pax-exam 3.0.0 migration ...


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1531754 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/felix4050/A.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/felix4050/A.java
deleted file mode 100644
index 5880268..0000000
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/felix4050/A.java
+++ /dev/null
@@ -1,26 +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.felix4050;
-
-import org.apache.felix.dm.annotation.api.Component;
-
-@Component(provides = { A.class })
-public class A {
-
-}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/felix4050/B.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/felix4050/B.java
deleted file mode 100644
index 5b68a96..0000000
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/felix4050/B.java
+++ /dev/null
@@ -1,23 +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.felix4050;
-
-public interface B {
-    void run();
-}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/felix4050/B1.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/felix4050/B1.java
deleted file mode 100644
index 38f420c..0000000
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/felix4050/B1.java
+++ /dev/null
@@ -1,28 +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.felix4050;
-
-import org.apache.felix.dm.annotation.api.Component;
-import org.apache.felix.dm.annotation.api.Property;
-
-@Component(properties = { @Property(name = "type", value = "b1") })
-public class B1 implements B {
-    public void run() {
-    }
-}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/felix4050/B2.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/felix4050/B2.java
deleted file mode 100644
index b36c821..0000000
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/felix4050/B2.java
+++ /dev/null
@@ -1,66 +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.felix4050;
-
-import java.util.Hashtable;
-
-import org.apache.felix.dm.annotation.api.Component;
-import org.apache.felix.dm.annotation.api.Inject;
-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.ServiceRegistration;
-
-@Component(provides = {})
-public class B2 implements B {
-    @Inject
-    BundleContext _ctx;
-    
-    @ServiceDependency
-    Sequencer m_sequencer;
-
-    @Start
-    void start() {
-        Thread t = new Thread(new Runnable() {
-            public void run() {
-                try {
-                    Thread.sleep(2000);
-                } catch (InterruptedException e) {
-                }
-                System.out.println("Registering B2");
-                ServiceRegistration sr = _ctx.registerService(B.class.getName(), B2.this, new Hashtable() {
-                    {
-                        put("type", "b2");
-                    }
-                });
-
-                try {
-                    Thread.sleep(1000);
-                } catch (InterruptedException e) {
-                }
-            }
-        });
-        t.start();
-    }
-    
-    public void run() {
-        m_sequencer.step(3);
-    }
-}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/felix4050/S.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/felix4050/S.java
deleted file mode 100644
index 2cec3f9..0000000
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/felix4050/S.java
+++ /dev/null
@@ -1,95 +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.felix4050;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.felix.dm.annotation.api.Component;
-import org.apache.felix.dm.annotation.api.Destroy;
-import org.apache.felix.dm.annotation.api.Init;
-import org.apache.felix.dm.annotation.api.Inject;
-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;
-
-@Component
-public class S {
-    @ServiceDependency
-    volatile Sequencer m_sequencer;
-
-    @Inject
-    volatile org.apache.felix.dm.Component _component;
-
-    volatile A m_a;
-    volatile B m_b;
-
-    void bind(A a) {
-        System.out.println("bind(A): " + a);
-        m_a = a;
-    }
-
-    @ServiceDependency(name = "B")
-    void bind(B b) {
-        System.out.println("bind(B): " + b);
-        m_b = b;
-    }
-
-    @Init
-    Map init() {
-        m_sequencer.step(1);
-
-        List l = new ArrayList();
-        l.add(_component.getDependencyManager().createServiceDependency().setService(A.class)
-                .setRequired(true).setCallbacks("bind", null).setInstanceBound(true));
-        _component.add(l);
-
-        return new HashMap() {
-            {
-                put("B.required", "true");
-                put("B.filter", "(type=b2)");
-            }
-        };
-    }
-
-    @Start
-    void start() {
-        if (m_a == null) {
-            throw new RuntimeException("A not injected");
-        }
-        if (m_b == null) {
-            throw new RuntimeException("B not injected");
-        }
-        m_sequencer.step(2);
-        m_b.run(); // step(3)
-    }
-
-    @Stop
-    void stop() {
-        m_sequencer.step(4);
-    }
-
-    @Destroy
-    void destroy() {
-        m_sequencer.step(5);
-    }
-}
diff --git a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/Felix4050Test.java b/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/Felix4050Test.java
deleted file mode 100644
index 28d9fcf..0000000
--- a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/Felix4050Test.java
+++ /dev/null
@@ -1,80 +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.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;
-
-/**
- * Test for FELIX-4050 issue: It validates that component state calculation does not mess up
- * when an @Init method adds an available dependency using the API, and also returns a Map for
- * configuring a named dependency.
- */
-@RunWith(JUnit4TestRunner.class)
-public class Felix4050Test 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, "AspectLifecycleTest")
-                    .set("Export-Package", "org.apache.felix.dm.test.bundle.annotation.sequencer")
-                    .set("Private-Package", "org.apache.felix.dm.test.bundle.annotation.felix4050")
-                    .set("Import-Package", "*")
-                    .set("-plugin", "org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin")
-                    .build()));         
-    }
-
-    @Test
-    public void testFelix4050(BundleContext context)
-    {
-        DependencyManager m = new DependencyManager(context);
-        // provide a sequencer to the test classes
-        Component seq = m.createComponent().setImplementation(this).setInterface(Sequencer.class.getName(), null);
-        m.add(seq);
-        // wait for S to be started
-        m_ensure.waitForStep(3, 10000);
-        // remove our sequencer: this will stop S
-        m.remove(seq);
-        // ensure that S is stopped and destroyed
-        m_ensure.waitForStep(5, 10000);
-    }
-}
diff --git a/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/Felix4050.java b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/Felix4050.java
new file mode 100644
index 0000000..ba41a0d
--- /dev/null
+++ b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/Felix4050.java
@@ -0,0 +1,152 @@
+/*
+* 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.ArrayList;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.felix.dm.annotation.api.Component;
+import org.apache.felix.dm.annotation.api.Destroy;
+import org.apache.felix.dm.annotation.api.Init;
+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;
+import org.osgi.framework.ServiceRegistration;
+
+public class Felix4050 {
+    @Component(provides = {A.class})
+    public static class A {
+
+    }
+
+    public interface B {
+        void run();
+    }
+
+    @Component(properties = {@Property(name = "type", value = "b1")})
+    public static class B1 implements B {
+        public void run() {
+        }
+    }
+
+    @Component(provides = {})
+    public static class B2 implements B {
+        @Inject
+        volatile BundleContext _ctx;
+
+        @ServiceDependency(filter = "(name=test.Felix4050)")
+        volatile Ensure m_sequencer;
+
+        @Start
+        void start() {
+            Thread t = new Thread(new Runnable() {
+                public void run() {
+                    try {
+                        Thread.sleep(2000);
+                    } catch (InterruptedException e) {
+                    }
+                    System.out.println("Registering B2");
+                    ServiceRegistration sr = _ctx.registerService(B.class.getName(), B2.this, new Hashtable() {
+                        {
+                            put("type", "b2");
+                        }
+                    });
+
+                    try {
+                        Thread.sleep(1000);
+                    } catch (InterruptedException e) {
+                    }
+                }
+            });
+            t.start();
+        }
+
+        public void run() {
+            m_sequencer.step(3);
+        }
+    }
+
+    @Component
+    public static class S {
+        @ServiceDependency(filter = "(name=test.Felix4050)")
+        volatile Ensure m_sequencer;
+
+        @Inject
+        volatile org.apache.felix.dm.Component _component;
+
+        volatile A m_a;
+        volatile B m_b;
+
+        void bind(A a) {
+            System.out.println("bind(A): " + a);
+            m_a = a;
+        }
+
+        @ServiceDependency(name = "B")
+        void bind(B b) {
+            System.out.println("bind(B): " + b);
+            m_b = b;
+        }
+
+        @Init
+        Map init() {
+            m_sequencer.step(1);
+
+            List l = new ArrayList();
+            l.add(_component.getDependencyManager().createServiceDependency().setService(A.class).setRequired(true)
+                    .setCallbacks("bind", null).setInstanceBound(true));
+            _component.add(l);
+
+            return new HashMap() {
+                {
+                    put("B.required", "true");
+                    put("B.filter", "(type=b2)");
+                }
+            };
+        }
+
+        @Start
+        void start() {
+            if (m_a == null) {
+                throw new RuntimeException("A not injected");
+            }
+            if (m_b == null) {
+                throw new RuntimeException("B not injected");
+            }
+            m_sequencer.step(2);
+            m_b.run(); // step(3)
+        }
+
+        @Stop
+        void stop() {
+            m_sequencer.step(4);
+        }
+
+        @Destroy
+        void destroy() {
+            m_sequencer.step(5);
+        }
+    }
+}
diff --git a/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/Felix4050Test.java b/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/Felix4050Test.java
new file mode 100644
index 0000000..9db9566
--- /dev/null
+++ b/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/Felix4050Test.java
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+/**
+ * Test for FELIX-4050 issue: It validates that component state calculation does not mess up
+ * when an @Init method adds an available dependency using the API, and also returns a Map for
+ * configuring a named dependency.
+ */
+@RunWith(PaxExam.class)
+public class Felix4050Test extends TestBase {
+    @Test
+    public void testFelix4050() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, "test.Felix4050");
+        // wait for S to be started
+        e.waitForStep(3, 10000);
+        // remove our sequencer: this will stop S
+        sr.unregister();
+        // ensure that S is stopped and destroyed
+        e.waitForStep(5, 10000);
+    }
+}