Modified: 
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/sequencer/Sequencer.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/sequencer/Sequencer.java?rev=1125833&r1=1125832&r2=1125833&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/sequencer/Sequencer.java
 (original)
+++ 
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/sequencer/Sequencer.java
 Sat May 21 22:14:54 2011
@@ -40,4 +40,10 @@ public interface Sequencer
      * @param timeout max milliseconds to wait.
      */
     void waitForStep(int step, int timeout);
+    
+    /**
+     *  Saves a thrown exception that occurred in a different thread. You can 
only save one exception
+     * at a time this way.
+     */
+    void throwable(Throwable throwable);
 }

Modified: 
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/simple/Consumer.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/simple/Consumer.java?rev=1125833&r1=1125832&r2=1125833&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/simple/Consumer.java
 (original)
+++ 
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/simple/Consumer.java
 Sat May 21 22:14:54 2011
@@ -18,11 +18,14 @@
  */
 package org.apache.felix.dm.test.bundle.annotation.simple;
 
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.annotation.api.Inject;
 import org.apache.felix.dm.annotation.api.Component;
 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;
+import org.osgi.framework.BundleContext;
 
 /**
  * Consumes a service which is provided by the {@link Producer} class.
@@ -35,15 +38,64 @@ public class Consumer
     
     @ServiceDependency
     Sequencer m_sequencer;
+    
+    @Inject
+    BundleContext m_bc;
+    BundleContext m_bcNotInjected;
+    
+    @Inject
+    DependencyManager m_dm;
+    DependencyManager m_dmNotInjected;
+    
+    @Inject
+    org.apache.felix.dm.Component m_component;
+    org.apache.felix.dm.Component m_componentNotInjected;
 
     @Start
     protected void start() {
-        m_sequencer.step(2);
+        checkInjectedFields();
+        m_sequencer.step(3);
         m_runnable.run();
     }
     
+    private void checkInjectedFields()
+    {
+        if (m_bc == null)
+        {
+            m_sequencer.throwable(new Exception("Bundle Context not 
injected"));
+            return;
+        }
+        if (m_bcNotInjected != null)
+        {
+            m_sequencer.throwable(new Exception("Bundle Context must not be 
injected"));
+            return;
+        }
+
+        if (m_dm == null)
+        {
+            m_sequencer.throwable(new Exception("DependencyManager not 
injected"));
+            return;
+        }
+        if (m_dmNotInjected != null)
+        {
+            m_sequencer.throwable(new Exception("DependencyManager must not be 
injected"));
+            return;
+        }
+
+        if (m_component == null)
+        {
+            m_sequencer.throwable(new Exception("Component not injected"));
+            return;
+        }
+        if (m_componentNotInjected != null)
+        {
+            m_sequencer.throwable(new Exception("Component must not be 
injected"));
+            return;
+        }
+    }
+
     @Stop
     protected void stop() {
-        m_sequencer.step(4);
+        m_sequencer.step(6);
     }
 }

Modified: 
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/simple/Producer.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/simple/Producer.java?rev=1125833&r1=1125832&r2=1125833&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/simple/Producer.java
 (original)
+++ 
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/simple/Producer.java
 Sat May 21 22:14:54 2011
@@ -19,32 +19,79 @@
 package org.apache.felix.dm.test.bundle.annotation.simple;
 
 import org.apache.felix.dm.annotation.api.Component;
+import org.apache.felix.dm.annotation.api.Property;
+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.Registered;
 import org.apache.felix.dm.annotation.api.Stop;
+import org.apache.felix.dm.annotation.api.Unregistered;
 import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
+import org.osgi.framework.ServiceRegistration;
 
 /**
  * Provides a <code>Runnable</code> service, which is required by the {@link 
Consumer} class.
  */
-@Component
+@Component(properties={@Property(name="foo", value="bar")})
 public class Producer implements Runnable
 {
     @ServiceDependency
     Sequencer m_sequencer;
+
+    @Init
+    protected void init()
+    {
+        // Our component is initializing (at this point: all required 
dependencies are injected).
+        m_sequencer.step(1);  
+    }
     
     @Start
