Re-structure the test suites, use withiPOJO and OSGi test helpers.
Also update some test to the latest tinybundles.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@939968 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/tests/online-manipulator/pom.xml b/ipojo/tests/online-manipulator/pom.xml
index 085bb02..3729fc9 100644
--- a/ipojo/tests/online-manipulator/pom.xml
+++ b/ipojo/tests/online-manipulator/pom.xml
@@ -1,6 +1,13 @@
 <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">
   <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+  	<groupId>ipojo.tests</groupId>
+  	<artifactId>ipojo.tests</artifactId>
+  	<version>1.5.0-SNAPSHOT</version>
+  </parent>
+
   <groupId>org.apache.felix</groupId>
   <artifactId>org.apache.felix.ipojo.online.manipulator.test</artifactId>
   <version>1.5.0-SNAPSHOT</version>
@@ -19,6 +26,7 @@
       <plugin>
         <groupId>org.apache.servicemix.tooling</groupId>
         <artifactId>depends-maven-plugin</artifactId>
+        <version>1.2</version>
         <executions>
           <execution>
             <id>generate-depends-file</id>
@@ -28,33 +36,13 @@
           </execution>
         </executions>
       </plugin>
-
-      <!--
-      <plugin>
-        <groupId>org.ops4j.pax.exam</groupId>
-        <artifactId>maven-paxexam-plugin</artifactId>
-        <executions>
-          <execution>
-          <id>generate-paxexam-config</id>
-          <goals>
-            <goal>generate-paxexam-config</goal>
-          </goals>
-          </execution>
-        </executions>
-        <configuration>
-        <settings>
-          <platform>felix</platform>
-        </settings>
-        </configuration>
-      </plugin> -->
     </plugins>
   </build>
 
   <dependencies>
-  <dependency>
-      <groupId>org.apache.felix</groupId>
+  	<dependency>
+      <groupId>org.osgi</groupId>
       <artifactId>org.osgi.core</artifactId>
-      <version>1.2.0</version>
     </dependency>
 
   <!--
@@ -63,7 +51,7 @@
   <dependency>
     <groupId>org.ops4j.pax.exam</groupId>
     <artifactId>pax-exam</artifactId>
-    <version>1.1.0</version>
+    <version>1.2.0</version>
   </dependency>
   <!--
     During runtime Pax Exam will discover the OSGi container to use by
@@ -75,57 +63,49 @@
     <groupId>org.ops4j.pax.exam</groupId>
     <artifactId>pax-exam-container-default
     </artifactId>
-    <version>1.1.0</version>
+    <version>1.2.0</version>
   </dependency>
   <!--
     If your test code is based on JUnit you will have to have the Junit
     support artifact:
   -->
-  <dependency>
-    <groupId>org.ops4j.pax.exam</groupId>
-    <artifactId>pax-exam-junit</artifactId>
-    <version>1.1.0</version>
-  </dependency>
-  <dependency>
-    <groupId>junit</groupId>
-    <artifactId>junit</artifactId>
-    <version>4.5</version>
-    <type>jar</type>
-    <scope>test</scope>
-  </dependency>
+	<dependency>
+		<groupId>org.ops4j.pax.exam</groupId>
+		<artifactId>pax-exam-junit</artifactId>
+		<version>1.2.0</version>
+	</dependency>
+	<dependency>
+		<groupId>junit</groupId>
+		<artifactId>junit</artifactId>
+		<version>4.5</version>
+		<type>jar</type>
+		<scope>test</scope>
+	</dependency>
 
