FELIX-1099: finish the switch to pax-exam

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@770093 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/karaf/itests/pom.xml b/karaf/itests/pom.xml
index e5b931b..30bb1a5 100644
--- a/karaf/itests/pom.xml
+++ b/karaf/itests/pom.xml
@@ -22,12 +22,12 @@
     <modelVersion>4.0.0</modelVersion>
 
     <parent>
-        <groupId>org.apache.servicemix.kernel.gshell</groupId>
-        <artifactId>gshell</artifactId>
+        <groupId>org.apache.servicemix.kernel</groupId>
+        <artifactId>kernel</artifactId>
         <version>1.2.0-SNAPSHOT</version>
     </parent>
 
-    <groupId>org.apache.servicemix.kernel.gshell</groupId>
+    <groupId>org.apache.servicemix.kernel</groupId>
     <artifactId>itests</artifactId>
     <packaging>jar</packaging>
     <version>1.2.0-SNAPSHOT</version>
@@ -38,31 +38,31 @@
     </description>
 
     <dependencies>
+        <!-- This is required to be first so that pax-exam classloader is not messed up with a newer version of felix
+              which would lead to java.lang.NoSuchMethodError: org.apache.felix.framework.Logger.<init>(I)V -->
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.framework</artifactId>
             <version>1.0.0</version>
         </dependency>
+        <!-- This is required to be first so that pax-exam classloader is not messed up with a newer version of felix
+              which would lead to java.lang.RuntimeException: Could not create [service.obr] -->
         <dependency>
-            <groupId>org.apache.servicemix.kernel.gshell</groupId>
-            <artifactId>org.apache.servicemix.kernel.gshell.core</artifactId>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.bundlerepository</artifactId>
+            <version>1.2.1</version>
+        </dependency>
+
+        <!-- The assembly and all the dependencies -->
+        <dependency>
+            <groupId>org.apache.servicemix.kernel</groupId>
+            <artifactId>apache-servicemix-kernel</artifactId>
+            <type>xml</type>
+            <classifier>features</classifier>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.apache.servicemix.kernel.gshell</groupId>
-            <artifactId>org.apache.servicemix.kernel.gshell.log</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.servicemix.kernel.gshell</groupId>
-            <artifactId>org.apache.servicemix.kernel.gshell.osgi</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.servicemix.kernel.jaas</groupId>
-            <artifactId>org.apache.servicemix.kernel.jaas.boot</artifactId>
-            <scope>test</scope>
-        </dependency>
+
+        <!-- Pax EXAM -->
         <dependency>
             <groupId>org.ops4j.pax.exam</groupId>
             <artifactId>pax-exam</artifactId>
@@ -87,6 +87,7 @@
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>4.5</version>
+            <scope>test</scope>
         </dependency>
     </dependencies>
 
@@ -112,27 +113,6 @@
 
     <build>
         <plugins>
-            <plugin>
-        <artifactId>maven-resources-plugin</artifactId>
-        <executions>
-          <execution>
-            <id>copy-resources</id>
-            <phase>validate</phase>
-            <goals>
-              <goal>copy-resources</goal>
-            </goals>
-            <configuration>
-              <outputDirectory>${pom.basedir}/target/test-classes/</outputDirectory>
-              <resources>          
-                <resource>
-                  <directory>${pom.basedir}/src/test/filtered-resources</directory>
-                  <filtering>true</filtering>
-                </resource>
-              </resources>              
-            </configuration>            
-          </execution>
-        </executions>
-      </plugin>
             <!-- generate dependencies versions -->
             <plugin>
                 <groupId>org.apache.servicemix.tooling</groupId>
diff --git a/karaf/itests/src/test/filtered-resources/features.xml b/karaf/itests/src/test/filtered-resources/features.xml
deleted file mode 100644
index 8316b3f..0000000
--- a/karaf/itests/src/test/filtered-resources/features.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
-      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.
--->
-<features>
-    <feature name="wrapper" version="${version}">
-        <bundle>mvn:org.apache.servicemix.kernel.gshell/org.apache.servicemix.kernel.gshell.wrapper/${version}</bundle>
-    </feature>
-    <feature name="obr" version="${version}">
-        <bundle>mvn:org.apache.felix/org.apache.felix.bundlerepository/${felix.bundlerepository.version}</bundle>
-        <bundle>mvn:org.apache.servicemix.kernel.gshell/org.apache.servicemix.kernel.gshell.obr/${version}</bundle>
-    </feature>
-</features>
diff --git a/karaf/itests/src/test/java/org/apache/servicemix/kernel/gshell/itests/AbstractIntegrationTest.java b/karaf/itests/src/test/java/org/apache/servicemix/kernel/gshell/itests/AbstractIntegrationTest.java
index cabbf35..4506991 100644
--- a/karaf/itests/src/test/java/org/apache/servicemix/kernel/gshell/itests/AbstractIntegrationTest.java
+++ b/karaf/itests/src/test/java/org/apache/servicemix/kernel/gshell/itests/AbstractIntegrationTest.java
@@ -18,6 +18,20 @@
 
 import org.ops4j.pax.exam.CoreOptions;
 import org.ops4j.pax.exam.Inject;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.logProfile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.configProfile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.profile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import static org.ops4j.pax.exam.CoreOptions.systemPackages;
