working with pax runner.
authorErik Brakkee <erik@brakkee.org>
Thu, 18 Aug 2011 20:29:52 +0000 (22:29 +0200)
committerErik Brakkee <erik@brakkee.org>
Thu, 18 Aug 2011 20:29:52 +0000 (22:29 +0200)
integrationtest/pom.xml
integrationtest/src/test/java/org/wamblee/xmlrouter/integrationtest/XmlRouterIntegrationTest.java
pom.xml
router/bundle/src/main/java/org/wamblee/xmlrouter/bundle/XmlrouterActivator.java

index 14256d05a3e9cfcc98a8684123821a38c32b86c8..fe3daa8783a3bf46d60436087c47f2a275f49cb7 100644 (file)
@@ -1,5 +1,6 @@
 <?xml version="1.0"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 
     <parent>
         <groupId>org.wamblee.xmlrouter</groupId>
     <packaging>jar</packaging>
     <name>/xmlrouter/integrationtest</name>
     <url>http://wamblee.org</url>
-    
+
     <dependencies>
         <dependency>
             <groupId>org.wamblee.xmlrouter</groupId>
             <artifactId>xmlrouter-router-bundle</artifactId>
             <version>0.1.0-SNAPSHOT</version>
         </dependency>
-       
+
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
@@ -27,8 +28,8 @@
         <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-all</artifactId>
-        </dependency>        
-        
+        </dependency>
+
         <!-- OSGI -->
         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.compendium</artifactId>
             <version>4.2.0</version>
         </dependency>
-        
+
         <!-- Pax exam -->
+
+        <!-- only runner -->
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-container-paxrunner</artifactId>
+        </dependency>
+
+        <!-- only runner -->
+        <dependency>
+            <groupId>org.ops4j.pax.runner</groupId>
+            <artifactId>pax-runner-no-jcl</artifactId>
+        </dependency>
+
+
         <!-- both runner and native -->
         <dependency>
             <groupId>org.ops4j.pax.exam</groupId>
             <artifactId>pax-exam-junit4</artifactId>
         </dependency>
-        
+
         <!-- both runner and native -->
         <dependency>
             <groupId>org.ops4j.pax.exam</groupId>
             <artifactId>pax-exam-link-mvn</artifactId>
         </dependency>
-        
+
         <!-- only native -->
+        <!--
         <dependency>
             <groupId>org.ops4j.pax.exam</groupId>
             <artifactId>pax-exam-container-native</artifactId>
         </dependency>
-        
+        -->
+
         <!-- only native -->
+        <!-- 
         <dependency>
             <groupId>org.ops4j.pax.url</groupId>
             <artifactId>pax-url-aether</artifactId>
             <groupId>org.ops4j.pax.url</groupId>
             <artifactId>pax-url-wrap</artifactId>
         </dependency>
-        
+        -->
+
         <!-- only native -->
+        <!-- 
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.framework</artifactId>
         </dependency>
-        
-        
+        -->
+
+
     </dependencies>
-    
+
     <build>
         <plugins>
             <plugin>
             </plugin>
         </plugins>
     </build>
-    
+
     <distributionManagement>
         <site>
             <id>xmlrouter-site</id>
index 7ca83cac3d61f518d41707196b965f38e7bc7060..a07a137b3f94e6db42b4dad602b4ebb722473741 100644 (file)
  */
 package org.wamblee.xmlrouter.integrationtest;
 
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.*;
 import static org.ops4j.pax.exam.CoreOptions.*;
 
+import javax.xml.transform.dom.DOMSource;
+
 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.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.wamblee.xmlrouter.subscribe.Destination;
 
 @RunWith(JUnit4TestRunner.class)
 public class XmlRouterIntegrationTest {
@@ -30,11 +36,14 @@ public class XmlRouterIntegrationTest {
     @Configuration()
     public Option[] config() {
         return options(
+            cleanCaches(),
             // Test dependencies
-            mavenBundle().groupId("junit").artifactId("junit-dep")
-                .version("4.8.2"), //
+            wrappedBundle(mavenBundle().groupId("junit")
+                .artifactId("junit-dep").version("4.8.2")), //
             mavenBundle().groupId("org.mockito").artifactId("mockito-all")
                 .version("1.8.5"), //
+            // junitBundles(),
+            // mockitoBundles(),
 
             // XML Router API packages.
             mavenBundle().groupId("org.wamblee.xmlrouter")
@@ -57,9 +66,17 @@ public class XmlRouterIntegrationTest {
     }
 
     @Test
-    public void test1(BundleContext aContext) {
+    public void test1(BundleContext aContext) throws InterruptedException {
         System.out.println("=== Got context " + aContext);
 
-    }
+        Destination dest = mock(Destination.class);
+        // verify(dest, never()).receive(any(DOMSource.class));
+        ServiceRegistration registration = aContext.registerService(
+            Destination.class.getName(), dest, null);
 
+        Thread.sleep(5000);
+        verify(dest, atLeastOnce()).receive(any(DOMSource.class));
+
+        registration.unregister();
+    }
 }
diff --git a/pom.xml b/pom.xml
index d2d2a858a7558040a3193bd52286e595feeb347f..0ea6cdac56889fb2ab5f3a70332190acc6e1bc42 100644 (file)
--- a/pom.xml
+++ b/pom.xml
             <dependency>
                 <groupId>org.mockito</groupId>
                 <artifactId>mockito-all</artifactId>
-                <version>1.8.0</version>
+                <version>1.8.5</version>
                 <scope>test</scope>
             </dependency>
             
index a070598f57d14d821916abf4bb22b865d68b585e..f01c0f67c090512bb9fc77e3ef08eb1bcdf932b8 100644 (file)
  */
 package org.wamblee.xmlrouter.bundle;
 
+import java.util.Timer;
+import java.util.TimerTask;
+
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
+import org.wamblee.xmlrouter.subscribe.Destination;
 
 public class XmlrouterActivator implements BundleActivator {
 
+    private BundleContext context;
+    private ServiceTracker destinations;
+    private Timer timer;
+
     @Override
     public void start(BundleContext aContext) throws Exception {
-        System.out.println("Starting bundle");
+        System.out.println("=== Starting bundle");
+        context = aContext;
+        destinations = new ServiceTracker(aContext,
+            Destination.class.getName(), null);
+        destinations.open();
+        timer = new Timer();
+        timer.schedule(new TimerTask() {
+
+            @Override
+            public void run() {
+                Destination dest = (Destination) destinations.getService();
+                System.out.println("  === timer expired");
+                if (dest != null) {
+                    System.out.println("   == calling");
+                    dest.receive(null);
+                }
+            }
+        }, 1000, 1000);
     }
 
     @Override
     public void stop(BundleContext aContext) throws Exception {
-        System.out.println("Stopping bundle");
+        System.out.println("=== Stopping bundle");
+        timer.cancel();
+        destinations.close();
     }
 
 }