FELIX-3903 - Migrate API test to pax exam 3

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1455541 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/api-it/pom.xml b/ipojo/runtime/api-it/pom.xml
new file mode 100644
index 0000000..af7748f
--- /dev/null
+++ b/ipojo/runtime/api-it/pom.xml
@@ -0,0 +1,468 @@
+<!--
+  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:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns="http://maven.apache.org/POM/4.0.0"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.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>
+    <artifactId>org.apache.felix.ipojo.runtime.api-it</artifactId>
+    <version>1.9.0-SNAPSHOT</version>
+    <name>Apache Felix iPOJO Runtime Project ~ API Integration Tests</name>
+    <packaging>pom</packaging>
+
+    <build>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+            </resource>
+            <resource>
+                <directory>.</directory>
+                <targetPath>META-INF</targetPath>
+                <includes>
+                    <include>LICENSE*</include>
+                    <include>NOTICE*</include>
+                    <include>DEPENDENCIES*</include>
+                </includes>
+            </resource>
+        </resources>
+
+        <plugins>
+            <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>
+
+            <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>
+        </plugins>
+
+    </build>
+
+    <properties>
+        <exam.version>3.1.0-SNAPSHOT</exam.version>
+        <url.version>1.5.1</url.version>
+    </properties>
+
+    <dependencies>
+
+        <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>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.framework</artifactId>
+            <version>4.2.0</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-core</artifactId>
+            <version>0.9.6</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <version>0.9.6</version>
+            <scope>test</scope>
+        </dependency>
+
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.9</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-all</artifactId>
+            <version>1.9.5</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.ops4j.pax.tinybundles</groupId>
+            <artifactId>tinybundles</artifactId>
+            <version>1.0.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.ipojo</artifactId>
+            <version>1.9.0-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.ipojo.api</artifactId>
+            <version>1.9.0-SNAPSHOT</version>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.ipojo.composite</artifactId>
+            <version>1.9.0-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.ipojo.manipulator</artifactId>
+            <version>1.9.0-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.configadmin</artifactId>
+            <version>1.6.0</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.ipojo.handler.whiteboard</artifactId>
+            <version>1.4.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>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.ow2.chameleon.testing</groupId>
+            <artifactId>tinybundles-ipojo</artifactId>
+            <version>0.3.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.ipojo.handler.eventadmin</artifactId>
+            <!--
+            We use the released version as we don't really have to do any behavioral test on the handler in the core
+            test.
+            -->
+            <version>1.8.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.log</artifactId>
+            <version>1.0.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.ops4j.pax.url</groupId>
+            <artifactId>pax-url-wrap</artifactId>
+            <version>1.5.2</version>
+        </dependency>
+    </dependencies>
+
+    <profiles>
+        <profile>
+            <id>release</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-assembly-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>make-assembly</id>
+                                <phase>package</phase>
+                                <goals>
+                                    <goal>single</goal>
+                                </goals>
+                                <configuration>
+                                    <descriptorRefs>
+                                        <descriptorRef>project</descriptorRef>
+                                    </descriptorRefs>
+                                    <!-- we don't want to attach all the assemblies, such as bz2 -->
+                                    <attach>false</attach>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <!-- only attach the project and bin assemblies, in tar.gz and zip flavors -->
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>build-helper-maven-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>attach-assemblies</id>
+                                <phase>package</phase>
+                                <goals>
+                                    <goal>attach-artifact</goal>
+                                </goals>
+                                <configuration>
+                                    <artifacts>
+                                        <artifact>
+                                            <file>
+                                                ${project.build.directory}/${project.artifactId}-${project.version}-project.tar.gz
+                                            </file>
+                                            <classifier>project</classifier>
+                                            <type>tar.gz</type>
+                                        </artifact>
+                                        <artifact>
+                                            <file>
+                                                ${project.build.directory}/${project.artifactId}-${project.version}-project.zip
+                                            </file>
+                                            <classifier>project</classifier>
+                                            <type>zip</type>
+                                        </artifact>
+                                    </artifacts>
+                                </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>
+
+        <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>
+    </profiles>
+</project>
diff --git a/ipojo/runtime/api-it/src/it/ipojo-api-test/pom.xml b/ipojo/runtime/api-it/src/it/ipojo-api-test/pom.xml
new file mode 100644
index 0000000..ae55600
--- /dev/null
+++ b/ipojo/runtime/api-it/src/it/ipojo-api-test/pom.xml
@@ -0,0 +1,20 @@
+<?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">
+
+    <parent>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>org.apache.felix.ipojo.runtime.api-it</artifactId>
+        <version>1.9.0-SNAPSHOT</version>
+        <relativePath>../../../pom.xml</relativePath>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.apache.felix</groupId>
+    <artifactId>ipojo-api-test</artifactId>
+
+    <name>${project.artifactId}</name>
+    
+</project>
\ No newline at end of file
diff --git a/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/components/FooImpl.java b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/components/FooImpl.java
new file mode 100644
index 0000000..1a04e64
--- /dev/null
+++ b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/components/FooImpl.java
@@ -0,0 +1,22 @@
+package org.apache.felix.ipojo.runtime.core.api.components;
+
+import org.apache.felix.ipojo.runtime.core.api.services.Foo;
+
+public class FooImpl implements Foo {
+    
+   // private List<String> m_list = new ArrayList<String>();
+
+    public void doSomething() {
+       // Do something...
+        System.out.println("Hello World !");
+    }
+    
+    public FooImpl(String s) {
+        _setIM(s);
+    }
+    
+    public void _setIM(String s) {
+        
+    }
+
+}
diff --git a/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/components/HostImpl.java b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/components/HostImpl.java
new file mode 100644
index 0000000..ea92fc3
--- /dev/null
+++ b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/components/HostImpl.java
@@ -0,0 +1,19 @@
+package org.apache.felix.ipojo.runtime.core.api.components;
+
+import org.osgi.framework.ServiceReference;
+
+public class HostImpl {
+    
+    public void arrival(ServiceReference ref) {
+        
+    }
+    
+    public void departure(ServiceReference ref) {
+        
+    }
+    
+    public void modification(ServiceReference ref) {
+        
+    }
+
+}
diff --git a/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/components/MyComponentImpl.java b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/components/MyComponentImpl.java
new file mode 100644
index 0000000..8c58fe3
--- /dev/null
+++ b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/components/MyComponentImpl.java
@@ -0,0 +1,31 @@
+package org.apache.felix.ipojo.runtime.core.api.components;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.runtime.core.api.services.Foo;
+
+/**
+ * This class is marked as a component to be manipulated.
+ */
+@Component(name="do-not-use-this-factory", public_factory = false)
+public class MyComponentImpl {
+    
+    private Foo myFoo;
+    
+    private int anInt;
+    
+    public MyComponentImpl() {
+        anInt = 2;
+    }
+    
+    public MyComponentImpl(int i) {
+        anInt = i;
+    }
+
+    public void start() {
+       myFoo.doSomething();
+       if (anInt > 0) {
+           System.out.println("Set int to " + anInt);
+       }
+    }
+
+}
diff --git a/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/components/MyServiceImpl.java b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/components/MyServiceImpl.java
new file mode 100644
index 0000000..d6176e9
--- /dev/null
+++ b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/components/MyServiceImpl.java
@@ -0,0 +1,9 @@
+package org.apache.felix.ipojo.runtime.core.api.components;

