pax-exam 3.0.0 migration ...


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1531738 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycle/AspectLifecycleTest.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycle/AspectLifecycleTest.java
deleted file mode 100644
index b2f9e27..0000000
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycle/AspectLifecycleTest.java
+++ /dev/null
@@ -1,36 +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.aspectlifecycle;
-
-import org.apache.felix.dm.annotation.api.Component;
-import org.apache.felix.dm.annotation.api.ServiceDependency;
-
-/**
- * Tests an aspect service, and ensure that its lifecycle methods are properly invoked (init/start/stop/destroy)
- */
-@Component
-public class AspectLifecycleTest
-{
-    @ServiceDependency
-    void bind(ServiceInterface service)
-    {
-        service.run();
-    }
-
-}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycle/ServiceInterface.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycle/ServiceInterface.java
deleted file mode 100644
index dbf5c53..0000000
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycle/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.aspectlifecycle;
-
-public interface ServiceInterface
-{
-    public void run();
-}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycle/ServiceProvider.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycle/ServiceProvider.java
deleted file mode 100644
index 2841324..0000000
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycle/ServiceProvider.java
+++ /dev/null
@@ -1,35 +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.aspectlifecycle;
-
-import org.apache.felix.dm.annotation.api.Component;
-import org.apache.felix.dm.annotation.api.ServiceDependency;
-import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
-
-@Component
-public class ServiceProvider implements ServiceInterface
-{
-    @ServiceDependency(filter = "(test=aspectLifecycle.ServiceProvider)")
-    protected Sequencer m_sequencer;
-
-    public void run()
-    {
-        m_sequencer.step();
-    }
-}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycle/ServiceProviderAspect.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycle/ServiceProviderAspect.java
deleted file mode 100644
index 03ffb89..0000000
--- a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspectlifecycle/ServiceProviderAspect.java
+++ /dev/null
@@ -1,75 +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.aspectlifecycle;
-
-import org.apache.felix.dm.annotation.api.AspectService;
-import org.apache.felix.dm.annotation.api.Destroy;
-import org.apache.felix.dm.annotation.api.Init;
-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;
-
-@AspectService(ranking = 10)
-public class ServiceProviderAspect implements ServiceInterface
-{
-    protected boolean m_initCalled;
-    protected Sequencer m_sequencer;
-
-    @ServiceDependency(filter = "(test=aspectLifecycle.ServiceProviderAspect)")
-    protected void bind(Sequencer sequencer)
-    {
-        m_sequencer = sequencer;
-        m_sequencer.step(2);
-    }
-
-    @Init
-    void init()
-    {
-        m_initCalled = true;
-    }
-
-    @Start
-    void start()
-    {
-        if (!m_initCalled)
-        {
-            throw new IllegalStateException("start method called, but init method was not called");
-        }
-        m_sequencer.step(3);
-    }
-
-    public void run()
-    {
-        m_sequencer.step(4);
-    }
-
-    @Stop()
-    void stop()
-    {
-        // At this point, the AspectLifecycleTest class has been rebound to the original ServiceProvider.
-        m_sequencer.step(6);
-    }
-
-    @Destroy
-    void destroy()
-    {
-        m_sequencer.step(7);
-    }
-}
diff --git a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectLifecycleAnnotationTest.java b/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectLifecycleAnnotationTest.java
deleted file mode 100644
index 3c96a78..0000000
--- a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectLifecycleAnnotationTest.java
+++ /dev/null
@@ -1,88 +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.util.Dictionary;
-import java.util.Hashtable;
-
-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;
-
-/**
- * Use case: Tests an aspect service, and ensure that its lifecycle methods are properly invoked 
- * (init/start/stop/destroy methods).
- */
-@RunWith(JUnit4TestRunner.class)
-public class AspectLifecycleAnnotationTest 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.aspectlifecycle")
-                    .set("Import-Package", "*")
-                    .set("-plugin", "org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin")
-                    .build()));         
-    }
-
-    @Test
-    public void testAnnotatedAspect(BundleContext context)
-    {
-        DependencyManager m = new DependencyManager(context);
-        // Provide the Sequencer server to the ServiceProvider service
-        Dictionary props = new Hashtable() {{ put("test", "aspectLifecycle.ServiceProvider"); }};
-        m.add(m.createComponent().setImplementation(this).setInterface(Sequencer.class.getName(), props));
-        // Check if the ServiceProvider has been injected in the AspectTest service.
-        m_ensure.waitForStep(1, 10000);
-        // Provide the Sequencer server to the ServiceProviderAspect service
-        props = new Hashtable() {{ put("test", "aspectLifecycle.ServiceProviderAspect"); }};
-        Component seq = m.createComponent().setImplementation(this).setInterface(Sequencer.class.getName(), props);
-        m.add(seq);
-        // Check if the AspectTest has been injected with the aspect
-        m_ensure.waitForStep(3, 10000);
-        // Stop the ServiceProviderAspect service.
-        m.remove(seq);
-        // And check if the aspect has been called in its stop/destroy methods.
-        m_ensure.waitForStep(7, 10000);
-    }
-}
diff --git a/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/AspectLifecycleAnnotation.java b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/AspectLifecycleAnnotation.java
new file mode 100644
index 0000000..ec591d4
--- /dev/null
+++ b/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/AspectLifecycleAnnotation.java
@@ -0,0 +1,94 @@
+/*
+ * 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 org.apache.felix.dm.annotation.api.AspectService;
+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.ServiceDependency;
+import org.apache.felix.dm.annotation.api.Start;
+import org.apache.felix.dm.annotation.api.Stop;
+
+public class AspectLifecycleAnnotation {
+    public interface ServiceInterface {
+        public void run();
+    }
+
+    /**
+     * Tests an aspect service, and ensure that its lifecycle methods are properly invoked (init/start/stop/destroy)
+     */
+    @Component
+    public static class AspectLifecycleTest {
+        @ServiceDependency
+        void bind(ServiceInterface service) {
+            service.run();
+        }
+    }
+
+    @Component
+    public static class ServiceProvider implements ServiceInterface {
+        @ServiceDependency(filter = "(name=aspectLifecycle.ServiceProvider)")
+        protected volatile Ensure m_sequencer;
+
+        public void run() {
+            m_sequencer.step();
+        }
+    }
+
+    @AspectService(ranking = 10)
+    public static class ServiceProviderAspect implements ServiceInterface {
+        protected volatile boolean m_initCalled;
+        protected volatile Ensure m_sequencer;
+
+        @ServiceDependency(filter = "(name=aspectLifecycle.ServiceProviderAspect)")
+        protected void bind(Ensure sequencer) {
+            m_sequencer = sequencer;
+            m_sequencer.step(2);
+        }
+
+        @Init
+        void init() {
+            m_initCalled = true;
+        }
+
+        @Start
+        void start() {
+            if (!m_initCalled) {
+                throw new IllegalStateException("start method called, but init method was not called");
+            }
+            m_sequencer.step(3);
+        }
+
+        public void run() {
+            m_sequencer.step(4);
+        }
+
+        @Stop()
+        void stop() {
+            // At this point, the AspectLifecycleTest class has been rebound to the original ServiceProvider.
+            m_sequencer.step(6);
+        }
+
+        @Destroy
+        void destroy() {
+            m_sequencer.step(7);
+        }
+    }
+}
diff --git a/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/AspectLifecycleAnnotationTest.java b/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/AspectLifecycleAnnotationTest.java
new file mode 100644
index 0000000..a2a89c1
--- /dev/null
+++ b/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/AspectLifecycleAnnotationTest.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.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: Tests an aspect service, and ensure that its lifecycle methods are properly invoked 
+ * (init/start/stop/destroy methods).
+ */
+@RunWith(PaxExam.class)
+public class AspectLifecycleAnnotationTest extends TestBase {
+    @Test
+    public void testAnnotatedAspect() {
+        Ensure e = new Ensure();
+        // Provide the Sequencer server to the ServiceProvider service
+        ServiceRegistration sr1 = register(e, "aspectLifecycle.ServiceProvider");                
+        // Check if the ServiceProvider has been injected in the AspectTest service.
+        e.waitForStep(1, 10000);
+        // Provide the Sequencer server to the ServiceProviderAspect service
+        ServiceRegistration sr2 = register(e, "aspectLifecycle.ServiceProviderAspect");        
+        // Check if the AspectTest has been injected with the aspect
+        e.waitForStep(3, 10000);
+        // Stop the ServiceProviderAspect service.
+        sr2.unregister();
+        // And check if the aspect has been called in its stop/destroy methods.
+        e.waitForStep(7, 10000);
+        sr1.unregister();
+    }
+}