+import static org.ops4j.pax.exam.CoreOptions.bootClasspathLibrary;
+import static org.ops4j.pax.exam.CoreOptions.maven;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.mavenConfiguration;
+import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -90,4 +104,50 @@
         return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject();
     }
 
+    @Configuration
+    public static Option[] configuration() {
+        Option[] options = options(
+            // install log service using pax runners profile abstraction (there are more profiles, like DS)
+            logProfile(),
+            configProfile(),
+            profile("spring.dm").version("1.2.0-rc1"),
+
+            // this is how you set the default log level when using pax logging (logProfile)
+            systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+            systemProperty("servicemix.name").value("root"),
+            systemProperty("servicemix.base").value("target/smx.base"),
+            systemProperty("servicemix.startLocalConsole").value("false"),
+            systemProperty("servicemix.startRemoteShell").value("false"),
+
+            // hack system packages
+            systemPackages("org.apache.servicemix.kernel.main.spi;version=1.0.0", "org.apache.servicemix.kernel.jaas.boot"),
+            bootClasspathLibrary(mavenBundle("org.apache.servicemix.kernel.jaas", "org.apache.servicemix.kernel.jaas.boot")).afterFramework(),
+            bootClasspathLibrary(mavenBundle("org.apache.servicemix.kernel", "org.apache.servicemix.kernel.main")).afterFramework(),
+
+            // Bundles
+            mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.jline"),
+            mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.commons-httpclient"),
+            mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.commons-jexl"),
+            mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.commons-vfs"),
+            mavenBundle("org.apache.mina", "mina-core"),
+            mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.oro"),
+            mavenBundle("org.apache.servicemix.kernel.jaas", "org.apache.servicemix.kernel.jaas.config"),
+            mavenBundle("org.apache.sshd", "sshd-core"),
+            mavenBundle("org.apache.servicemix.kernel.gshell", "org.apache.servicemix.kernel.gshell.core"),
+            mavenBundle("org.apache.servicemix.kernel.gshell", "org.apache.servicemix.kernel.gshell.osgi"),
+            mavenBundle("org.apache.servicemix.kernel.gshell", "org.apache.servicemix.kernel.gshell.log").noStart(),
+
+
+//            mavenBundle("org.apache.felix", "org.apache.felix.bundlerepository"),
+
+            scanFeatures(
+                    maven().groupId("org.apache.servicemix.kernel").artifactId("apache-servicemix-kernel").type("xml").classifier("features").versionAsInProject(),
+                    "obr", "wrapper"
+            ),
+
+            felix()
+        );
+        return options;
+    }
+
 }
diff --git a/karaf/itests/src/test/java/org/apache/servicemix/kernel/gshell/itests/CoreTest.java b/karaf/itests/src/test/java/org/apache/servicemix/kernel/gshell/itests/CoreTest.java
index cb66fd1..82f940e 100644
--- a/karaf/itests/src/test/java/org/apache/servicemix/kernel/gshell/itests/CoreTest.java
+++ b/karaf/itests/src/test/java/org/apache/servicemix/kernel/gshell/itests/CoreTest.java
@@ -24,17 +24,7 @@
 import static org.junit.Assert.fail;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import static org.ops4j.pax.exam.CoreOptions.felix;
-import static org.ops4j.pax.exam.CoreOptions.mavenConfiguration;
-import static org.ops4j.pax.exam.CoreOptions.options;
-import static org.ops4j.pax.exam.CoreOptions.systemPackages;
-import static org.ops4j.pax.exam.CoreOptions.systemProperty;
-import static org.ops4j.pax.exam.CoreOptions.bootClasspathLibrary;
 import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.OptionUtils;
-import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.configProfile;
-import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.logProfile;
-import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.profile;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.Bundle;
@@ -65,7 +55,7 @@
 
         shell.execute("log/display");
 
-        b.uninstall();
+        b.stop();
 
         try {
             shell.execute("log/display");
@@ -84,86 +74,19 @@
         shell.execute("..");
     }
     
