You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dk...@apache.org on 2014/08/28 18:41:44 UTC

[2/2] git commit: Get many of the OSGi/Karaf tests passing with Karaf3 by making sure the JUnit bundle is loaded very very early.

Get many of the OSGi/Karaf tests passing with Karaf3 by making sure the JUnit bundle is loaded very very early.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a522c92e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a522c92e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a522c92e

Branch: refs/heads/master
Commit: a522c92e4fb25ff4a36d693f1f7154f6d7b1f47f
Parents: 9fd3919
Author: Daniel Kulp <dk...@apache.org>
Authored: Thu Aug 28 12:40:54 2014 -0400
Committer: Daniel Kulp <dk...@apache.org>
Committed: Thu Aug 28 12:40:54 2014 -0400

----------------------------------------------------------------------
 parent/pom.xml                                  |  6 +++
 tests/camel-itest-karaf/pom.xml                 |  5 +++
 .../camel/itest/karaf/AbstractFeatureTest.java  | 34 +++++++++++++---
 tests/camel-itest-osgi/pom.xml                  | 10 +++++
 .../itest/osgi/OSGiIntegrationTestSupport.java  | 42 +++++++++++++++-----
 5 files changed, 83 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a522c92e/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 8ae3da2..f3ae665 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1970,6 +1970,12 @@
         <artifactId>pax-swissbox-tinybundles</artifactId>
         <version>${pax-tiny-bundle-version}</version>
       </dependency>
+      <dependency>
+          <groupId>org.ops4j.pax.exam</groupId>
+          <artifactId>pax-exam-invoker-junit</artifactId>
+          <version>${pax-exam-version}</version>
+      </dependency>
+      
 
 
       <!-- optional Saxon support -->

http://git-wip-us.apache.org/repos/asf/camel/blob/a522c92e/tests/camel-itest-karaf/pom.xml
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/pom.xml b/tests/camel-itest-karaf/pom.xml
index 9944170..5f5bc44 100644
--- a/tests/camel-itest-karaf/pom.xml
+++ b/tests/camel-itest-karaf/pom.xml
@@ -82,6 +82,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.servicemix.bundles</groupId>
+            <artifactId>org.apache.servicemix.bundles.junit</artifactId>
+            <version>${junit-bundle-version}</version>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/camel/blob/a522c92e/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/AbstractFeatureTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/AbstractFeatureTest.java b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/AbstractFeatureTest.java
index 430273d..2ab693c 100644
--- a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/AbstractFeatureTest.java
+++ b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/AbstractFeatureTest.java
@@ -17,9 +17,11 @@
 package org.apache.camel.itest.karaf;
 
 import java.io.File;
-
+import java.io.InputStream;
 import java.lang.reflect.Field;
 import java.nio.charset.Charset;
+import java.util.Properties;
+
 import javax.inject.Inject;
 
 import org.apache.camel.CamelContext;
@@ -33,13 +35,14 @@ import org.junit.Before;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.karaf.options.KarafDistributionOption;
 import org.ops4j.pax.exam.karaf.options.LogLevelOption;
+import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
 import org.ops4j.pax.exam.options.UrlReference;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 import static org.junit.Assert.assertNotNull;
+
 import static org.ops4j.pax.exam.CoreOptions.maven;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
 import static org.ops4j.pax.exam.CoreOptions.vmOption;
@@ -177,15 +180,31 @@ public abstract class AbstractFeatureTest {
             throw new RuntimeException(e);
         }
     }
-
+    
     private static String getKarafVersion() {
-        String karafVersion = System.getProperty("karafVersion");
+        InputStream ins = AbstractFeatureTest.class.getResourceAsStream("/META-INF/maven/dependencies.properties");
+        Properties p = new Properties();
+        try {
+            p.load(ins);
+        } catch (Throwable t) {
+            //
+        }
+        String karafVersion = p.getProperty("org.apache.karaf/apache-karaf/version");
+        if (karafVersion == null) {
+            karafVersion = System.getProperty("karafVersion");
+        }
         if (karafVersion == null) {
             // setup the default version of it
             karafVersion = "2.3.6";
         }
         return karafVersion;
     }
