Added a default template for the overall site (but this still needs work).
Added test dependencies to junit and easymock.
Added a couple of unit test to the dependency manager (as an example of how to do this).
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@418696 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/org.apache.felix.dependencymanager/pom.xml b/org.apache.felix.dependencymanager/pom.xml
index 0258f53..4450b52 100644
--- a/org.apache.felix.dependencymanager/pom.xml
+++ b/org.apache.felix.dependencymanager/pom.xml
@@ -15,6 +15,20 @@
<version>${pom.version}</version>
<scope>provided</scope>
</dependency>
+ <!--
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+ -->
</dependencies>
<build>
<plugins>
diff --git a/org.apache.felix.dependencymanager/src/main/java/org/apache/felix/dependencymanager/ServiceImpl.java b/org.apache.felix.dependencymanager/src/main/java/org/apache/felix/dependencymanager/ServiceImpl.java
index 42907a0..0ba7404 100644
--- a/org.apache.felix.dependencymanager/src/main/java/org/apache/felix/dependencymanager/ServiceImpl.java
+++ b/org.apache.felix.dependencymanager/src/main/java/org/apache/felix/dependencymanager/ServiceImpl.java
@@ -246,7 +246,9 @@
}
catch (Exception e) {
// TODO handle this exception
- e.printStackTrace();
+ // e.printStackTrace();
+ // TODO remove line below!!!
+ throw new RuntimeException(e);
}
}
}
diff --git a/org.apache.felix.dependencymanager/src/test/java/org/apache/felix/dependencymanager/ServiceDependencyTest.java b/org.apache.felix.dependencymanager/src/test/java/org/apache/felix/dependencymanager/ServiceDependencyTest.java
new file mode 100644
index 0000000..601dd72
--- /dev/null
+++ b/org.apache.felix.dependencymanager/src/test/java/org/apache/felix/dependencymanager/ServiceDependencyTest.java
@@ -0,0 +1,165 @@
+package org.apache.felix.dependencymanager;
+
+import junit.framework.TestCase;
+
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+
+public class ServiceDependencyTest extends TestCase {
+ /**
+ * Checks the basic life-cycle of a service that has no dependencies.
+ * Makes sure that the init, start, stop and destroy callbacks are
+ * invoked on the implementation.
+ */
+ public void testStandaloneService() throws Exception {
+ // setup the mock objects
+ IMocksControl ctrl = EasyMock.createControl();
+ BundleContext context = ctrl.createMock(BundleContext.class);
+ MyService svc = ctrl.createMock(MyService.class);
+ ctrl.checkOrder(true);
+ svc.init();
+ svc.start();
+ svc.stop();
+ svc.destroy();
+ // start the actual test
+ ctrl.replay();
+ DependencyManager dm = new DependencyManager(context);
+ Service service = new ServiceImpl(context).setImplementation(svc);
+ dm.add(service);
+ dm.remove(service);
+ // verify the results
+ ctrl.verify();
+ }
+
+ /**
+ * Defines a service with one required dependency that is not
+ * available. Makes sure the service is not started.
+ */
+ public void testRequiredUnavailableDependency() throws Exception {
+ // setup the mock objects
+ IMocksControl ctrl = EasyMock.createControl();
+ BundleContext context = ctrl.createMock(BundleContext.class);
+ Dependency dependency = ctrl.createMock(Dependency.class);
+ MyService svc = ctrl.createMock(MyService.class);
+ ctrl.checkOrder(false);
+ EasyMock.expect(dependency.isRequired()).andReturn(Boolean.TRUE).anyTimes();
+ EasyMock.expect(dependency.isAvailable()).andReturn(Boolean.FALSE).anyTimes();
+ dependency.start((Service) EasyMock.anyObject());
+ dependency.stop((Service) EasyMock.anyObject());
+ // start the actual test
+ ctrl.replay();
+ DependencyManager dm = new DependencyManager(context);
+ Service service = new ServiceImpl(context)
+ .setImplementation(svc)
+ .add(dependency);
+ dm.add(service);
+ dm.remove(service);
+ // verify the results
+ ctrl.verify();
+ }
+
+ /**
+ * Defines a service with one required dependency that is
+ * available. Makes sure the service is started.
+ */
+ public void testRequiredAvailableDependency() throws Exception {
+ // setup the mock objects
+ IMocksControl ctrl = EasyMock.createControl();
+ BundleContext context = ctrl.createMock(BundleContext.class);
+ Dependency dependency = ctrl.createMock(Dependency.class);
+ MyService svc = ctrl.createMock(MyService.class);
+ ctrl.checkOrder(false);
+ EasyMock.expect(dependency.isRequired()).andReturn(Boolean.TRUE).anyTimes();
+ EasyMock.expect(dependency.isAvailable()).andReturn(Boolean.TRUE).anyTimes();
+ dependency.start((Service) EasyMock.anyObject());
+ svc.init();
+ svc.start();
+ svc.stop();
+ svc.destroy();
+ dependency.stop((Service) EasyMock.anyObject());
+ // start the actual test
+ ctrl.replay();
+ DependencyManager dm = new DependencyManager(context);
+ Service service = new ServiceImpl(context)
+ .setImplementation(svc)
+ .add(dependency);
+ dm.add(service);
+ dm.remove(service);
+ // verify the results
+ ctrl.verify();
+ }
+
+ /**
+ * Defines a service with an optional dependency that is not available.
+ * Makes sure the service is started.
+ */
+ public void testOptionalDependency() throws Exception {
+ // setup the mock objects
+ IMocksControl ctrl = EasyMock.createControl();
+ BundleContext context = ctrl.createMock(BundleContext.class);
+ Dependency dependency = ctrl.createMock(Dependency.class);
+ MyService svc = ctrl.createMock(MyService.class);
+ ctrl.checkOrder(false);
+ EasyMock.expect(dependency.isRequired()).andReturn(Boolean.FALSE).anyTimes();
+ EasyMock.expect(dependency.isAvailable()).andReturn(Boolean.FALSE).anyTimes();
+ dependency.start((Service) EasyMock.anyObject());
+ svc.init();
+ svc.start();
+ svc.stop();
+ svc.destroy();
+ dependency.stop((Service) EasyMock.anyObject());
+ // start the actual test
+ ctrl.replay();
+ DependencyManager dm = new DependencyManager(context);
+ Service service = new ServiceImpl(context)
+ .setImplementation(svc)
+ .add(dependency);
+ dm.add(service);
+ dm.remove(service);
+ // verify the results
+ ctrl.verify();
+ }
+
+ public void XtestRequiredAvailableServiceDependency() throws Exception {
+ // setup the mock objects
+ IMocksControl ctrl = EasyMock.createControl();
+ BundleContext context = ctrl.createMock(BundleContext.class);
+ Filter filter = ctrl.createMock(Filter.class);
+ MyService svc = ctrl.createMock(MyService.class);
+ ctrl.checkOrder(false);
+ EasyMock.expect(context.createFilter("(objectClass=org.apache.felix.dependencymanager.DummyService)")).andReturn(filter);
+ context.addServiceListener((ServiceListener) EasyMock.anyObject());
+ EasyMock.expect(context.getServiceReferences(null, "EasyMock for interface org.osgi.framework.Filter")).andReturn(new ServiceReference[] {});
+ context.removeServiceListener((ServiceListener) EasyMock.anyObject());
+ svc.init();
+ svc.start();
+ svc.stop();
+ svc.destroy();
+ // start the actual test
+ ctrl.replay();
+ DependencyManager dm = new DependencyManager(context);
+ Service service = new ServiceImpl(context)
+ .setImplementation(svc)
+ .add(new ServiceDependency(context)
+ .setRequired(true)
+ .setService(DummyService.class));
+ dm.add(service);
+ dm.remove(service);
+ // verify the results
+ ctrl.verify();
+ }
+}
+
+interface MyService {
+ public void init();
+ public void start();
+ public void stop();
+ public void destroy();
+}
+
+interface DummyService {
+}
diff --git a/pom.xml b/pom.xml
index 0260bb9..cd83501 100644
--- a/pom.xml
+++ b/pom.xml
@@ -91,4 +91,39 @@
</pluginRepository>
</pluginRepositories>
+ <!-- definitions for testing -->
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-report-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </reporting>
</project>
diff --git a/src/site/site.xml b/src/site/site.xml
new file mode 100644
index 0000000..857d174
--- /dev/null
+++ b/src/site/site.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<project name="Apache Felix">
+ <bannerLeft>
+ <name>Apache Felix</name>
+ <href>http://incubator.apache.org/felix/</href>
+ </bannerLeft>
+ <body>
+ <links>
+ <item name="Apache" href="http://www.apache.org/" />
+ <item name="Wiki" href="#"/>
+ </links>
+
+ <menu name="Apache Felix">
+ <item name="Introduction" href="index.html"/>
+ <item name="Download" href="download.html"/>
+ <item name="Release Notes" href="release-notes.html" />
+ <item name="General Information" href="about.html"/>
+ <item name="Road Map" href="roadmap.html" />
+ </menu>
+
+ <menu ref="modules" />
+
+ <menu ref="reports" />
+
+ <menu name="Test Reports">
+ <item name="Unit tests" href="surefire-report.html" />
+ </menu>
+
+ ${reports}
+
+ </body>
+</project>