<?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>
<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>
*/
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 {
@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")
}
@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();
+ }
}
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
- <version>1.8.0</version>
+ <version>1.8.5</version>
<scope>test</scope>
</dependency>
*/
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();
}
}