+

+import org.apache.felix.ipojo.runtime.core.api.services.MyService;

+

+public class MyServiceImpl implements MyService {

+    public double compute(double value) {

+	return Math.exp(value * Math.cosh(value));

+    }

+}

diff --git a/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/services/BarService.java b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/services/BarService.java
new file mode 100644
index 0000000..e42f3f3
--- /dev/null
+++ b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/services/BarService.java
@@ -0,0 +1,8 @@
+package org.apache.felix.ipojo.runtime.core.api.services;
+
+public interface BarService {
+    
+    public void doSomethingWithBar();
+    
+
+}
diff --git a/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/services/Foo.java b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/services/Foo.java
new file mode 100644
index 0000000..84c9127
--- /dev/null
+++ b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/services/Foo.java
@@ -0,0 +1,8 @@
+package org.apache.felix.ipojo.runtime.core.api.services;
+
+public interface Foo {
+    
+    
+    public void doSomething();
+
+}
diff --git a/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/services/MyService.java b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/services/MyService.java
new file mode 100644
index 0000000..b7372ae
--- /dev/null
+++ b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/main/java/org/apache/felix/ipojo/runtime/core/api/services/MyService.java
@@ -0,0 +1,5 @@
+package org.apache.felix.ipojo.runtime.core.api.services;

+

+public interface MyService {

+    double compute(double value);

+}