-    protected void start() {
-        m_sequencer.step(1);
+    protected void start()
+    {
+        // We are about to be registered in the OSGi registry.
+        m_sequencer.step(2);
     }
-    
-    @Stop
-    protected void stop() {
+
+    public void run()
+    {
+        // the Consumer has been injected with our service, and is invoking 
our run() method.
+        m_sequencer.step(4);
+    }
+
+    @Registered
+    protected void started(ServiceRegistration sr)
+    {
+        // We are registered in the OSGi registry
+        if (sr == null)
+        {
+            m_sequencer.throwable(new Exception("ServiceRegistration is 
null"));
+        }
+        if (!"bar".equals(sr.getReference().getProperty("foo")))
+        {
+            m_sequencer.throwable(new Exception("Invalid Service Properties"));
+        }
         m_sequencer.step(5);
     }
+
+    @Stop
+    protected void stop()
+    {
+        // We are about to be unregistered from the OSGi registry, and we must 
stop.
+        m_sequencer.step(7);
+    }
+
+    @Unregistered
+    protected void stopped()
+    {
+        // We are unregistered from the OSGi registry.
+        m_sequencer.step(8);
+    }    
     
-    public void run()
+    @Destroy
+    public void destroy()
     {
-        m_sequencer.step(3);
+        // Our component is shutting down.
+        m_sequencer.step(9); 
     }
 }

Modified: 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AdapterAnnotationTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AdapterAnnotationTest.java?rev=1125833&r1=1125832&r2=1125833&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AdapterAnnotationTest.java
 (original)
+++ 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AdapterAnnotationTest.java
 Sat May 21 22:14:54 2011
@@ -76,12 +76,13 @@ public class AdapterAnnotationTest exten
      * Check if an adapter gets injected with its adaptee in a named class 
field.
      */
     @Test
-    public void testAnnotatedAdapterAutoConfigField(BundleContext context)
+    public void testAnnotatedAdapterAutoConfigField(BundleContext context) 
throws Throwable
     {
         DependencyManager m = new DependencyManager(context);
         // Provide the Sequencer to the 
org.apache.felix.dm.test.bundle.annotation.adapter.AdapterTest bundle 
         m.add(makeSequencer(m, "AdapterAutoConfigField"));
         m_ensure.waitForStep(3, 10000);
+        m_ensure.ensure();
     }
     
     /**

Modified: 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AnnotationBase.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AnnotationBase.java?rev=1125833&r1=1125832&r2=1125833&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AnnotationBase.java
 (original)
+++ 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AnnotationBase.java
 Sat May 21 22:14:54 2011
@@ -113,4 +113,9 @@ public class AnnotationBase extends Base
     {
         m_ensure.waitForStep(nr, timeout);
     }
+
+    public void throwable(Throwable throwable)
+    {
+        m_ensure.throwable(throwable);
+    }
 }

Modified: 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectAnnotationTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectAnnotationTest.java?rev=1125833&r1=1125832&r2=1125833&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectAnnotationTest.java
 (original)
+++ 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/AspectAnnotationTest.java
 Sat May 21 22:14:54 2011
@@ -61,7 +61,7 @@ public class AspectAnnotationTest extend
     }
 
     @Test
-    public void testAspectChain(BundleContext context)
+    public void testAspectChain(BundleContext context) throws Throwable
     {
         DependencyManager m = new DependencyManager(context);
         // Activate service consumer
@@ -87,5 +87,6 @@ public class AspectAnnotationTest extend
         m.remove(spSequencer);
         // Make sure that service aspect 1 has been called in ts removed and 
stop callbacks 
         m_ensure.waitForStep(8, 10000);
+        m_ensure.ensure();
     }    
 }

Modified: 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/BundleDependencyAnnotationTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/BundleDependencyAnnotationTest.java?rev=1125833&r1=1125832&r2=1125833&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/BundleDependencyAnnotationTest.java
 (original)
+++ 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/BundleDependencyAnnotationTest.java
 Sat May 21 22:14:54 2011
@@ -80,13 +80,15 @@ public class BundleDependencyAnnotationT
     /**
      * Tests a Bundle Adapter, which adapts the dependency manager bundle to a 
"ServiceInterface" service.
      * @param context
+     * @throws Throwable 
      */
     @Test
-    public void testBundleAdapterServiceAnnotation(BundleContext context)
+    public void testBundleAdapterServiceAnnotation(BundleContext context) 
throws Throwable
     {
         DependencyManager m = new DependencyManager(context);
         Properties props = new Properties() {{ put("test", "adapter"); }};
         
m.add(m.createComponent().setImplementation(this).setInterface(Sequencer.class.getName(),
 props));
         m_ensure.waitForStep(3, 10000);
+        m_ensure.ensure();
     }    
 }

Modified: 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/FactoryConfigurationAdapterAnnotationTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/FactoryConfigurationAdapterAnnotationTest.java?rev=1125833&r1=1125832&r2=1125833&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/FactoryConfigurationAdapterAnnotationTest.java
 (original)
+++ 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/FactoryConfigurationAdapterAnnotationTest.java
 Sat May 21 22:14:54 2011
@@ -69,7 +69,7 @@ public class FactoryConfigurationAdapter
     }
 
     @Test
-    public void testFactoryConfigurationAdapterAnnotation(BundleContext 
context)
+    public void testFactoryConfigurationAdapterAnnotation(BundleContext 
context) throws Throwable
     {
         DependencyManager m = new DependencyManager(context);
         // Provide the Sequencer to the adapter bundle service (see 
main/src/.../factoryconfadapter/*.java). 
@@ -89,7 +89,8 @@ public class FactoryConfigurationAdapter
             // Remove configuration.
             cf.delete();
             // Check if ServiceProvider has been stopped.
-            m_ensure.waitForStep(5, 1000);
+            m_ensure.waitForStep(6, 1000);
+            m_ensure.ensure();
         }
         catch (IOException e)
         {

Modified: 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/ResourceAnnotationTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/ResourceAnnotationTest.java?rev=1125833&r1=1125832&r2=1125833&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/ResourceAnnotationTest.java
 (original)
+++ 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/ResourceAnnotationTest.java
 Sat May 21 22:14:54 2011
@@ -94,12 +94,13 @@ public class ResourceAnnotationTest exte
      * @param context
      */
     @Test
-    public void testResourceAdapterAnnotation(BundleContext context)
+    public void testResourceAdapterAnnotation(BundleContext context) throws 
Throwable
     {
         DependencyManager m = new DependencyManager(context);
         Properties props = new Properties() {{ put("test", "adapter"); }};
         
m.add(m.createComponent().setImplementation(this).setInterface(Sequencer.class.getName(),
 props));
         super.stopBundle("ResourceTest", context);
         m_ensure.waitForStep(2, 10000);
+        m_ensure.ensure();
     }
 }

Modified: 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/SimpleAnnotationTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/SimpleAnnotationTest.java?rev=1125833&r1=1125832&r2=1125833&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/SimpleAnnotationTest.java
 (original)
+++ 
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/SimpleAnnotationTest.java
 Sat May 21 22:14:54 2011
@@ -61,7 +61,7 @@ public class SimpleAnnotationTest extend
     }
 
     @Test
-    public void testSimpleAnnotations(BundleContext context)
+    public void testSimpleAnnotations(BundleContext context) throws Throwable
     {
         DependencyManager m = new DependencyManager(context);
         // We provide ourself as a "Sequencer" service to the annotated 
bundles. 
@@ -71,6 +71,7 @@ public class SimpleAnnotationTest extend
         // Stop our annotation bundle.
         stopBundle("SimpleAnnotationTest", context);
         // And check if components have been deactivated orderly.
-        m_ensure.waitForStep(5, 10000);
+        m_ensure.waitForStep(9, 10000);
+        m_ensure.ensure();
     }        
 }


Reply via email to