-//    @Test
-//    public void testInstallFeature() throws Exception {
-//        Shell shell = getOsgiService(Shell.class);
-//
-//        try {
-//            shell.execute("obr");
-//            fail("command should not exist");
-//        } catch (CommandLineExecutionFailed e) {
-//            assertNotNull(e.getCause());
-//            assertTrue(e.getCause() instanceof NoSuchCommandException);
-//        }
-//        try {
-//            shell.execute("wrapper");
-//            fail("command should not exist");
-//        } catch (CommandLineExecutionFailed e) {
-//            assertNotNull(e.getCause());
-//            assertTrue(e.getCause() instanceof NoSuchCommandException);
-//        }
-//        String url = getClass().getClassLoader().getResource("features.xml").toString();
-//        addFeatureRepo(url);
-//        installFeature("obr");
-//        installFeature("wrapper");
-//        shell.execute("obr");
-//        shell.execute("wrapper");
-//    }
-
-    /**
-     * TODO: This test seems to fail, there must be a timing issue somewhere
-     *
+    @Test
     public void testCommandGroupAfterInstall() throws Exception {
-        Bundle b = installBundle("org.apache.servicemix.kernel.gshell", "org.apache.servicemix.kernel.gshell.log", null, "jar");
+        Bundle b = getInstalledBundle("org.apache.servicemix.kernel.gshell.log");
+        b.start();
         Shell shell = getOsgiService(Shell.class);
         shell.execute("log");
         shell.execute("help");
         shell.execute("..");
     }
-     */
 
     @Configuration
     public static Option[] configuration() {
-        Option[] options = options(
-            // install log service using pax runners profile abstraction (there are more profiles, like DS)
-            logProfile(),
-            configProfile(),
-            profile("spring.dm").version("1.2.0-rc1"),
-
-            // this is how you set the default log level when using pax logging (logProfile)
-            systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
-            systemProperty("servicemix.name").value("root"),
-            systemProperty("servicemix.base").value("target/smx.base"),
-            systemProperty("servicemix.startLocalConsole").value("false"),
-            systemProperty("servicemix.startRemoteShell").value("false"),
-
-            // hack system packages
-            systemPackages("org.apache.servicemix.kernel.main.spi;version=1.0.0", "org.apache.servicemix.kernel.jaas.boot"),
-            bootClasspathLibrary(mavenBundle("org.apache.servicemix.kernel.jaas", "org.apache.servicemix.kernel.jaas.boot")).afterFramework(),
-            bootClasspathLibrary(mavenBundle("org.apache.servicemix.kernel", "org.apache.servicemix.kernel.main")).afterFramework(),
-
-            // Bundles
-            mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.jline"),
-            mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.commons-httpclient"),
-            mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.commons-jexl"),
-            mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.commons-vfs"),
-            mavenBundle("org.apache.mina", "mina-core"),
-            mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.oro"),
-            mavenBundle("org.apache.servicemix.kernel.jaas", "org.apache.servicemix.kernel.jaas.config"),
-            mavenBundle("org.apache.sshd", "sshd-core"),
-            mavenBundle("org.apache.servicemix.kernel.gshell", "org.apache.servicemix.kernel.gshell.core"),
-            mavenBundle("org.apache.servicemix.kernel.gshell", "org.apache.servicemix.kernel.gshell.osgi"),
-            mavenBundle("org.apache.servicemix.kernel.gshell", "org.apache.servicemix.kernel.gshell.log").noStart(),
-
-            felix()
-        );
-
-        // use config generated by the Maven plugin (until PAXEXAM-62/64 get resolved)
-        if (CoreTest.class.getClassLoader().getResource("META-INF/maven/paxexam-config.args") != null) {
-            options = OptionUtils.combine(options, mavenConfiguration());
-        }
-
-        return options;
+        return AbstractIntegrationTest.configuration();
     }
 
 }
diff --git a/karaf/itests/src/test/java/org/apache/servicemix/kernel/gshell/itests/FeaturesTest.java b/karaf/itests/src/test/java/org/apache/servicemix/kernel/gshell/itests/FeaturesTest.java
new file mode 100644
index 0000000..738d4b7
--- /dev/null
+++ b/karaf/itests/src/test/java/org/apache/servicemix/kernel/gshell/itests/FeaturesTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+package org.apache.servicemix.kernel.gshell.itests;
+
+import org.apache.geronimo.gshell.shell.Shell;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+
+@RunWith(JUnit4TestRunner.class)
+public class FeaturesTest extends AbstractIntegrationTest {
+
+    @Test
+    public void testFeatures() throws Exception {
+        Shell shell = getOsgiService(Shell.class);
+        shell.execute("obr");
+        shell.execute("wrapper");
+    }
+
+    @Configuration
+    public static Option[] configuration() {
+        return AbstractIntegrationTest.configuration();
+    }
+
+}