diff --git a/ipojo/runtime/api-it/src/it/ipojo-api-test/src/test/java/org/apache/felix/ipojo/runtime/core/api/Common.java b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/test/java/org/apache/felix/ipojo/runtime/core/api/Common.java
new file mode 100644
index 0000000..def3d91
--- /dev/null
+++ b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/test/java/org/apache/felix/ipojo/runtime/core/api/Common.java
@@ -0,0 +1,302 @@
+package org.apache.felix.ipojo.runtime.core.api;
+
+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.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.composite.CompositeManager;
+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.PerMethod;
+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.osgi.framework.ServiceReference;
+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(PerMethod.class)
+public class Common {
+
+    @Inject
+    protected
+    BundleContext bc;
+    protected OSGiHelper osgiHelper;
+    protected IPOJOHelper ipojoHelper;
+    protected boolean deployTestedBundle = true;
+
+    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"),
+
+                // Mockito without Hamcrest and Objenesis
+                mavenBundle("org.mockito", "mockito-core", "1.9.5"),
+
+                // Hamcrest with a version matching the range expected by Mockito
+                mavenBundle("org.hamcrest", "com.springsource.org.hamcrest.core", "1.1.0"),
+
+                // 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.
+                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.
+                 */
+                frameworkProperty("felix.bootdelegation.implicit").value("false")
+        );
+    }
+
+    public static ServiceContext getServiceContext(ComponentInstance ci) {
+        if (ci instanceof CompositeManager) {
+            return ((CompositeManager) ci).getServiceContext();
+        } else {
+            throw new RuntimeException("Cannot get the service context from a non composite instance");
+        }
+    }
+
+    @Configuration
+    public Option[] config() throws IOException {
+        Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+        root.setLevel(Level.INFO);
+
+        if (deployTestedBundle) {
+            return options(
+                    cleanCaches(),
+                    ipojoBundles(),
+                    junitBundles(),
+                    testedBundle(),
+                    systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
+            );
+        } else {
+            return options(
+                    cleanCaches(),
+                    ipojoBundles(),
+                    junitBundles(),
+                    systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
+            );
+        }
+    }
+
+    @Before
+    public void commonSetUp() {
+        osgiHelper = new OSGiHelper(bc);
+        ipojoHelper = new IPOJOHelper(bc);
+
+        // 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);
+
+        waitForStability(bc);
+    }
+
+    @After
+    public void commonTearDown() {
+        ipojoHelper.dispose();
+        osgiHelper.dispose();
+    }
+
+    public BundleContext getContext() {
+        return bc;
+    }
+
+    public CompositeOption ipojoBundles() {
+        return new DefaultCompositeOption(
+                mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
+                mavenBundle("org.apache.felix", "org.apache.felix.ipojo.composite").versionAsInProject(),
+                mavenBundle("org.apache.felix", "org.apache.felix.ipojo.api").versionAsInProject(),
+                mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject(),
+                // configuration admin
+                mavenBundle("org.apache.felix", "org.apache.felix.configadmin").versionAsInProject(),
+                // whiteboard pattern 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");
+        if (out.exists()) {
+            return bundle(out.toURI().toURL().toExternalForm());
+        }
+
+        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);
+            }
+        }
+
+        // Export the components and services
+        String export = "org.apache.felix.ipojo.runtime.core.api.components";
+        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 {
+            org.apache.commons.io.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);
+    }
+
+    /**
+     * Waits for stability:
+     * <ul>
+     * <li>all bundles are activated
+     * <li>service count is stable
+     * </ul>
+     * If the stability can't be reached after a specified time,
+     * the method throws a {@link IllegalStateException}.
+     *
+     * @param context the bundle context
+     * @throws IllegalStateException when the stability can't be reach after a several attempts.
+     */
+    private void waitForStability(BundleContext context) throws IllegalStateException {
+        // Wait for bundle initialization.
+        boolean bundleStability = getBundleStability(context);
+        int count = 0;
+        while (!bundleStability && count < 500) {
+            try {
+                Thread.sleep(5);
+            } catch (InterruptedException e) {
+                // Interrupted
+            }
+            count++;
+            bundleStability = getBundleStability(context);
+        }
+
+        if (count == 500) {
+            System.err.println("Bundle stability isn't reached after 500 tries");
+            throw new IllegalStateException("Cannot reach the bundle stability");
+        }
+
+        boolean serviceStability = false;
+        count = 0;
+        int count1 = 0;
+        int count2 = 0;
+        while (!serviceStability && count < 500) {
+            try {
+                ServiceReference[] refs = context.getServiceReferences((String) null, null);
+                count1 = refs.length;
+                Thread.sleep(500);
+                refs = context.getServiceReferences((String) null, null);
+                count2 = refs.length;
+                serviceStability = count1 == count2;
+            } catch (Exception e) {
+                System.err.println(e);
+                serviceStability = false;
+                // Nothing to do, while recheck the condition
+            }
+            count++;
+        }
+
+        if (count == 500) {
+            System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
+            throw new IllegalStateException("Cannot reach the service stability");
+        }
+    }
+
+    /**
+     * Are bundle stables.
+     *
+     * @param bc the bundle context
+     * @return <code>true</code> if every bundles are activated.
+     */
+    private boolean getBundleStability(BundleContext bc) {
+        boolean stability = true;
+        Bundle[] bundles = bc.getBundles();
+        for (int i = 0; i < bundles.length; i++) {
+            stability = stability && (bundles[i].getState() == Bundle.ACTIVE);
+        }
+        return stability;
+    }
+
+
+}
diff --git a/ipojo/runtime/api-it/src/it/ipojo-api-test/src/test/java/org/apache/felix/ipojo/runtime/core/api/CompositeTest.java b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/test/java/org/apache/felix/ipojo/runtime/core/api/CompositeTest.java
new file mode 100644
index 0000000..1a8f518
--- /dev/null
+++ b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/test/java/org/apache/felix/ipojo/runtime/core/api/CompositeTest.java
@@ -0,0 +1,228 @@
+package org.apache.felix.ipojo.runtime.core.api;
+
+import org.apache.felix.ipojo.*;
+import org.apache.felix.ipojo.api.Dependency;
+import org.apache.felix.ipojo.api.PrimitiveComponentType;
+import org.apache.felix.ipojo.api.Service;
+import org.apache.felix.ipojo.api.composite.*;
+import org.apache.felix.ipojo.runtime.core.api.components.FooImpl;
+import org.apache.felix.ipojo.runtime.core.api.components.MyComponentImpl;
+import org.apache.felix.ipojo.runtime.core.api.services.Foo;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.junit.Assert.assertThat;
+
+
+public class CompositeTest extends Common {
+
+    private BundleContext context;
+
+    @Before
+    public void setUp() {
+        context = getContext();
+    }
+
+    @Test
+    public void createACompositeWithcontainedInstance() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
+        // Define the component types
+        PrimitiveComponentType prov = createAProvider();
+        PrimitiveComponentType cons = createAConsumer();
+
+        CompositeComponentType type = new CompositeComponentType()
+                .setBundleContext(context)
+                .setComponentTypeName("comp1")
+                .addInstance(new Instance(prov.getFactory().getName()))
+                .addInstance(new Instance(cons.getFactory().getName()));
+
+        ComponentInstance ci = type.createInstance();
+
+        assertThat("ci is valid", ci.getState(), is(ComponentInstance.VALID));
+
+        // Stop cons
+        cons.stop();
+        assertThat("ci is invalid", ci.getState(), is(ComponentInstance.INVALID));
+
+        // Restart cons
+        cons.start();
+        assertThat("ci is valid - 2", ci.getState(), is(ComponentInstance.VALID));
+
+    }
+
+    @Test
+    public void createACompositeWithAnInstantiatedService() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
+        // Define the component types
+        PrimitiveComponentType prov = createAProvider();
+        prov.start();
+        PrimitiveComponentType cons = createAConsumer();
+
+        ServiceReference[] refs = osgiHelper.getServiceReferences(Factory.class.getName(),
+                "(component.providedServiceSpecifications=" + Foo.class.getName() + ")");
+        assertThat(refs.length, is(not(0)));
+
+        Factory factory = (Factory) osgiHelper.getServiceObject(refs[0]);
+        System.out.println(factory.getComponentDescription().getDescription());
+
+        CompositeComponentType type = new CompositeComponentType()
+                .setBundleContext(context)
+                .setComponentTypeName("comp2")
+                .addSubService(new InstantiatedService().setSpecification(Foo.class.getName()))
+                .addInstance(new Instance(cons.getFactory().getName()));
+
+        ComponentInstance ci = type.createInstance();
+
+        System.out.println(ci.getInstanceDescription().getDescription());
+
+        assertThat("ci is valid", ci.getState(), is(ComponentInstance.VALID));
+
+        // Stop prov
+        prov.stop();
+        assertThat("ci is invalid", ci.getState(), is(ComponentInstance.INVALID));
+
+        // Restart prov
+        prov.start();
+        assertThat("ci is valid - 2", ci.getState(), is(ComponentInstance.VALID));
+
+    }
+
+    @Test
+    public void createACompositeWithAnOptionalInstantiatedService() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
+        // Define the component types
+        PrimitiveComponentType prov = createAProvider();
+        prov.start();
+
+        CompositeComponentType type = new CompositeComponentType()
+                .setBundleContext(context)
+                .setComponentTypeName("comp3")
+                .addSubService(new InstantiatedService().setSpecification(Foo.class.getName()).setOptional(true));
+
+        ComponentInstance ci = type.createInstance();
+
+        assertThat("ci is valid", ci.getState(), is(ComponentInstance.VALID));
+
+        // Stop prov
+        prov.stop();
+        assertThat("ci is valid - 1", ci.getState(), is(ComponentInstance.VALID));
+
+        // Restart prov
+        prov.start();
+        assertThat("ci is valid - 2", ci.getState(), is(ComponentInstance.VALID));
+
+    }
+
+    @Test
+    public void createACompositeWithAnImportedService() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
+        // Define the component types
+        PrimitiveComponentType prov = createAProvider();
+        prov.createInstance();
+        PrimitiveComponentType cons = createAConsumer();
+
+        ServiceReference[] refs = osgiHelper.getServiceReferences(Factory.class.getName(),
+                "(component.providedServiceSpecifications=" + Foo.class.getName() + ")");
+        assertThat(refs.length, is(not(0)));
+
+        CompositeComponentType type = new CompositeComponentType()
+                .setBundleContext(context)
+                .setComponentTypeName("comp2")
+                .addSubService(new ImportedService().setSpecification(Foo.class.getName()))
+                .addInstance(new Instance(cons.getFactory().getName()));
+
+        ComponentInstance ci = type.createInstance();
+
+        System.out.println(ci.getInstanceDescription().getDescription());
+
+        assertThat("ci is valid", ci.getState(), is(ComponentInstance.VALID));
+
+        // Stop prov
+        prov.stop();
+        assertThat("ci is invalid", ci.getState(), is(ComponentInstance.INVALID));
+
+        // Restart prov
+        prov.start();
+        prov.createInstance();
+        assertThat("ci is valid - 2", ci.getState(), is(ComponentInstance.VALID));
+
+    }
+
+    @Test
+    public void createACompositeWithAnOptionalImportedService() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
+        // Define the component types
+        PrimitiveComponentType prov = createAProvider();
+        prov.createInstance();
+
+        CompositeComponentType type = new CompositeComponentType()
+                .setBundleContext(context)
+                .setComponentTypeName("comp3")
+                .addSubService(new ImportedService().setSpecification(Foo.class.getName()).setOptional(true));
+
+        ComponentInstance ci = type.createInstance();
+
+        assertThat("ci is valid", ci.getState(), is(ComponentInstance.VALID));
+
+        // Stop prov
+        prov.stop();
+        assertThat("ci is valid - 1", ci.getState(), is(ComponentInstance.VALID));
+
+        // Restart prov
+        prov.start();
+        prov.createInstance();
+        assertThat("ci is valid - 2", ci.getState(), is(ComponentInstance.VALID));
+
+    }
+
+    @Test
+    public void createACompositeWithExportingAService() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
+        // Define the component types
+        PrimitiveComponentType prov = createAProvider();
+        prov.start();
+        PrimitiveComponentType cons = createAConsumer();
+        ComponentInstance c = cons.createInstance();
+
+        CompositeComponentType type = new CompositeComponentType()
+                .setBundleContext(context)
+                .setComponentTypeName("compExport")
+                .addSubService(new InstantiatedService().setSpecification(Foo.class.getName()))
+                .addService(new ExportedService().setSpecification(Foo.class.getName()));
+
+        ComponentInstance ci = type.createInstance();
+
+        assertThat("ci is valid", ci.getState(), is(ComponentInstance.VALID));
+        assertThat("c is valid", c.getState(), is(ComponentInstance.VALID));
+
+
+        // Stop prov
+        prov.stop();
+        assertThat("ci is invalid", ci.getState(), is(ComponentInstance.INVALID));
+        assertThat("c is invalid", c.getState(), is(ComponentInstance.INVALID));
+
+
+        // Restart prov
+        prov.start();
+        assertThat("ci is valid - 2", ci.getState(), is(ComponentInstance.VALID));
+        assertThat("c is valid - 2", c.getState(), is(ComponentInstance.VALID));
+
+
+    }
+
+    private PrimitiveComponentType createAProvider() {
+        return new PrimitiveComponentType()
+                .setBundleContext(context)
+                .setClassName(FooImpl.class.getName())
+                .setPublic(true)
+                .addService(new Service()); // Provide the FooService
+    }
+
+    private PrimitiveComponentType createAConsumer() {
+        return new PrimitiveComponentType()
+                .setBundleContext(context)
+                .setClassName(MyComponentImpl.class.getName())
+                .addDependency(new Dependency().setField("myFoo"))
+                .setValidateMethod("start");
+    }
+
+
+}
diff --git a/ipojo/runtime/api-it/src/it/ipojo-api-test/src/test/java/org/apache/felix/ipojo/runtime/core/api/ExternalHandlerTest.java b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/test/java/org/apache/felix/ipojo/runtime/core/api/ExternalHandlerTest.java
new file mode 100644
index 0000000..202a247
--- /dev/null
+++ b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/test/java/org/apache/felix/ipojo/runtime/core/api/ExternalHandlerTest.java
@@ -0,0 +1,72 @@
+package org.apache.felix.ipojo.runtime.core.api;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.api.PrimitiveComponentType;
+import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.runtime.core.api.components.HostImpl;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+
+public class ExternalHandlerTest extends Common {
+
+
+    private BundleContext context;
+
+    @Before
+    public void setUp() {
+        context = getContext();
+    }
+
+    @Test
+    public void createAHost() throws Exception {
+        PrimitiveComponentType type = createAWhiteboardHost();
+        ComponentInstance ci = type.createInstance();
+        assertThat(ci.getState(), is(ComponentInstance.VALID));
+        HandlerDescription hd = ci.getInstanceDescription().getHandlerDescription(Whiteboard.NAMESPACE + ":" + Whiteboard.NAME);
+        assertThat(hd, is(notNullValue()));
+    }
+
+    @Test
+    public void createDoubleHost() throws Exception {
+        PrimitiveComponentType type = createASecondWhiteboardHost();
+        ComponentInstance ci = type.createInstance();
+        assertThat(ci.getState(), is(ComponentInstance.VALID));
+        HandlerDescription hd = ci.getInstanceDescription().getHandlerDescription(Whiteboard.NAMESPACE + ":" + Whiteboard.NAME);
+        assertThat(hd, is(notNullValue()));
+    }
+
+    private PrimitiveComponentType createAWhiteboardHost() {
+        return new PrimitiveComponentType()
+                .setBundleContext(context)
+                .setClassName(HostImpl.class.getName())
+                .addHandler(new Whiteboard()
+                        .onArrival("arrival")
+                        .onDeparture("departure")
+                        .setFilter("(foo=foo)")
+                );
+    }
+
+    private PrimitiveComponentType createASecondWhiteboardHost() {
+        return new PrimitiveComponentType()
+                .setBundleContext(context)
+                .setClassName(HostImpl.class.getName())
+                .addHandler(new Whiteboard()
+                        .onArrival("arrival")
+                        .onDeparture("departure")
+                        .setFilter("(foo=foo)")
+                )
+                .addHandler(new Whiteboard()
+                        .onArrival("arrival")
+                        .onDeparture("departure")
+                        .setFilter("(foo=bar)")
+                        .onModification("modification")
+                );
+    }
+
+}
diff --git a/ipojo/runtime/api-it/src/it/ipojo-api-test/src/test/java/org/apache/felix/ipojo/runtime/core/api/PrimitiveComponentTest.java b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/test/java/org/apache/felix/ipojo/runtime/core/api/PrimitiveComponentTest.java
new file mode 100644
index 0000000..a19606e
--- /dev/null
+++ b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/test/java/org/apache/felix/ipojo/runtime/core/api/PrimitiveComponentTest.java
@@ -0,0 +1,143 @@
+package org.apache.felix.ipojo.runtime.core.api;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.MissingHandlerException;
+import org.apache.felix.ipojo.UnacceptableConfiguration;
+import org.apache.felix.ipojo.api.Dependency;
+import org.apache.felix.ipojo.api.PrimitiveComponentType;
+import org.apache.felix.ipojo.api.Service;
+import org.apache.felix.ipojo.api.SingletonComponentType;
+import org.apache.felix.ipojo.runtime.core.api.components.FooImpl;
+import org.apache.felix.ipojo.runtime.core.api.components.MyComponentImpl;
+import org.apache.felix.ipojo.runtime.core.api.services.Foo;
+import org.junit.Before;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import java.io.IOException;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.assertThat;
+
+
+public class PrimitiveComponentTest extends Common {
+
+    private BundleContext context;
+
+    @Before
+    public void setUp() {
+        context = getContext();
+    }
+
+    @Configuration
+    public Option[] config() throws IOException {
+        return super.config();
+    }
+
+    @Test
+    public void createAServiceProvider() throws Exception {
+        assertThat(context, is(notNullValue()));
+        ComponentInstance ci;
+
+        PrimitiveComponentType type = createAProvider();
+        ci = type.createInstance();
+        assertThat("Ci is valid", ci.getState(), is(ComponentInstance.VALID));
+        ServiceReference ref = ipojoHelper.getServiceReferenceByName(Foo.class
+                .getName(), ci.getInstanceName());
+        assertThat(ref, is(notNullValue()));
+
+    }
+
+    @Test
+    public void killTheFactory() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
+        assertThat(context, is(notNullValue()));
+        ComponentInstance ci = null;
+
+        PrimitiveComponentType type = createAProvider();
+        ci = type.createInstance();
+        assertThat("Ci is valid", ci.getState(), is(ComponentInstance.VALID));
+        ServiceReference ref = ipojoHelper.getServiceReferenceByName(Foo.class
+                .getName(), ci.getInstanceName());
+        assertThat(ref, is(notNullValue()));
+        type.stop();
+        assertThat("Ci is disposed", ci.getState(),
+                is(ComponentInstance.DISPOSED));
+        ref = ipojoHelper.getServiceReferenceByName(Foo.class.getName(), ci
+                .getInstanceName());
+        assertThat(ref, is(nullValue()));
+
+    }
+
+    @Test
+    public void createAServiceCons() throws Exception {
+        assertThat(context, is(notNullValue()));
+        ComponentInstance ci = null;
+
+        PrimitiveComponentType type = createAConsumer();
+        ci = type.createInstance();
+        assertThat("Ci is invalid", ci.getState(),
+                is(ComponentInstance.INVALID));
+
+    }
+
+    @Test
+    public void createBoth() throws Exception {
+        ComponentInstance cons = createAConsumer().createInstance();
+        // cons is invalid
+        assertThat("cons is invalid", cons.getState(), is(ComponentInstance.INVALID));
+
+        ComponentInstance prov = createAProvider().createInstance();
+        assertThat("prov is valid", prov.getState(), is(ComponentInstance.VALID));
+        assertThat("cons is valid", cons.getState(), is(ComponentInstance.VALID));
+
+    }
+
+    @Test
+    public void createTwoCons() throws Exception {
+        ComponentInstance cons1 = createAConsumer().createInstance();
+        // cons is invalid
+        assertThat("cons is invalid", cons1.getState(), is(ComponentInstance.INVALID));
+
+        ComponentInstance prov = createAProvider().createInstance();
+        assertThat("prov is valid", prov.getState(), is(ComponentInstance.VALID));
+        assertThat("cons is valid", cons1.getState(), is(ComponentInstance.VALID));
+
+        ComponentInstance cons2 = createAnOptionalConsumer().createInstance();
+
+        assertThat("cons2 is valid", cons2.getState(), is(ComponentInstance.VALID));
+
+        prov.stop();
+        assertThat("cons is invalid", cons1.getState(), is(ComponentInstance.INVALID));
+        assertThat("cons2 is valid", cons2.getState(), is(ComponentInstance.VALID));
+    }
+
+    private PrimitiveComponentType createAProvider() {
+        return new PrimitiveComponentType()
+                .setBundleContext(context)
+                .setClassName(FooImpl.class.getName())
+                .addService(new Service()); // Provide the FooService
+    }
+
+    private PrimitiveComponentType createAConsumer() {
+        return new SingletonComponentType()
+                .setBundleContext(context)
+                .setClassName(MyComponentImpl.class.getName())
+                .addDependency(new Dependency().setField("myFoo"))
+                .setValidateMethod("start");
+    }
+
+    private PrimitiveComponentType createAnOptionalConsumer() {
+        return new SingletonComponentType()
+                .setBundleContext(context)
+                .setComponentTypeName("cons.optional")
+                .setClassName(MyComponentImpl.class.getName())
+                .addDependency(new Dependency().setField("myFoo").setOptional(true))
+                .setValidateMethod("start");
+    }
+
+
+}
diff --git a/ipojo/runtime/api-it/src/it/ipojo-api-test/src/test/java/org/apache/felix/ipojo/runtime/core/api/SingletonComponentTest.java b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/test/java/org/apache/felix/ipojo/runtime/core/api/SingletonComponentTest.java
new file mode 100644
index 0000000..8d7f74b
--- /dev/null
+++ b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/test/java/org/apache/felix/ipojo/runtime/core/api/SingletonComponentTest.java
@@ -0,0 +1,159 @@
+package org.apache.felix.ipojo.runtime.core.api;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.MissingHandlerException;
+import org.apache.felix.ipojo.UnacceptableConfiguration;
+import org.apache.felix.ipojo.api.Dependency;
+import org.apache.felix.ipojo.api.PrimitiveComponentType;
+import org.apache.felix.ipojo.api.Service;
+import org.apache.felix.ipojo.api.SingletonComponentType;
+import org.apache.felix.ipojo.runtime.core.api.components.FooImpl;
+import org.apache.felix.ipojo.runtime.core.api.components.MyComponentImpl;
+import org.apache.felix.ipojo.runtime.core.api.services.Foo;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.assertThat;
+
+
+public class SingletonComponentTest extends Common {
+
+    private BundleContext context;
+
+    @Before
+    public void setUp() {
+        context = getContext();
+    }
+
+    @Test
+    public void createAServiceProvider() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
+        assertThat(context, is(notNullValue()));
+        ComponentInstance ci = null;
+
+        SingletonComponentType type = createAProvider();
+        ci = type.create();
+        assertThat("Ci is valid", ci.getState(), is(ComponentInstance.VALID));
+        ServiceReference ref = ipojoHelper.getServiceReferenceByName(Foo.class
+                .getName(), ci.getInstanceName());
+        assertThat(ref, is(notNullValue()));
+        type.disposeInstance(ci);
+
+    }
+
+    @Test
+    public void killTheFactory() throws Exception {
+        assertThat(context, is(notNullValue()));
+        ComponentInstance ci = null;
+        SingletonComponentType type = createAProvider();
+        ci = type.create();
+        assertThat("Ci is valid", ci.getState(), is(ComponentInstance.VALID));
+        ServiceReference ref = ipojoHelper.getServiceReferenceByName(Foo.class
+                .getName(), ci.getInstanceName());
+        assertThat(ref, is(notNullValue()));
+        type.stop();
+        assertThat("Ci is disposed", ci.getState(),
+                is(ComponentInstance.DISPOSED));
+        ref = ipojoHelper.getServiceReferenceByName(Foo.class.getName(), ci
+                .getInstanceName());
+        assertThat(ref, is(nullValue()));
+    }
+
+    @Test
+    public void createAServiceCons() throws Exception {
+        assertThat(context, is(notNullValue()));
+        ComponentInstance ci = null;
+
+        SingletonComponentType type = createAConsumer();
+        ci = type.create();
+        assertThat("Ci is invalid", ci.getState(),
+                is(ComponentInstance.INVALID));
+        type.stop();
+    }
+
+    @Test
+    public void createBoth() throws Exception {
+        SingletonComponentType consFactory = createAConsumer();
+        ComponentInstance cons = consFactory.create();
+        // cons is invalid
+        assertThat("cons is invalid", cons.getState(), is(ComponentInstance.INVALID));
+
+        SingletonComponentType provFactory = createAProvider();
+        ComponentInstance prov = provFactory.create();
+        assertThat("prov is valid", prov.getState(), is(ComponentInstance.VALID));
+        assertThat("cons is valid", cons.getState(), is(ComponentInstance.VALID));
+        consFactory.stop();
+        provFactory.stop();
+    }
+
+    @Test
+    public void createTwoCons() throws Exception {
+        SingletonComponentType consFactory = createAConsumer();
+        ComponentInstance cons1 = createAConsumer().create();
+        // cons is invalid
+        assertThat("cons is invalid", cons1.getState(), is(ComponentInstance.INVALID));
+
+        ComponentInstance prov = createAProvider().create();
+        assertThat("prov is valid", prov.getState(), is(ComponentInstance.VALID));
+        assertThat("cons is valid", cons1.getState(), is(ComponentInstance.VALID));
+
+        ComponentInstance cons2 = createAnOptionalConsumer().create();
+
+        assertThat("cons2 is valid", cons2.getState(), is(ComponentInstance.VALID));
+
+        prov.stop();
+        assertThat("cons is invalid", cons1.getState(), is(ComponentInstance.INVALID));
+        assertThat("cons2 is valid", cons2.getState(), is(ComponentInstance.VALID));
+    }
+
+    @Test
+   // @Ignore("We can't test as the MyComponentImpl must be manipulated before creating the object")
+    public void setObject() throws Exception {
+        ComponentInstance cons = createAConsumer().setObject(new MyComponentImpl(5)).create();
+        // cons is invalid
+        assertThat("cons is invalid", cons.getState(), is(ComponentInstance.INVALID));
+
+        ComponentInstance prov = createAProvider().create();
+        assertThat("prov is valid", prov.getState(), is(ComponentInstance.VALID));
+        assertThat("cons is valid", cons.getState(), is(ComponentInstance.VALID));
+
+    }
+
+    private SingletonComponentType createAProvider() {
+        PrimitiveComponentType type = new SingletonComponentType()
+                .setBundleContext(context)
+                .setClassName(FooImpl.class.getName())
+                .addService(new Service()); // Provide the FooService
+
+        return (SingletonComponentType) type;
+    }
+
+    private SingletonComponentType createAConsumer() {
+        PrimitiveComponentType type = new SingletonComponentType()
+                .setBundleContext(context)
+                .setClassName(MyComponentImpl.class.getName())
+                .setComponentTypeName("singleton.cons")
+                .addDependency(new Dependency().setField("myFoo"))
+                .setValidateMethod("start");
+
+        return (SingletonComponentType) type;
+    }
+
+    private SingletonComponentType createAnOptionalConsumer() {
+        PrimitiveComponentType type = new SingletonComponentType()
+                .setBundleContext(context)
+                .setClassName(MyComponentImpl.class.getName())
+                .addDependency(new Dependency().setField("myFoo").setOptional(true))
+                .setComponentTypeName("singleton.optional.consumer")
+                .setValidateMethod("start");
+
+        return (SingletonComponentType) type;
+
+    }
+
+
+}
diff --git a/ipojo/runtime/api-it/src/it/ipojo-api-test/src/test/java/org/apache/felix/ipojo/runtime/core/api/Whiteboard.java b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/test/java/org/apache/felix/ipojo/runtime/core/api/Whiteboard.java
new file mode 100644
index 0000000..de3e305
--- /dev/null
+++ b/ipojo/runtime/api-it/src/it/ipojo-api-test/src/test/java/org/apache/felix/ipojo/runtime/core/api/Whiteboard.java
@@ -0,0 +1,71 @@
+package org.apache.felix.ipojo.runtime.core.api;
+
+import org.apache.felix.ipojo.api.HandlerConfiguration;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+
+public class Whiteboard implements HandlerConfiguration {
+    
+    public static final String NAME = "wbp";
+    
+    public static final String NAMESPACE = "org.apache.felix.ipojo.whiteboard";
+    
+    private String arrival;
+    
+    private String departure;
+    
+    private String modification;
+    
+    private String filter;
+    
+    public Whiteboard onArrival(String method) {
+        arrival = method;
+        return this;
+    }
+    
+    public Whiteboard onDeparture(String method) {
+        departure = method;
+        return this;
+    }
+    
+    public Whiteboard onModification(String method) {
+        modification = method;
+        return this;
+    }
+    
+    public Whiteboard setFilter(String fil) {
+        filter = fil;
+        return this;
+    }
+
+    public Element getElement() {
+        ensureValidity();
+        // Create the root element.
+        Element element = new Element(NAME, NAMESPACE);
+        // Mandatory attributes
+        element.addAttribute(new Attribute("onArrival", arrival));
+        element.addAttribute(new Attribute("onDeparture", departure));
+        element.addAttribute(new Attribute("filter", filter));
+        
+        // Optional attribute
+        if (modification != null) {
+            element.addAttribute(new Attribute("onModification", modification));
+        }        
+        
+        return element;
+    }
+
+    private void ensureValidity() {
+        if (arrival == null) {
+            throw new IllegalStateException("The whiteboard pattern configuration must have a onArrival method");
+        }
+        if (departure == null) {
+            throw new IllegalStateException("The whiteboard pattern configuration must have a onDeparture method");
+        }
+        if (filter == null) {
+            throw new IllegalStateException("The whiteboard pattern configuration must have a filter");
+        }
+        
+    }
+
+}