felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r953564 - in /felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory: MyService.java MyServiceFactory.java
Date Fri, 11 Jun 2010 05:50:29 GMT
Author: pderop
Date: Fri Jun 11 05:50:29 2010
New Revision: 953564

URL: http://svn.apache.org/viewvc?rev=953564&view=rev
Log:
Modified annotation service factory test in order to validate that dependency filters are
properly configured from init methods.

Modified:
    felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyService.java
    felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyServiceFactory.java

Modified: felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyService.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyService.java?rev=953564&r1=953563&r2=953564&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyService.java
(original)
+++ felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyService.java
Fri Jun 11 05:50:29 2010
@@ -19,23 +19,46 @@
 package org.apache.felix.dm.test.bundle.annotation.factory;
 
 import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
 
+import junit.framework.Assert;
+
+import org.apache.felix.dm.annotation.api.Init;
 import org.apache.felix.dm.annotation.api.Property;
 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.apache.felix.dm.annotation.api.ServiceDependency;
 import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
 
+/**
+ * This service will be instantiated by our MyServiceFactory class.
+ */
 @Service(factory = "MyServiceFactory", factoryConfigure = "configure", properties = { @Property(name
= "foo", value = "bar") })
 public class MyService implements MyServiceInterface
 {
-    @ServiceDependency
-    Sequencer m_sequencer;
-
+    /**
+     *  The configuration provided by MyServiceFactory
+     */
     @SuppressWarnings("unchecked")
     Dictionary m_configuration;
 
+    /**
+     *  Our sequencer.
+     */
+    @ServiceDependency
+    Sequencer m_sequencer;
+    
+    /**
+     *  An extra dependency (we'll dynamically configure the filter from our init() method).
+     */
+    @ServiceDependency(name="extra")
+    Runnable m_extra;
+
+    /**
+     * This is the first method called: we are provided with the MyServiceFactory configuration.
+     */
     public void configure(Dictionary<?, ?> configuration)
     {
         if (m_configuration == null)
@@ -48,12 +71,32 @@ public class MyService implements MyServ
         }
     }
 
+    /**
+     * Initialize our Service: we'll dynamically configure our dependency whose name is "extra".
+     */
+    @Init
+    Map init() 
+    {
+        return new HashMap() {{
+            put("extra.filter", "(foo=bar2)");
+            put("extra.required", "true");
+        }};
+    }
+        
+    /**
+     * our Service is starting: at this point, all required dependencies have been injected.
+     */
     @Start
     public void start()
     {
+        Assert.assertNotNull("Extra dependency not injected", m_extra);
+        m_extra.run();
         m_sequencer.step(2);
     }
 
+    /**
+     * Our service is stopping.
+     */
     @Stop
     public void stop()
     {

Modified: felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyServiceFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyServiceFactory.java?rev=953564&r1=953563&r2=953564&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyServiceFactory.java
(original)
+++ felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyServiceFactory.java
Fri Jun 11 05:50:29 2010
@@ -26,8 +26,8 @@ import java.util.Set;
 import junit.framework.Assert;
 
 import org.apache.felix.dm.annotation.api.Service;
-import org.apache.felix.dm.annotation.api.Start;
 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;
 
 @SuppressWarnings("unchecked")
@@ -36,10 +36,10 @@ public class MyServiceFactory
 {
     @ServiceDependency(filter = "(dm.factory.name=MyServiceFactory)")
     Set<Dictionary> m_myServiceFactory;
-
+    
     @ServiceDependency
-    Sequencer m_sequencer;
-
+    Sequencer m_sequencer;    
+    
     Hashtable m_conf;
 
     @Start



Mime
View raw message