FELIX-3903 - migrate whiteboard handler test to pax exam 3
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1454063 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/handler/whiteboard/whiteboard-handler-it/pom.xml b/ipojo/handler/whiteboard/whiteboard-handler-it/pom.xml
new file mode 100644
index 0000000..8bed968
--- /dev/null
+++ b/ipojo/handler/whiteboard/whiteboard-handler-it/pom.xml
@@ -0,0 +1,362 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>felix-parent</artifactId>
+ <version>1.2.1</version>
+ <relativePath>../../../../pom/pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>pom</packaging>
+ <name>Apache Felix iPOJO Whiteboard Handler - Integration Test</name>
+ <artifactId>org.apache.felix.ipojo.handler.whiteboard-it</artifactId>
+ <version>1.6.1-SNAPSHOT</version>
+
+ <properties>
+ <exam.version>3.0.0</exam.version>
+ <url.version>1.5.1</url.version>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.handler.whiteboard</artifactId>
+ <version>${project.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ <version>4.2.0</version>
+ <scope>test</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo</artifactId>
+ <version>1.8.6</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-native</artifactId>
+ <version>${exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit4</artifactId>
+ <version>${exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-link-mvn</artifactId>
+ <version>${exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.url</groupId>
+ <artifactId>pax-url-aether</artifactId>
+ <version>${url.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <version>0.9.20</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>0.9.20</version>
+ <scope>test</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.ops4j.pax.tinybundles</groupId>
+ <artifactId>tinybundles</artifactId>
+ <version>1.0.0</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ow2.chameleon.testing</groupId>
+ <artifactId>osgi-helpers</artifactId>
+ <version>0.6.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ow2.chameleon.testing</groupId>
+ <artifactId>tinybundles-ipojo</artifactId>
+ <version>0.3.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.9</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.url</groupId>
+ <artifactId>pax-url-wrap</artifactId>
+ <version>1.5.2</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.servicemix.tooling</groupId>
+ <artifactId>depends-maven-plugin</artifactId>
+ <version>1.2</version>
+ <executions>
+ <execution>
+ <id>generate-config</id>
+ <goals>
+ <goal>generate-depends-file</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.5.1</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>test</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <version>1.8</version>
+ <configuration>
+ <streamLogs>true</streamLogs>
+ <goals>
+ <goal>clean</goal>
+ <goal>test</goal>
+ </goals>
+ <cloneClean>true</cloneClean>
+ </configuration>
+ <executions>
+ <execution>
+ <id>regular</id>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <profiles>
+ <profile>felix</profile>
+ </profiles>
+ <cloneProjectsTo>${project.build.directory}/regular</cloneProjectsTo>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <profile>
+ <id>test-all</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <version>1.8</version>
+ <configuration>
+ <streamLogs>true</streamLogs>
+ <goals>
+ <goal>clean</goal>
+ <goal>test</goal>
+ </goals>
+ <cloneClean>true</cloneClean>
+ </configuration>
+ <executions>
+ <execution>
+ <id>equinox-native</id>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <profiles>
+ <profile>equinox</profile>
+ </profiles>
+ <cloneProjectsTo>${project.build.directory}/equinox-native</cloneProjectsTo>
+
+ </configuration>
+ </execution>
+ <execution>
+ <id>felix-native</id>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <profiles>
+ <profile>felix</profile>
+ </profiles>
+ <cloneProjectsTo>${project.build.directory}/felix-native</cloneProjectsTo>
+ </configuration>
+ </execution>
+ <execution>
+ <id>knopflerfish-native</id>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <profiles>
+ <profile>knopflerfish</profile>
+ </profiles>
+ <cloneProjectsTo>${project.build.directory}/knopflerfish-native</cloneProjectsTo>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <profile>
+ <id>knopflerfish</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ <property>
+ <name>pax.exam.framework</name>
+ <value>knopflerfish</value>
+ </property>
+ </activation>
+ <properties>
+ <pax.exam.framework>knopflerfish</pax.exam.framework>
+ </properties>
+ <repositories>
+ <repository>
+ <id>knopflerfish-releases</id>
+ <url>http://www.knopflerfish.org/maven2</url>
+ </repository>
+ </repositories>
+ <dependencies>
+ <dependency>
+ <groupId>org.knopflerfish</groupId>
+ <artifactId>framework</artifactId>
+ <version>5.2.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+
+ <profile>
+ <id>equinox</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ <property>
+ <name>pax.exam.framework</name>
+ <value>equinox</value>
+ </property>
+ </activation>
+ <properties>
+ <pax.exam.framework>equinox</pax.exam.framework>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>org.eclipse.osgi</artifactId>
+ <version>3.8.1.v20120830-144521</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+
+ <profile>
+ <id>felix</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ <property>
+ <name>pax.exam.framework</name>
+ <value>felix</value>
+ </property>
+ </activation>
+ <properties>
+ <pax.exam.framework>felix</pax.exam.framework>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ <version>4.2.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+
+ </profiles>
+</project>
diff --git a/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/pom.xml b/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/pom.xml
new file mode 100644
index 0000000..d1bfcef
--- /dev/null
+++ b/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/pom.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.handler.whiteboard-it</artifactId>
+ <version>1.6.1-SNAPSHOT</version>
+ <relativePath>../../../pom.xml</relativePath>
+ </parent>
+
+
+ <artifactId>ipojo-whiteboard-integration-test</artifactId>
+ <name>${project.artifactId}</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>4.2.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.annotations</artifactId>
+ <version>1.8.6</version>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/main/java/org/apache/felix/ipojo/handler/whiteboard/components/FooProvider.java b/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/main/java/org/apache/felix/ipojo/handler/whiteboard/components/FooProvider.java
new file mode 100644
index 0000000..5fc011b
--- /dev/null
+++ b/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/main/java/org/apache/felix/ipojo/handler/whiteboard/components/FooProvider.java
@@ -0,0 +1,17 @@
+package org.apache.felix.ipojo.handler.whiteboard.components;
+
+import org.apache.felix.ipojo.handler.whiteboard.services.FooService;
+
+public class FooProvider implements FooService {
+
+ public String foo;
+
+ public void foo() {
+ if (foo.equals("foo")) {
+ foo = "bar";
+ } else {
+ foo = "foo";
+ }
+ }
+
+}
diff --git a/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/main/java/org/apache/felix/ipojo/handler/whiteboard/components/FooWhiteBoardPattern.java b/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/main/java/org/apache/felix/ipojo/handler/whiteboard/components/FooWhiteBoardPattern.java
new file mode 100644
index 0000000..95092ed
--- /dev/null
+++ b/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/main/java/org/apache/felix/ipojo/handler/whiteboard/components/FooWhiteBoardPattern.java
@@ -0,0 +1,75 @@
+package org.apache.felix.ipojo.handler.whiteboard.components;
+
+import org.apache.felix.ipojo.handler.whiteboard.services.Observable;
+import org.osgi.framework.ServiceReference;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class FooWhiteBoardPattern implements Observable {
+
+ List list = new ArrayList();
+ int modifications = 0;
+
+ long validate_time = 0;
+ long first_arrival_time = 0;
+ long first_departure_time = 0;
+ long invalidate_time = 0;
+
+ public void onArrival(ServiceReference ref) {
+ if (first_arrival_time == 0) {
+ first_arrival_time = System.currentTimeMillis();
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) { }
+ }
+ list.add(ref);
+ }
+
+ public void onDeparture(ServiceReference ref) {
+ list.remove(ref);
+ if (first_departure_time == 0) {
+ first_departure_time = System.currentTimeMillis();
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) { }
+ }
+ }
+
+ public void onModification(ServiceReference ref) {
+ modifications = modifications + 1;
+ }
+
+ public Map getObservations() {
+ Map map = new HashMap();
+ map.put("list", list);
+ map.put("modifications", new Integer(modifications));
+ map.put("validate", new Long(validate_time));
+ map.put("invalidate", new Long(invalidate_time));
+ map.put("arrival", new Long(first_arrival_time));
+ map.put("departure", new Long(first_departure_time));
+ return map;
+ }
+
+ public void start() {
+ if (validate_time == 0) {
+ validate_time = System.currentTimeMillis();
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) { }
+ }
+ }
+
+ public void stop() {
+ if (invalidate_time == 0) {
+ invalidate_time = System.currentTimeMillis();
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) { }
+ }
+ }
+
+
+}
diff --git a/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/main/java/org/apache/felix/ipojo/handler/whiteboard/services/FooService.java b/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/main/java/org/apache/felix/ipojo/handler/whiteboard/services/FooService.java
new file mode 100644
index 0000000..c016a2f
--- /dev/null
+++ b/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/main/java/org/apache/felix/ipojo/handler/whiteboard/services/FooService.java
@@ -0,0 +1,7 @@
+package org.apache.felix.ipojo.handler.whiteboard.services;
+
+public interface FooService {
+
+ public void foo();
+
+}
diff --git a/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/main/java/org/apache/felix/ipojo/handler/whiteboard/services/Observable.java b/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/main/java/org/apache/felix/ipojo/handler/whiteboard/services/Observable.java
new file mode 100644
index 0000000..94e9a84
--- /dev/null
+++ b/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/main/java/org/apache/felix/ipojo/handler/whiteboard/services/Observable.java
@@ -0,0 +1,9 @@
+package org.apache.felix.ipojo.handler.whiteboard.services;
+
+import java.util.Map;
+
+public interface Observable {
+
+ public Map getObservations();
+
+}
diff --git a/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/main/resources/metadata.xml b/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/main/resources/metadata.xml
new file mode 100644
index 0000000..a3b227e
--- /dev/null
+++ b/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/main/resources/metadata.xml
@@ -0,0 +1,46 @@
+<ipojo
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/SNAPSHOT/core.xsd"
+ xmlns="org.apache.felix.ipojo"
+ xmlns:wbp="org.apache.felix.ipojo.whiteboard">
+ <component classname="org.apache.felix.ipojo.handler.whiteboard.components.FooProvider" name="fooprovider">
+ <provides>
+ <property field="foo" value="foo"/>
+ </provides>
+ </component>
+
+ <component classname="org.apache.felix.ipojo.handler.whiteboard.components.FooWhiteBoardPattern" name="under-providers">
+ <wbp:wbp
+ filter="(objectclass=org.apache.felix.ipojo.handler.whiteboard.services.FooService)"
+ onArrival="onArrival" onDeparture="onDeparture" onModification="onModification"
+ />
+ <provides/>
+ </component>
+
+ <component classname="org.apache.felix.ipojo.handler.whiteboard.components.FooWhiteBoardPattern" name="under-properties">
+ <wbp:wbp filter="(foo=foo)" onArrival="onArrival" onDeparture="onDeparture"
+ onModification="onModification"
+ />
+ <provides/>
+ </component>
+
+ <component classname="org.apache.felix.ipojo.handler.whiteboard.components.FooWhiteBoardPattern" name="under-providers-2">
+ <wbp:whiteboards>
+ <wbp:wbp
+ filter="(objectclass=org.apache.felix.ipojo.handler.whiteboard.services.FooService)"
+ onArrival="onArrival" onDeparture="onDeparture" onModification="onModification"
+ />
+ </wbp:whiteboards>
+ <provides/>
+ </component>
+
+ <component classname="org.apache.felix.ipojo.handler.whiteboard.components.FooWhiteBoardPattern" name="under-providers-lifecycle">
+ <wbp:wbp
+ filter="(objectclass=org.apache.felix.ipojo.handler.whiteboard.services.FooService)"
+ onArrival="onArrival" onDeparture="onDeparture" onModification="onModification"
+ />
+ <provides/>
+ <callback transition="validate" method="start"/>
+ <callback transition="invalidate" method="stop"/>
+ </component>
+</ipojo>
\ No newline at end of file
diff --git a/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/test/java/org/apache/felix/ipojo/handler/whiteboard/test/Common.java b/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/test/java/org/apache/felix/ipojo/handler/whiteboard/test/Common.java
new file mode 100644
index 0000000..1dd0898
--- /dev/null
+++ b/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/test/java/org/apache/felix/ipojo/handler/whiteboard/test/Common.java
@@ -0,0 +1,197 @@
+package org.apache.felix.ipojo.handler.whiteboard.test;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.TrueFileFilter;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.options.CompositeOption;
+import org.ops4j.pax.exam.options.DefaultCompositeOption;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.tinybundles.core.TinyBundle;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.ow2.chameleon.testing.helpers.IPOJOHelper;
+import org.ow2.chameleon.testing.helpers.OSGiHelper;
+import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import static junit.framework.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.*;
+
+/**
+ * Bootstrap the test from this project
+ */
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class Common {
+
+ @Inject
+ BundleContext bc;
+
+ OSGiHelper osgiHelper;
+ IPOJOHelper ipojoHelper;
+
+ Bundle testedBundle;
+
+ @Configuration
+ public Option[] config() throws IOException {
+ Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+ root.setLevel(Level.DEBUG);
+
+ return options(
+ cleanCaches(),
+ ipojoBundles(),
+ junitBundles(),
+ testedBundle(),
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
+ );
+ }
+
+ public static Option junitAndMockitoBundles() {
+ return new DefaultCompositeOption(
+ // Repository required to load harmcrest (OSGi-fied version).
+ repository("http://repository.springsource.com/maven/bundles/external").id(
+ "com.springsource.repository.bundles.external"),
+
+ // Hamcrest with a version matching the range expected by Mockito
+ mavenBundle("org.hamcrest", "com.springsource.org.hamcrest.core", "1.1.0"),
+
+ // Mockito core does not includes Hamcrest
+ mavenBundle("org.mockito", "mockito-core", "1.9.5"),
+
+ // Objenesis with a version matching the range expected by Mockito
+ wrappedBundle(mavenBundle("org.objenesis", "objenesis", "1.2"))
+ .exports("*;version=1.2"),
+
+ // The default JUnit bundle also exports Hamcrest, but with an (incorrect) version of
+ // 4.9 which does not match the Mockito import. When deployed after the hamcrest bundles, it gets
+ // resolved correctly.
+ CoreOptions.junitBundles(),
+
+ /*
+ * Felix has implicit boot delegation enabled by default. It conflicts with Mockito:
+ * java.lang.LinkageError: loader constraint violation in interface itable initialization:
+ * when resolving method "org.osgi.service.useradmin.User$$EnhancerByMockitoWithCGLIB$$dd2f81dc
+ * .newInstance(Lorg/mockito/cglib/proxy/Callback;)Ljava/lang/Object;" the class loader
+ * (instance of org/mockito/internal/creation/jmock/SearchingClassLoader) of the current class,
+ * org/osgi/service/useradmin/User$$EnhancerByMockitoWithCGLIB$$dd2f81dc, and the class loader
+ * (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for interface
+ * org/mockito/cglib/proxy/Factory have different Class objects for the type org/mockito/cglib/
+ * proxy/Callback used in the signature
+ *
+ * So we disable the bootdelegation. this property has no effect on the other OSGi implementation.
+ */
+ frameworkProperty("felix.bootdelegation.implicit").value("false")
+ );
+ }
+
+ @Before
+ public void commonSetUp() {
+ osgiHelper = new OSGiHelper(bc);
+ ipojoHelper = new IPOJOHelper(bc);
+
+ testedBundle = osgiHelper.getBundle("test.bundle");
+
+ // Dump OSGi Framework information
+ String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
+ if (vendor == null) {
+ vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
+ }
+ String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
+ System.out.println("OSGi Framework : " + vendor + " - " + version);
+ }
+
+ @After
+ public void commonTearDown() {
+ ipojoHelper.dispose();
+ osgiHelper.dispose();
+ }
+
+ public static CompositeOption ipojoBundles() {
+ return new DefaultCompositeOption(
+ mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
+ mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject(),
+ // The tested handler
+ mavenBundle("org.apache.felix", "org.apache.felix.ipojo.handler.whiteboard").versionAsInProject()
+ );
+ }
+
+ public Option testedBundle() throws MalformedURLException {
+ File out = new File("target/tested/bundle.jar");
+
+ TinyBundle tested = TinyBundles.bundle();
+
+ // We look inside target/classes to find the class and resources
+ File classes = new File("target/classes");
+ Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
+ List<File> services = new ArrayList<File>();
+ for (File file : files) {
+ if (file.isDirectory()) {
+ // By convention we export of .services and .service package
+ if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
+ services.add(file);
+ }
+ } else {
+ // We need to compute the path
+ String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
+ tested.add(path, file.toURI().toURL());
+ System.out.println(file.getName() + " added to " + path);
+ }
+ }
+
+ String export = "";
+ for (File file : services) {
+ if (export.length() > 0) { export += ", "; }
+ String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
+ String packageName = path.replace('/', '.');
+ export += packageName;
+ }
+
+ System.out.println("Exported packages : " + export);
+
+ InputStream inputStream = tested
+ .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
+ //.set(Constants.IMPORT_PACKAGE, "*")
+ .set(Constants.EXPORT_PACKAGE, export)
+ .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
+
+ try {
+ FileUtils.copyInputStreamToFile(inputStream, out);
+ return bundle(out.toURI().toURL().toExternalForm());
+ } catch (MalformedURLException e) {
+ throw new RuntimeException("Cannot compute the url of the manipulated bundle");
+ } catch (IOException e) {
+ throw new RuntimeException("Cannot write of the manipulated bundle");
+ }
+ }
+
+ public void assertContains(String s, String[] arrays, String object) {
+ for (String suspect : arrays) {
+ if (object.equals(suspect)) {
+ return;
+ }
+ }
+ fail("Assertion failed : " + s);
+ }
+
+
+}
diff --git a/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/test/java/org/apache/felix/ipojo/handler/whiteboard/test/TestWhiteboardPatternHandler.java b/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/test/java/org/apache/felix/ipojo/handler/whiteboard/test/TestWhiteboardPatternHandler.java
new file mode 100644
index 0000000..b8fa7f9
--- /dev/null
+++ b/ipojo/handler/whiteboard/whiteboard-handler-it/src/it/whiteboard-it/src/test/java/org/apache/felix/ipojo/handler/whiteboard/test/TestWhiteboardPatternHandler.java
@@ -0,0 +1,283 @@
+package org.apache.felix.ipojo.handler.whiteboard.test;
+
+import org.apache.felix.ipojo.*;
+import org.apache.felix.ipojo.handler.whiteboard.services.FooService;
+import org.apache.felix.ipojo.handler.whiteboard.services.Observable;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestWhiteboardPatternHandler extends Common {
+
+ Factory provFactory;
+ Factory factory, factory2, factory3, factory4;
+
+ @Before
+ public void setUp() {
+ provFactory = ipojoHelper.getFactory("fooprovider");
+ factory = ipojoHelper.getFactory("under-providers");
+ factory2 = ipojoHelper.getFactory("under-properties");
+ factory3 = ipojoHelper.getFactory("under-providers-lifecycle");
+ factory4 = ipojoHelper.getFactory("under-providers-2");
+ }
+
+ @Test
+ public void testServiceProviders() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
+ ComponentInstance ci = factory.createComponentInstance(new Properties());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(Observable.class.getName(), ci.getInstanceName());
+ assertNotNull("Check Observable availability", ref);
+ Observable obs = (Observable) osgiHelper.getServiceObject(ref);
+
+ Map map = obs.getObservations();
+ assertEquals("Check empty list", ((List) map.get("list")).size(), 0);
+
+ Properties p1 = new Properties();
+ p1.put("foo", "foo");
+ ComponentInstance prov1 = provFactory.createComponentInstance(p1);
+
+ map = obs.getObservations();
+ assertEquals("Check list #1", ((List) map.get("list")).size(), 1);
+
+ Properties p2 = new Properties();
+ p2.put("foo", "foo");
+ ComponentInstance prov2 = provFactory.createComponentInstance(p2);
+
+ map = obs.getObservations();
+ assertEquals("Check list #2", ((List) map.get("list")).size(), 2);
+
+ prov1.stop();
+
+ map = obs.getObservations();
+ assertEquals("(1) Check list #1", ((List) map.get("list")).size(), 1);
+
+ prov2.stop();
+
+ map = obs.getObservations();
+ assertEquals("(2) Check list #0", ((List) map.get("list")).size(), 0);
+
+ prov2.start();
+
+ map = obs.getObservations();
+ assertEquals("(3) Check list #1", ((List) map.get("list")).size(), 1);
+
+ prov1.start();
+
+ map = obs.getObservations();
+ assertEquals("(4) Check list #2", ((List) map.get("list")).size(), 2);
+
+ prov1.dispose();
+
+ map = obs.getObservations();
+ assertEquals("(5) Check list #1", ((List) map.get("list")).size(), 1);
+
+ prov2.dispose();
+
+ map = obs.getObservations();
+ assertEquals("(6) Check list #0", ((List) map.get("list")).size(), 0);
+
+ bc.ungetService(ref);
+ ci.dispose();
+ }
+
+ @Test
+ public void testPropertiesProviders() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
+ ComponentInstance ci = factory2.createComponentInstance(new Properties());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(Observable.class.getName(), ci.getInstanceName());
+ assertNotNull("Check Observable availability", ref);
+ Observable obs = (Observable) osgiHelper.getServiceObject(ref);
+
+ Map map = obs.getObservations();
+ assertEquals("Check empty list", ((List) map.get("list")).size(), 0);
+
+ Properties p1 = new Properties();
+ p1.put("foo", "foo");
+ ComponentInstance prov1 = provFactory.createComponentInstance(p1);
+ ServiceReference ref1 = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov1.getInstanceName());
+ FooService fs1 = (FooService) osgiHelper.getServiceObject(ref1);
+
+ map = obs.getObservations();
+ assertEquals("Check list #1", ((List) map.get("list")).size(), 1);
+
+ Properties p2 = new Properties();
+ p2.put("foo", "foo");
+ ComponentInstance prov2 = provFactory.createComponentInstance(p2);
+ ServiceReference ref2 = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov2.getInstanceName());
+ FooService fs2 = (FooService) osgiHelper.getServiceObject(ref2);
+
+ map = obs.getObservations();
+ assertEquals("Check list #2", ((List) map.get("list")).size(), 2);
+
+ fs1.foo();
+
+ map = obs.getObservations();
+ assertEquals("(1) Check list #1", ((List) map.get("list")).size(), 1);
+
+ fs2.foo();
+
+ map = obs.getObservations();
+ assertEquals("(2) Check list #0", ((List) map.get("list")).size(), 0);
+
+ fs2.foo();
+
+ map = obs.getObservations();
+ assertEquals("(3) Check list #1", ((List) map.get("list")).size(), 1);
+
+ fs1.foo();
+
+ map = obs.getObservations();
+ assertEquals("(4) Check list #2", ((List) map.get("list")).size(), 2);
+
+ prov1.dispose();
+
+ map = obs.getObservations();
+ assertEquals("(5) Check list #1", ((List) map.get("list")).size(), 1);
+
+ prov2.dispose();
+
+ map = obs.getObservations();
+ assertEquals("(6) Check list #0", ((List) map.get("list")).size(), 0);
+
+ bc.ungetService(ref1);
+ bc.ungetService(ref2);
+ bc.ungetService(ref);
+ ci.dispose();
+ }
+
+ @Test
+ public void testModifications() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
+ ComponentInstance ci = factory.createComponentInstance(new Properties());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(Observable.class.getName(), ci.getInstanceName());
+ assertNotNull("Check Observable availability", ref);
+ Observable obs = (Observable) osgiHelper.getServiceObject(ref);
+
+ Map map = obs.getObservations();
+ assertEquals("Check empty list", ((List) map.get("list")).size(), 0);
+
+ Properties p1 = new Properties();
+ p1.put("foo", "foo");
+ ComponentInstance prov1 = provFactory.createComponentInstance(p1);
+
+ map = obs.getObservations();
+ assertEquals("Check list #1", ((List) map.get("list")).size(), 1);
+ assertEquals("Check modification #0", ((Integer) map.get("modifications")).intValue(), 0);
+
+ ServiceReference ref2 = osgiHelper.getServiceReference(FooService.class.getName(), null);
+ assertNotNull("Check FooService availability", ref2);
+
+ FooService fs = (FooService) osgiHelper.getServiceObject(ref2);
+ fs.foo();
+
+ map = obs.getObservations();
+ assertEquals("Check list #1", ((List) map.get("list")).size(), 1);
+ assertEquals("Check modification #1 (" + map.get("modifications") + ")", ((Integer) map.get("modifications")).intValue(), 1);
+
+ fs.foo();
+
+ map = obs.getObservations();
+ assertEquals("Check list #1", ((List) map.get("list")).size(), 1);
+ assertEquals("Check modification #2", ((Integer) map.get("modifications")).intValue(), 2);
+
+ prov1.dispose();
+ map = obs.getObservations();
+ assertEquals("Check list #0", ((List) map.get("list")).size(), 0);
+ assertEquals("Check modification #2", ((Integer) map.get("modifications")).intValue(), 2);
+
+ bc.ungetService(ref);
+ bc.ungetService(ref2);
+ ci.dispose();
+ }
+
+ @Test
+ public void testLifecycleCompliance() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
+ // First expose a service.
+ Properties p1 = new Properties();
+ p1.put("foo", "foo");
+ ComponentInstance prov1 = provFactory.createComponentInstance(p1);
+
+ ComponentInstance ci = factory3.createComponentInstance(new Properties());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(Observable.class.getName(), ci.getInstanceName());
+ assertNotNull("Check Observable availability", ref);
+ Observable obs = (Observable) osgiHelper.getServiceObject(ref);
+
+ Map map = obs.getObservations();
+ // Check time
+ Long validate = (Long) map.get("validate");
+ Long arrival = (Long) map.get("arrival");
+
+ // Validate must be call before.
+ assertTrue(validate + " <?> " + arrival, validate < arrival);
+
+ prov1.dispose();
+ ci.dispose();
+
+ }
+
+ @Test
+ public void testServiceProvidersWhiteWhiteboards() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
+ ComponentInstance ci = factory4.createComponentInstance(new Properties());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(Observable.class.getName(), ci.getInstanceName());
+ assertNotNull("Check Observable availability", ref);
+ Observable obs = (Observable) osgiHelper.getServiceObject(ref);
+
+ Map map = obs.getObservations();
+ assertEquals("Check empty list", ((List) map.get("list")).size(), 0);
+
+ Properties p1 = new Properties();
+ p1.put("foo", "foo");
+ ComponentInstance prov1 = provFactory.createComponentInstance(p1);
+
+ map = obs.getObservations();
+ assertEquals("Check list #1", ((List) map.get("list")).size(), 1);
+
+ Properties p2 = new Properties();
+ p2.put("foo", "foo");
+ ComponentInstance prov2 = provFactory.createComponentInstance(p2);
+
+ map = obs.getObservations();
+ assertEquals("Check list #2", ((List) map.get("list")).size(), 2);
+
+ prov1.stop();
+
+ map = obs.getObservations();
+ assertEquals("(1) Check list #1", ((List) map.get("list")).size(), 1);
+
+ prov2.stop();
+
+ map = obs.getObservations();
+ assertEquals("(2) Check list #0", ((List) map.get("list")).size(), 0);
+
+ prov2.start();
+
+ map = obs.getObservations();
+ assertEquals("(3) Check list #1", ((List) map.get("list")).size(), 1);
+
+ prov1.start();
+
+ map = obs.getObservations();
+ assertEquals("(4) Check list #2", ((List) map.get("list")).size(), 2);
+
+ prov1.dispose();
+
+ map = obs.getObservations();
+ assertEquals("(5) Check list #1", ((List) map.get("list")).size(), 1);
+
+ prov2.dispose();
+
+ map = obs.getObservations();
+ assertEquals("(6) Check list #0", ((List) map.get("list")).size(), 0);
+
+ bc.ungetService(ref);
+ ci.dispose();
+ }
+}