felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r910049 - in /felix/trunk/dependencymanager/test: annotation/src/main/java/org/apache/felix/dm/test/annotation/AspectLifecycleTest.java src/test/java/org/apache/felix/dm/test/AnnotationTest.java
Date Sun, 14 Feb 2010 17:24:13 GMT
Author: pderop
Date: Sun Feb 14 17:24:13 2010
New Revision: 910049

URL: http://svn.apache.org/viewvc?rev=910049&view=rev
Log:
added new AspectWithLifecycleAnnotation test

Added:
    felix/trunk/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/AspectLifecycleTest.java
Modified:
    felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/AnnotationTest.java

Added: felix/trunk/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/AspectLifecycleTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/AspectLifecycleTest.java?rev=910049&view=auto
==============================================================================
--- felix/trunk/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/AspectLifecycleTest.java
(added)
+++ felix/trunk/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/AspectLifecycleTest.java
Sun Feb 14 17:24:13 2010
@@ -0,0 +1,100 @@
+/*
+ * 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 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.Param;
+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.annotation.api.Stop;
+import org.osgi.framework.Constants;
+
+/**
+ * Tests an aspect service, and ensure that its lifecycle methods are properly invoked (init/start/stop/destroy)
+ */
+@Service
+public class AspectLifecycleTest
+{
+    public interface ServiceInterface
+    {
+        public void run();
+    }
+
+    @ServiceDependency
+    void bind(ServiceInterface service)
+    {
+        service.run();
+    }
+
+    @Service
+    public static class ServiceProvider implements ServiceInterface
+    {
+        @ServiceDependency(filter = "(test=aspectLifecycle.ServiceProvider)")
+        protected Sequencer m_sequencer;
+
+        public void run()
+        {
+            m_sequencer.step(1);
+        }
+    }
+
+    @AspectService(filter = "(!(" + Constants.SERVICE_RANKING + "=*))", properties = { @Param(name
= Constants.SERVICE_RANKING, value = "1") })
+    public static 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() {
+            m_sequencer.step(5);
+        }
+        
+        @Destroy
+        void destroy() {
+            m_sequencer.step(6);
+        }
+    }
+}

Modified: felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/AnnotationTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/AnnotationTest.java?rev=910049&r1=910048&r2=910049&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/AnnotationTest.java
(original)
+++ felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/AnnotationTest.java
Sun Feb 14 17:24:13 2010
@@ -140,6 +140,27 @@
         m_ensure.waitForStep(2, 10000);
     }
 
+    @Test
+    public void testAspectWithLifecycleAnnotation(BundleContext context)
+    {
+        m_ensure = new Ensure();
+        DependencyManager m = new DependencyManager(context);
+        // We provide ourself as a "Sequencer" service: this will active the org.apache.felix.dependencymanager.test.annotation.AspectTest
service
+        Dictionary props = new Hashtable() {{ put("test", "aspectLifecycle.ServiceProvider");
}};
+        m.add(m.createService().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 for activating the ServiceProviderAspect service
+        props = new Hashtable() {{ put("test", "aspectLifecycle.ServiceProviderAspect");
}};
+        m.add(m.createService().setImplementation(this).setInterface(Sequencer.class.getName(),
props));
+        // Check if the AspectTest has been injected with the aspect
+        m_ensure.waitForStep(3, 10000);
+        // Stop the test.annotation bundle.
+        stopAnnotationBundle(context);
+        // And check if the aspect has been called in its stop/destroy methods.
+        m_ensure.waitForStep(6, 10000);
+    }
+
     private void sleep(int i)
     {
         try {



Mime
View raw message