-
-  <!-- TinyBundle -->
-  <dependency>
-    <groupId>org.ops4j.pax.swissbox</groupId>
-    <artifactId>pax-swissbox-tinybundles</artifactId>
-    <version>1.0.0</version>
-  </dependency>
-  <dependency>
-    <groupId>org.apache.felix</groupId>
-    <artifactId>org.apache.felix.ipojo.tinybundles.bundleAsiPOJO</artifactId>
-    <version>1.5.0-SNAPSHOT</version>
-  </dependency>
-    <dependency>
-      <groupId>xerces</groupId>
-      <artifactId>xercesImpl</artifactId>
-      <version>2.4.0</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.felix</groupId>
-      <artifactId>org.apache.felix.ipojo.annotations</artifactId>
-      <version>1.6.0</version>
-    </dependency>
-     <dependency>
-      <groupId>org.apache.felix</groupId>
-      <artifactId>org.apache.felix.ipojo</artifactId>
-      <version>1.7.0-SNAPSHOT</version>
-    </dependency>
-     <dependency>
-      <groupId>org.apache.felix</groupId>
-      <artifactId>org.apache.felix.ipojo.online.manipulator</artifactId>
-      <version>1.7.0-SNAPSHOT</version>
-    </dependency>
+	<dependency>
+		<groupId>org.ops4j.pax.swissbox</groupId>
+		<artifactId>pax-swissbox-tinybundles</artifactId>
+		<version>1.2.0</version>
+	</dependency>
+	<dependency>
+		<groupId>xerces</groupId>
+		<artifactId>xercesImpl</artifactId>
+		<version>2.4.0</version>
+	</dependency>
+	<dependency>
+		<groupId>org.apache.felix</groupId>
+		<artifactId>org.apache.felix.ipojo.annotations</artifactId>
+	</dependency>
+	<dependency>
+		<groupId>org.apache.felix</groupId>
+		<artifactId>org.apache.felix.ipojo</artifactId>
+		<version>1.7.0-SNAPSHOT</version>
+	</dependency>
+	<dependency>
+		<groupId>org.apache.felix</groupId>
+		<artifactId>org.apache.felix.ipojo.online.manipulator</artifactId>
+		<version>1.7.0-SNAPSHOT</version>
+	</dependency>
 
   </dependencies>
 </project>
diff --git a/ipojo/tests/online-manipulator/src/test/java/org/apache/felix/org/apache/felix/ipojo/online/manipulator/test/OnlineManipulatorTest.java b/ipojo/tests/online-manipulator/src/test/java/org/apache/felix/org/apache/felix/ipojo/online/manipulator/test/OnlineManipulatorTest.java
index c10f824..30963d5 100644
--- a/ipojo/tests/online-manipulator/src/test/java/org/apache/felix/org/apache/felix/ipojo/online/manipulator/test/OnlineManipulatorTest.java
+++ b/ipojo/tests/online-manipulator/src/test/java/org/apache/felix/org/apache/felix/ipojo/online/manipulator/test/OnlineManipulatorTest.java
@@ -3,20 +3,18 @@
 
 import static org.ops4j.pax.exam.CoreOptions.equinox;
 import static org.ops4j.pax.exam.CoreOptions.felix;
-import static org.ops4j.pax.exam.CoreOptions.knopflerfish;
 import static org.ops4j.pax.exam.CoreOptions.frameworks;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
-import static org.ops4j.pax.exam.MavenUtils.asInProject;
 import static org.ops4j.pax.exam.CoreOptions.options;
 import static org.ops4j.pax.exam.CoreOptions.provision;
 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
-import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.asFile;
-import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.asURL;
+import static org.ops4j.pax.exam.MavenUtils.asInProject;
 import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.newBundle;
-import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.with;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 
 import org.apache.felix.ipojo.ComponentInstance;
 import org.apache.felix.ipojo.architecture.Architecture;
@@ -29,10 +27,13 @@
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.ops4j.io.StreamUtils;
+import org.ops4j.pax.exam.Customizer;
 import org.ops4j.pax.exam.Inject;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.swissbox.tinybundles.core.TinyBundles;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
@@ -79,11 +80,6 @@
                       //  knopflerfish() KF does not export an XML parser.
                     ),
             provision(
-                mavenBundle()
-                    .groupId( "org.ops4j.pax.swissbox" )
-                    .artifactId( "pax-swissbox-tinybundles" )
-                    .version(asInProject())),
-            provision(
                     mavenBundle()
                     .groupId("org.apache.felix")
                     .artifactId("org.apache.felix.ipojo")
@@ -98,17 +94,27 @@
                     ),
             provision(
                             newBundle()
-                                .addClass( Hello.class )
-                                .prepare()
+                                .add( Hello.class )
                                .set(Constants.BUNDLE_SYMBOLICNAME,"ServiceInterface")
                                .set(Constants.EXPORT_PACKAGE, "org.apache.felix.org.apache.felix.ipojo.online.manipulator.test.service")
-                                .build( asURL() ).toExternalForm()
+                               .build()
                         ),
            systemProperty( "providerWithMetadata" ).value( providerWithMetadata ),
            systemProperty( "providerWithMetadataInMetaInf" ).value( providerWithMetadataInMetaInf ),
            systemProperty( "providerWithoutMetadata" ).value( providerWithoutMetadata ),
            systemProperty( "consumerWithMetadata").value(consumerWithMetadata),