+    public static MavenArtifactProvisionOption getJUnitBundle() {
+        MavenArtifactProvisionOption mavenOption = mavenBundle().groupId("org.apache.servicemix.bundles")
+            .artifactId("org.apache.servicemix.bundles.junit");
+        mavenOption.versionAsInProject().start(true).startLevel(10);
+        return mavenOption;
+    }
 
     public static Option[] configure(String feature) {
         switchPlatformEncodingToUTF8();
@@ -193,6 +212,10 @@ public abstract class AbstractFeatureTest {
         LOG.info("*** The karaf version is " + karafVersion + " ***");
 
         Option[] options = new Option[] {
+            // for remote debugging
+            //org.ops4j.pax.exam.CoreOptions.vmOption("-Xdebug"),
+            //org.ops4j.pax.exam.CoreOptions.vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5008"),
+            
             KarafDistributionOption.karafDistributionConfiguration()
                     .frameworkUrl(maven().groupId("org.apache.karaf").artifactId("apache-karaf").type("tar.gz").versionAsInProject())
                     .karafVersion(karafVersion)
@@ -206,7 +229,8 @@ public abstract class AbstractFeatureTest {
             //KarafDistributionOption.replaceConfigurationFile("etc/config.properties", new File("src/test/resources/org/apache/camel/itest/karaf/config.properties")),
             KarafDistributionOption.replaceConfigurationFile("etc/custom.properties", new File("src/test/resources/org/apache/camel/itest/karaf/custom.properties")),
             KarafDistributionOption.replaceConfigurationFile("etc/org.ops4j.pax.url.mvn.cfg", new File("src/test/resources/org/apache/camel/itest/karaf/org.ops4j.pax.url.mvn.cfg")),
-
+            
+            getJUnitBundle(),
 
             // we need INFO logging otherwise we cannot see what happens
             new LogLevelOption(LogLevelOption.LogLevel.INFO),

http://git-wip-us.apache.org/repos/asf/camel/blob/a522c92e/tests/camel-itest-osgi/pom.xml
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/pom.xml b/tests/camel-itest-osgi/pom.xml
index a1be199..c1106f8 100644
--- a/tests/camel-itest-osgi/pom.xml
+++ b/tests/camel-itest-osgi/pom.xml
@@ -56,6 +56,11 @@
     </dependency>
     <dependency>
         <groupId>org.ops4j.pax.exam</groupId>
+        <artifactId>pax-exam-invoker-junit</artifactId>
+        <scope>test</scope>
+    </dependency>
+    <dependency>
+        <groupId>org.ops4j.pax.exam</groupId>
         <artifactId>pax-exam</artifactId>
         <scope>test</scope>
     </dependency>
@@ -338,6 +343,11 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+        <groupId>org.apache.servicemix.bundles</groupId>
+        <artifactId>org.apache.servicemix.bundles.junit</artifactId>
+        <version>${junit-bundle-version}</version>
+    </dependency>
+    <dependency>
         <groupId>org.apache.aries.blueprint</groupId>
         <artifactId>org.apache.aries.blueprint</artifactId>
         <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/camel/blob/a522c92e/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java
index e9ee455..359403f 100644
--- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java
+++ b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/OSGiIntegrationTestSupport.java
@@ -16,8 +16,10 @@
  */
 package org.apache.camel.itest.osgi;
 import java.io.File;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Properties;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.inject.Inject;
@@ -80,6 +82,12 @@ public class OSGiIntegrationTestSupport extends CamelTestSupport {
         return getCamelKarafFeatureUrl(null);
     }
 
+    public static MavenArtifactProvisionOption getJUnitBundle() {
+        MavenArtifactProvisionOption mavenOption = mavenBundle().groupId("org.apache.servicemix.bundles")
+            .artifactId("org.apache.servicemix.bundles.junit");
+        mavenOption.versionAsInProject().start(true).startLevel(10);
+        return mavenOption;
+    }
     public static UrlReference getCamelKarafFeatureUrl(String version) {
 
         String type = "xml/features";
@@ -139,7 +147,17 @@ public class OSGiIntegrationTestSupport extends CamelTestSupport {
     }
 
     private static String getKarafVersion() {
-        String karafVersion = System.getProperty("karafVersion");
+        InputStream ins = OSGiIntegrationTestSupport.class.getResourceAsStream("/META-INF/maven/dependencies.properties");
+        Properties p = new Properties();
+        try {
+            p.load(ins);
+        } catch (Throwable t) {
+            //
+        }
+        String karafVersion = p.getProperty("org.apache.karaf/apache-karaf/version");
+        if (karafVersion == null) {
+            karafVersion = System.getProperty("karafVersion");
+        }
         if (karafVersion == null) {
             // setup the default version of it
             karafVersion = "2.3.6";
@@ -154,19 +172,27 @@ public class OSGiIntegrationTestSupport extends CamelTestSupport {
         Option[] options =
         // Set the karaf environment with some customer configuration
             new Option[] {
+                      // for remote debugging
+                      //org.ops4j.pax.exam.CoreOptions.vmOption("-Xdebug"),
+                      //org.ops4j.pax.exam.CoreOptions.vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5008"),
+
                       KarafDistributionOption.karafDistributionConfiguration()
-                          .frameworkUrl(maven().groupId("org.apache.karaf").artifactId("apache-karaf").type("tar.gz").versionAsInProject())
+                          .frameworkUrl(maven().groupId("org.apache.karaf")
+                                        .artifactId("apache-karaf").type("tar.gz").versionAsInProject())
                           .karafVersion(karafVersion)
                           .name("Apache Karaf")
-                          .useDeployFolder(false).unpackDirectory(new File("target/paxexam/unpack/")),
+                          .useDeployFolder(false)
+                          .unpackDirectory(new File("target/paxexam/unpack/")),
 
                       //KarafDistributionOption.keepRuntimeFolder(),
                       // override the config.properties (to fix pax-exam bug)
                       // KarafDistributionOption.replaceConfigurationFile("etc/config.properties", new File("src/test/resources/org/apache/camel/itest/karaf/config.properties")),
                       KarafDistributionOption.replaceConfigurationFile("etc/custom.properties", new File("src/test/resources/org/apache/camel/itest/karaf/custom.properties")),
                       KarafDistributionOption.replaceConfigurationFile("etc/org.ops4j.pax.url.mvn.cfg", new File("src/test/resources/org/apache/camel/itest/karaf/org.ops4j.pax.url.mvn.cfg")),
-
-
+               
+                //Grab JUnit and put it very early in the startup to make sure any bundles that are loaded 
+                //will use the same version/bundle
+                getJUnitBundle(),
                 // we need INFO logging otherwise we cannot see what happens
                 new LogLevelOption(LogLevelOption.LogLevel.INFO),
                 // install the cxf jaxb spec as the karaf doesn't provide it by default
@@ -179,10 +205,8 @@ public class OSGiIntegrationTestSupport extends CamelTestSupport {
     @Configuration
     public static Option[] configure() throws Exception {
         Option[] options = combine(
-            getDefaultCamelKarafOptions());
-
-        // for remote debugging
-        // vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5008"),
+            getDefaultCamelKarafOptions()
+        );
 
         return options;
     }