felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r884482 - in /felix/trunk/dependencymanager: core/src/main/java/org/apache/felix/dependencymanager/ core/src/main/java/org/apache/felix/dependencymanager/dependencies/ test/src/test/java/org/apache/felix/dependencymanager/test/
Date Thu, 26 Nov 2009 09:58:44 GMT
Author: marrs
Date: Thu Nov 26 09:58:44 2009
New Revision: 884482

URL: http://svn.apache.org/viewvc?rev=884482&view=rev
Log:
added support for bundle dependencies plus a basic test

Added:
    felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/BundleDependencyTest.java
Modified:
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/DependencyActivatorBase.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/DependencyManager.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/dependencies/BundleDependency.java

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/DependencyActivatorBase.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/DependencyActivatorBase.java?rev=884482&r1=884481&r2=884482&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/DependencyActivatorBase.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/DependencyActivatorBase.java
Thu Nov 26 09:58:44 2009
@@ -20,6 +20,7 @@
 
 import java.util.List;
 
+import org.apache.felix.dependencymanager.dependencies.BundleDependency;
 import org.apache.felix.dependencymanager.dependencies.ConfigurationDependency;
 import org.apache.felix.dependencymanager.dependencies.ServiceDependency;
 import org.apache.felix.dependencymanager.dependencies.TemporalServiceDependency;
@@ -128,7 +129,16 @@
      * @return the configuration dependency
      */
     public ConfigurationDependency createConfigurationDependency() {
-    	return new ConfigurationDependency(m_context, m_logger);
+    	return m_manager.createConfigurationDependency();
+    }
+
+    /**
+     * Creates a new bundle dependency.
+     * 
+     * @return the bundle dependency
+     */
+    public BundleDependency createBundleDependency() {
+        return m_manager.createBundleDependency();
     }
 
     /**

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/DependencyManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/DependencyManager.java?rev=884482&r1=884481&r2=884482&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/DependencyManager.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/DependencyManager.java
Thu Nov 26 09:58:44 2009
@@ -22,6 +22,7 @@
 import java.util.Collections;
 import java.util.List;
 
+import org.apache.felix.dependencymanager.dependencies.BundleDependency;
 import org.apache.felix.dependencymanager.dependencies.ConfigurationDependency;
 import org.apache.felix.dependencymanager.dependencies.ServiceDependency;
 import org.apache.felix.dependencymanager.dependencies.TemporalServiceDependency;
@@ -104,6 +105,10 @@
         return new ConfigurationDependency(m_context, m_logger);
     }
     
+    public BundleDependency createBundleDependency() {
+        return new BundleDependency(m_context, m_logger);
+    }
+    
     /**
      * Returns a list of services.
      * 

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/dependencies/BundleDependency.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/dependencies/BundleDependency.java?rev=884482&r1=884481&r2=884482&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/dependencies/BundleDependency.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/dependencies/BundleDependency.java
Thu Nov 26 09:58:44 2009
@@ -41,7 +41,7 @@
 	private final Logger m_logger;
 	private boolean m_isStarted;
 	private BundleTracker m_tracker;
-	private int m_stateMask;
+	private int m_stateMask = Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE;
 	private boolean m_isAvailable;
 	private boolean m_isRequired;
 	private DependencyService m_service;

Added: felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/BundleDependencyTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/BundleDependencyTest.java?rev=884482&view=auto
==============================================================================
--- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/BundleDependencyTest.java
(added)
+++ felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/BundleDependencyTest.java
Thu Nov 26 09:58:44 2009
@@ -0,0 +1,76 @@
+package org.apache.felix.dependencymanager.test;
+
+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 junit.framework.Assert;
+
+import org.apache.felix.dependencymanager.DependencyManager;
+import org.apache.felix.dependencymanager.Service;
+import org.apache.felix.dependencymanager.impl.Logger;
+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.Bundle;
+import org.osgi.framework.BundleContext;
+
+@RunWith(JUnit4TestRunner.class)
+public class BundleDependencyTest {
+    @Configuration
+    public static Option[] configuration() {
+        return options(
+            provision(
+                mavenBundle().groupId("org.osgi").artifactId("org.osgi.compendium").version("4.2.0"),
+                mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager").versionAsInProject()
+            )
+        );
+    }    
+    
+    @Test
+    public void testBundleDependencies(BundleContext context) {
+        DependencyManager m = new DependencyManager(context, new Logger(context));
+        // helper class that ensures certain steps get executed in sequence
+        Ensure e = new Ensure();
+        // create a service provider and consumer
+        Consumer c = new Consumer(e);
+        Service consumer = m.createService().setImplementation(c).add(m.createBundleDependency().setCallbacks("add",
"remove"));
+//        Service consumerWithFilter = m.createService().setImplementation(new Consumer(e)).add(m.createBundleDependency().setFilter(""));
+//        Service consumerWithStateMask = m.createService().setImplementation(new Consumer(e)).add(m.createBundleDependency().setStateMask(0));
+        // add the service consumer
+        m.add(consumer);
+        // check if at least one bundle was found
+        c.check();
+        // remove the consumer again
+        m.remove(consumer);
+        // check if all bundles were removed correctly
+        c.doubleCheck();
+    }
+    
+    static class Consumer {
+        private final Ensure m_ensure;
+        private int m_count = 0;
+
+        public Consumer(Ensure e) {
+            m_ensure = e;
+        }
+        
+        public void add(Bundle b) {
+            Assert.assertNotNull("bundle instance must not be null", b);
+            m_count++;
+        }
+        
+        public void check() {
+            Assert.assertTrue("we should have found at least one bundle", m_count > 0);
+        }
+        
+        public void remove(Bundle b) {
+            m_count--;
+        }
+        
+        public void doubleCheck() {
+            Assert.assertTrue("all bundles we found should have been removed again", m_count
== 0);
+        }
+    }
+}



Mime
View raw message