-           systemProperty( "consumerWithoutMetadata").value(consumerWithoutMetadata)
+           systemProperty( "consumerWithoutMetadata").value(consumerWithoutMetadata),
+
+           new Customizer() {
+                	 @Override
+                     public InputStream customizeTestProbe( InputStream testProbe )
+                     {
+                         return TinyBundles.modifyBundle(testProbe).set(Constants.IMPORT_PACKAGE,
+                        		 "org.apache.felix.org.apache.felix.ipojo.online.manipulator.test.service")
+                        		 .build();
+                     }
+
+                }
            );
 
 
@@ -141,12 +147,16 @@
     }
 
     @Test
-    public void installProviderWithMetadata1() throws BundleException, InvalidSyntaxException, IOException {
+    public void installProviderWithMetadata1() throws BundleException, InvalidSyntaxException, Exception {
         String url = context.getProperty("providerWithMetadata");
         Assert.assertNotNull(url);
-        context.installBundle("ipojo:"+url).start();
+        Bundle bundle = context.installBundle("ipojo:"+url);
+        bundle.start();
 
         assertBundle("Provider");
+
+        Assert.assertNotNull(context.getAllServiceReferences(Hello.class.getName(), null));
+
         helper.waitForService(Hello.class.getName(), null, 5000);
         assertValidity();
         Assert.assertNotNull(context.getServiceReference(Hello.class.getName()));
@@ -226,15 +236,16 @@
      * @throws IOException
      */
     public static String providerWithMetadata() throws IOException {
-        return newBundle()
-        .addResource("metadata.xml", OnlineManipulatorTest.class.getClassLoader().getResource("provider.xml"))
-        .addClass(MyProvider.class)
-        .prepare(
-            with()
-                .set(Constants.BUNDLE_SYMBOLICNAME,"Provider")
-                .set(Constants.IMPORT_PACKAGE, "org.apache.felix.org.apache.felix.ipojo.online.manipulator.test.service")
-            )
-              .build( asFile(getTemporaryFile("providerWithMetadata")) ).toURL().toExternalForm();
+        InputStream is = newBundle()
+        .add("metadata.xml", OnlineManipulatorTest.class.getClassLoader().getResource("provider.xml"))
+        .add(MyProvider.class)
+        .set(Constants.BUNDLE_SYMBOLICNAME,"Provider")
+        .set(Constants.IMPORT_PACKAGE, "org.apache.felix.org.apache.felix.ipojo.online.manipulator.test.service")
+        .build();
+
+        File out = getTemporaryFile("providerWithMetadata");
+        StreamUtils.copyStream(is, new FileOutputStream(out), true);
+        return out.toURI().toURL().toExternalForm();
     }
 
     /**
@@ -243,15 +254,16 @@
      * @throws IOException
      */
     public static String providerWithMetadataInMetaInf() throws IOException {
-        return newBundle()
-        .addResource("META-INF/metadata.xml", OnlineManipulatorTest.class.getClassLoader().getResource("provider.xml"))
-        .addClass(MyProvider.class)
-        .prepare(
-            with()
-                .set(Constants.BUNDLE_SYMBOLICNAME,"Provider")
-                .set(Constants.IMPORT_PACKAGE, "org.apache.felix.org.apache.felix.ipojo.online.manipulator.test.service")
-            )
-              .build( asFile(getTemporaryFile("providerWithMetadataInMetaInf")) ).toURL().toExternalForm();
+        InputStream is = newBundle()
+        .add("META-INF/metadata.xml", OnlineManipulatorTest.class.getClassLoader().getResource("provider.xml"))
+        .add(MyProvider.class)
+        .set(Constants.BUNDLE_SYMBOLICNAME,"Provider")
+        .set(Constants.IMPORT_PACKAGE, "org.apache.felix.org.apache.felix.ipojo.online.manipulator.test.service")
+        .build();
+
+        File out = getTemporaryFile("providerWithMetadataInMetaInf");
+        StreamUtils.copyStream(is, new FileOutputStream(out), true);
+        return out.toURI().toURL().toExternalForm();
     }
 
     /**
@@ -260,15 +272,16 @@
      * @throws IOException
      */
     public static String providerWithoutMetadata() throws IOException {
-        String url = newBundle()
+    	InputStream is = newBundle()
         //.addResource("metadata.xml", this.getClass().getClassLoader().getResource("provider.xml"))
-        .addClass(MyProvider.class)
-        .prepare(
-            with()
-                .set(Constants.BUNDLE_SYMBOLICNAME,"Provider")
-                .set(Constants.IMPORT_PACKAGE, "org.apache.felix.org.apache.felix.ipojo.online.manipulator.test.service")
-            )
-              .build( asFile(getTemporaryFile("providerWithoutMetadata")) ).toURL().toExternalForm();
+        .add(MyProvider.class)
+        .set(Constants.BUNDLE_SYMBOLICNAME,"Provider")
+        .set(Constants.IMPORT_PACKAGE, "org.apache.felix.org.apache.felix.ipojo.online.manipulator.test.service")
+        .build();
+
+    	File out = getTemporaryFile("providerWithoutMetadata");
+        StreamUtils.copyStream(is, new FileOutputStream(out), true);
+        String url = out.toURI().toURL().toExternalForm();
 
         return url + "!" +OnlineManipulatorTest.class.getClassLoader().getResource("provider.xml");
     }
@@ -280,17 +293,16 @@
      * @throws IOException
      */
     public static String consumerWithMetadata() throws IOException {
-        return newBundle()
-            .addResource("metadata.xml", OnlineManipulatorTest.class.getClassLoader().getResource("consumer.xml"))
-            .addClass(Consumer.class)
+        InputStream is = newBundle()
+            .add("metadata.xml", OnlineManipulatorTest.class.getClassLoader().getResource("consumer.xml"))
+            .add(Consumer.class)
+            .set(Constants.BUNDLE_SYMBOLICNAME, "Consumer")
+            .set(Constants.IMPORT_PACKAGE, "org.apache.felix.org.apache.felix.ipojo.online.manipulator.test.service")
+            .build();
 
-        .prepare(
-                with()
-                        .set(Constants.BUNDLE_SYMBOLICNAME, "Consumer")
-                .set(Constants.IMPORT_PACKAGE, "org.apache.felix.org.apache.felix.ipojo.online.manipulator.test.service")
-                )
-                .build( asFile(getTemporaryFile("consumerWithMetadata")) ).toURL().toExternalForm();
-
+        File out = getTemporaryFile("consumerWithMetadata");
+        StreamUtils.copyStream(is, new FileOutputStream(out), true);
+        return out.toURI().toURL().toExternalForm();
     }
 
     /**
@@ -300,14 +312,15 @@
      * @throws IOException
      */
     public static String consumerWithoutMetadata() throws IOException {
-        String url = newBundle()
-        .addClass(Consumer.class)
-        .prepare(
-                with()
-                        .set(Constants.BUNDLE_SYMBOLICNAME, "Consumer")
-                .set(Constants.IMPORT_PACKAGE, "org.apache.felix.org.apache.felix.ipojo.online.manipulator.test.service")
-                )
-                .build( asFile(getTemporaryFile("consumerWithoutMetadata")) ).toURL().toExternalForm();
+        InputStream is = newBundle()
+        .add(Consumer.class)
+        .set(Constants.BUNDLE_SYMBOLICNAME, "Consumer")
+        .set(Constants.IMPORT_PACKAGE, "org.apache.felix.org.apache.felix.ipojo.online.manipulator.test.service")
+        .build();
+
+        File out = getTemporaryFile("consumerWithoutMetadata");
+        StreamUtils.copyStream(is, new FileOutputStream(out), true);
+        String url = out.toURI().toURL().toExternalForm();
 
         return url + "!" + OnlineManipulatorTest.class.getClassLoader().getResource("consumer.xml");
     }