You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pd...@apache.org on 2013/10/13 21:27:54 UTC

svn commit: r1531736 - in /felix/trunk/dependencymanager: test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspect/ test/src/test/java/org/apache/felix/dm/test/annotation/ test2/src/main/java/org/apache/felix/dependencymanager/test2/compone...

Author: pderop
Date: Sun Oct 13 19:27:54 2013
New Revision: 1531736

URL: http://svn.apache.org/r1531736
Log:
pax-exam 3.0.0 migration ...

Added:
    felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/AspectAnnotation.java
      - copied, changed from r1531247, felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspect/AspectChainTest.java
    felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/AspectAnnotationTest.java
      - copied, changed from r1531247, felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectAnnotationTest.java
Removed:
    felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspect/AspectChainTest.java
    felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectAnnotationTest.java

Copied: felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/AspectAnnotation.java (from r1531247, felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspect/AspectChainTest.java)
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/AspectAnnotation.java?p2=felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/AspectAnnotation.java&p1=felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspect/AspectChainTest.java&r1=1531247&r2=1531736&rev=1531736&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/aspect/AspectChainTest.java (original)
+++ felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/AspectAnnotation.java Sun Oct 13 19:27:54 2013
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.felix.dm.test.bundle.annotation.aspect;
+package org.apache.felix.dependencymanager.test2.components;
 
 import org.apache.felix.dm.DependencyManager;
 import org.apache.felix.dm.annotation.api.AspectService;
@@ -26,122 +26,107 @@ import org.apache.felix.dm.annotation.ap
 import org.apache.felix.dm.annotation.api.Inject;
 import org.apache.felix.dm.annotation.api.ServiceDependency;
 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 AspectChainTest
