Fix tests on KF

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1479788 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/core-it/pom.xml b/ipojo/runtime/core-it/pom.xml
index 03b9a42..b624811 100644
--- a/ipojo/runtime/core-it/pom.xml
+++ b/ipojo/runtime/core-it/pom.xml
@@ -122,12 +122,12 @@
             <scope>test</scope>
         </dependency>
 
-        <dependency>
+        <!--<dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.framework</artifactId>
             <version>4.2.0</version>
             <scope>test</scope>
-        </dependency>
+        </dependency>-->
 
         <dependency>
             <groupId>ch.qos.logback</groupId>
@@ -143,7 +143,6 @@
             <scope>test</scope>
         </dependency>
 
-
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
@@ -179,6 +178,12 @@
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.ipojo</artifactId>
             <version>1.9.0-SNAPSHOT</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.osgi</groupId>
+                    <artifactId>org.osgi.core</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
 
         <dependency>
@@ -216,12 +221,24 @@
             test.
             -->
             <version>1.8.0</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.osgi</groupId>
+                    <artifactId>org.osgi.core</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
 
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.log</artifactId>
             <version>1.0.1</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.osgi</groupId>
+                    <artifactId>org.osgi.core</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
 
         <dependency>
@@ -317,6 +334,12 @@
                     <version>5.2.0</version>
                     <scope>test</scope>
                 </dependency>
+                <dependency>
+                    <groupId>org.osgi</groupId>
+                    <artifactId>org.osgi.core</artifactId>
+                    <version>4.3.1</version>
+                    <scope>provided</scope>
+                </dependency>
             </dependencies>
         </profile>
 
@@ -339,13 +362,19 @@
                     <version>3.8.1.v20120830-144521</version>
                     <scope>test</scope>
                 </dependency>
+                <dependency>
+                    <groupId>org.osgi</groupId>
+                    <artifactId>org.osgi.core</artifactId>
+                    <version>4.3.1</version>
+                    <scope>provided</scope>
+                </dependency>
             </dependencies>
         </profile>
 
         <profile>
             <id>felix</id>
             <activation>
-                <activeByDefault>false</activeByDefault>
+                <activeByDefault>true</activeByDefault>
                 <property>
                     <name>pax.exam.framework</name>
                     <value>felix</value>
@@ -361,6 +390,12 @@
                     <version>4.2.0</version>
                     <scope>test</scope>
                 </dependency>
+                <dependency>
+                    <groupId>org.osgi</groupId>
+                    <artifactId>org.osgi.core</artifactId>
+                    <version>4.3.1</version>
+                    <scope>provided</scope>
+                </dependency>
             </dependencies>
         </profile>
 
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/Tools.java b/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/Tools.java
index a5e9f94..a6be5ec 100644
--- a/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/Tools.java
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/Tools.java
@@ -28,18 +28,24 @@
 
     /**
      * Get the Factory linked to the given pid
-     * @param osgi
-     * @param name
-     * @return The factory
+     *
+     * @param osgi the osgi test helper
+     * @param name the factory name
+     * @return The factory or {@literal null} if not found.
      */
     public static Factory getValidFactory(final OSGiHelper osgi, final String name) {
-        // Get The Factory ServiceReference
-        ServiceReference facref = osgi.getServiceReference(Factory.class.getName(),
-                "(&(factory.state=1)(factory.name=" + name + "))");
-        // Get the factory
-        Factory factory = (Factory) osgi.getServiceObject(facref);
+        // Wait for service first.
+        ServiceReference ref = osgi.waitForService(
+                Factory.class.getName(),
+                "(&(factory.state=1)(factory.name=" + name + "))",
+                1000, false);
 
-        return factory;
+        if (ref != null) {
+            // Get the factory
+            return (Factory) osgi.getServiceObject(ref);
+        } else {
+            return null;
+        }
     }
 
 }