-{
-    public interface ServiceInterface
-    {
+public class AspectAnnotation {
+    public interface ServiceInterface {
         public void invoke(Runnable run);
     }
 
     @Component
-    public static class ServiceProvider implements ServiceInterface
-    {
-        @ServiceDependency(filter="(name=AspectChainTest.ServiceProvider)")
-        protected Sequencer m_sequencer;
+    public static class ServiceProvider implements ServiceInterface {
+        @ServiceDependency(filter = "(name=AspectChainTest.ServiceProvider)")
+        protected volatile Ensure m_sequencer;
         // Injected by reflection.
-        protected ServiceRegistration m_sr;
-               
+        protected volatile ServiceRegistration m_sr;
+
         @Init
         void init() {
             System.out.println("ServiceProvider.init");
         }
-        
+
         @Destroy
         void destroy() {
             System.out.println("ServiceProvider.destroy");
         }
 
-        public void invoke(Runnable run)
-        {
+        public void invoke(Runnable run) {
             run.run();
             m_sequencer.step(6);
         }
     }
-    
+
     @AspectService(ranking = 20)
-    public static class ServiceAspect2 implements ServiceInterface
-    {
-        @ServiceDependency(filter="(name=AspectChainTest.ServiceAspect2)")
-        protected Sequencer m_sequencer;
+    public static class ServiceAspect2 implements ServiceInterface {
+        @ServiceDependency(filter = "(name=AspectChainTest.ServiceAspect2)")
+        protected volatile Ensure m_sequencer;
         // Injected by reflection.
         private volatile ServiceInterface m_parentService;
 
         // Check auto config injections
         @Inject
-        BundleContext m_bc;
+        volatile BundleContext  m_bc;
         BundleContext m_bcNotInjected;
-        
+
         @Inject
-        DependencyManager m_dm;
+        volatile DependencyManager  m_dm;
         DependencyManager m_dmNotInjected;
-        
+
         @Inject
-        org.apache.felix.dm.Component m_component;
+        volatile org.apache.felix.dm.Component  m_component;
         org.apache.felix.dm.Component m_componentNotInjected;
 
         @Init
         void init() {
             System.out.println("ServiceAspect2.init");
         }
-        
+
         @Destroy
         void destroy() {
             System.out.println("ServiceAspect2.destroy");
         }
-        
-        public void invoke(Runnable run)
-        {
+
+        public void invoke(Runnable run) {
             checkInjectedFields();
             m_sequencer.step(3);
             m_parentService.invoke(run);
         }
-        
-        private void checkInjectedFields()
-        {
-            if (m_bc == null)
-            {
+
+        private void checkInjectedFields() {
+            if (m_bc == null) {
                 m_sequencer.throwable(new Exception("Bundle Context not injected"));
                 return;
             }
-            if (m_bcNotInjected != null)
-            {
+            if (m_bcNotInjected != null) {
                 m_sequencer.throwable(new Exception("Bundle Context must not be injected"));
                 return;
             }
 
-            if (m_dm == null)
-            {
+            if (m_dm == null) {
                 m_sequencer.throwable(new Exception("DependencyManager not injected"));
                 return;
             }
-            if (m_dmNotInjected != null)
-            {
+            if (m_dmNotInjected != null) {
                 m_sequencer.throwable(new Exception("DependencyManager must not be injected"));
                 return;
             }
 
-            if (m_component == null)
-            {
+            if (m_component == null) {
                 m_sequencer.throwable(new Exception("Component not injected"));
                 return;
             }
-            if (m_componentNotInjected != null)
-            {
+            if (m_componentNotInjected != null) {
                 m_sequencer.throwable(new Exception("Component must not be injected"));
                 return;
             }
         }
     }
 
-    @AspectService(ranking = 30, added="add")
-    public static class ServiceAspect3 implements ServiceInterface
-    {
-        @ServiceDependency(filter="(name=AspectChainTest.ServiceAspect3)")
-        protected Sequencer m_sequencer;
+    @AspectService(ranking = 30, added = "add")
+    public static class ServiceAspect3 implements ServiceInterface {
+        @ServiceDependency(filter = "(name=AspectChainTest.ServiceAspect3)")
+        protected volatile Ensure m_sequencer;
         // Injected using add callback.
         private volatile ServiceInterface m_parentService;
 
@@ -149,29 +134,26 @@ public class AspectChainTest
         void init() {
             System.out.println("ServiceAspect3.init");
         }
-        
+
         @Destroy
         void destroy() {
             System.out.println("ServiceAspect3.destroy");
         }
 
-        void add(ServiceInterface si)
-        {
+        void add(ServiceInterface si) {
             m_parentService = si;
         }
-        
-        public void invoke(Runnable run)
-        {
+
+        public void invoke(Runnable run) {
             m_sequencer.step(2);
             m_parentService.invoke(run);
         }
     }
 
-    @AspectService(ranking = 10, added="added", removed="removed")
-    public static class ServiceAspect1 implements ServiceInterface
-    {
-        @ServiceDependency(filter="(name=AspectChainTest.ServiceAspect1)")
-        protected Sequencer m_sequencer;
+    @AspectService(ranking = 10, added = "added", removed = "removed")
+    public static class ServiceAspect1 implements ServiceInterface {
+        @ServiceDependency(filter = "(name=AspectChainTest.ServiceAspect1)")
+        protected volatile Ensure m_sequencer;
         // Injected by reflection.
         private volatile ServiceInterface m_parentService;
 
@@ -179,40 +161,35 @@ public class AspectChainTest
         void init() {
             System.out.println("ServiceAspect1.init");
         }
-        
+
         @Destroy
         void destroy() {
             System.out.println("ServiceAspect1.destroy");
         }
 
-        void added(ServiceInterface si)
-        {
+        void added(ServiceInterface si) {
             m_parentService = si;
         }
-                
+
         @Stop
-        void stop()
-        {
+        void stop() {
             m_sequencer.step(7);
         }
-        
-        void removed(ServiceInterface si)
-        {
+
+        void removed(ServiceInterface si) {
             m_sequencer.step(8);
         }
-        
-        public void invoke(Runnable run)
-        {
+
+        public void invoke(Runnable run) {
             m_sequencer.step(4);
             m_parentService.invoke(run);
         }
     }
 
     @Component
-    public static class ServiceConsumer implements Runnable
-    {
+    public static class ServiceConsumer implements Runnable {
         @ServiceDependency(filter = "(name=AspectChainTest.ServiceConsumer)")
-        protected Sequencer m_sequencer;
+        protected volatile Ensure m_sequencer;
 
         @ServiceDependency
         private volatile ServiceInterface m_service;
@@ -220,34 +197,26 @@ public class AspectChainTest
         private Thread m_thread;
 
         @Init
-        public void init()
-        {
+        public void init() {
             m_thread = new Thread(this, "ServiceConsumer");
             m_thread.start();
         }
 
-        public void run()
-        {
+        public void run() {
             m_sequencer.waitForStep(1, 2000);
-            m_service.invoke(new Runnable()
-            {
-                public void run()
-                {
+            m_service.invoke(new Runnable() {
+                public void run() {
                     m_sequencer.step(5);
                 }
             });
         }
-        
+
         @Destroy
-        void destroy()
-        {
+        void destroy() {
             m_thread.interrupt();
-            try
-            {
+            try {
                 m_thread.join();
-            }
-            catch (InterruptedException e)
-            {
+            } catch (InterruptedException e) {
             }
         }
     }

Copied: felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/AspectAnnotationTest.java (from r1531247, felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectAnnotationTest.java)
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/AspectAnnotationTest.java?p2=felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/AspectAnnotationTest.java&p1=felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectAnnotationTest.java&r1=1531247&r2=1531736&rev=1531736&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectAnnotationTest.java (original)
+++ felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/AspectAnnotationTest.java Sun Oct 13 19:27:54 2013
@@ -16,77 +16,46 @@
 * specific language governing permissions and limitations
 * under the License.
 */
-package org.apache.felix.dm.test.annotation;
+package org.apache.felix.dependencymanager.test2.integration.annotations;
 
-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.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.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.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceRegistration;
 
 /**
  * Use case: Verify Aspect Annotations usage.
  */
-@RunWith(JUnit4TestRunner.class)
-public class AspectAnnotationTest 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, "AspectTest")
-                    .set("Export-Package", "org.apache.felix.dm.test.bundle.annotation.sequencer")
-                    .set("Private-Package", "org.apache.felix.dm.test.bundle.annotation.aspect")
-                    .set("Import-Package", "*")
-                    .set("-plugin", "org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin")
-                    .build()));           
-    }
-
+@RunWith(PaxExam.class)
+public class AspectAnnotationTest extends TestBase {
     @Test
-    public void testAspectChain(BundleContext context) throws Throwable
-    {
-        DependencyManager m = new DependencyManager(context);
+    public void testAspectChain() throws Throwable {
+        Ensure e = new Ensure();
         // Activate service consumer
-        Component scSequencer = makeSequencer(m, "AspectChainTest.ServiceConsumer");
-        m.add(scSequencer);
+        ServiceRegistration scSequencer = register(e, "AspectChainTest.ServiceConsumer");
         // Activate service provider
-        Component spSequencer = makeSequencer(m, "AspectChainTest.ServiceProvider");
-        m.add(spSequencer);
+        ServiceRegistration spSequencer = register(e, "AspectChainTest.ServiceProvider");
         // Activate service aspect 2
-        Component sa2Sequencer = makeSequencer(m, "AspectChainTest.ServiceAspect2");
-        m.add(sa2Sequencer);
+        ServiceRegistration sa2Sequencer = register(e, "AspectChainTest.ServiceAspect2");
         // Activate service aspect 3
-        Component sa3Sequencer = makeSequencer(m, "AspectChainTest.ServiceAspect3");
-        m.add(sa3Sequencer);
+        ServiceRegistration sa3Sequencer = register(e, "AspectChainTest.ServiceAspect3");
         // Activate service aspect 1
-        Component sa1Sequencer = makeSequencer(m, "AspectChainTest.ServiceAspect1");
-        m.add(sa1Sequencer);
+        ServiceRegistration sa1Sequencer = register(e, "AspectChainTest.ServiceAspect1");
 
-        m_ensure.step();
-        m_ensure.waitForStep(6, 10000);
+        e.step();
+        e.waitForStep(6, 10000);
 
         // Deactivate service provider
-        m.remove(spSequencer);
+        spSequencer.unregister();
         // Make sure that service aspect 1 has been called in ts removed and stop callbacks 
-        m_ensure.waitForStep(8, 10000);
-        m_ensure.ensure();
-    }    
+        e.waitForStep(8, 10000);
+        e.ensure();
+        
+        scSequencer.unregister();
+        sa1Sequencer.unregister();
+        sa2Sequencer.unregister();
+        sa3Sequencer.unregister();
+    }
 }