Convert toaster-it to use mdsal-it
[controller.git] / opendaylight / config / config-it-base / src / main / java / org / opendaylight / controller / config / it / base / AbstractConfigTestBase.java
index 641d25409dbb53cd16a76cf292ff1ecc69fd6305..ce38de2d3a33fdb83f383a4400526560f5e6921a 100644 (file)
@@ -14,15 +14,14 @@ import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfi
 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
-
 import com.google.common.base.Stopwatch;
-
 import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
 import java.lang.management.ManagementFactory;
+import java.util.Properties;
 import java.util.concurrent.TimeUnit;
-
 import javax.management.ObjectName;
-
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.internal.AssumptionViolatedException;
@@ -41,6 +40,10 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public abstract class AbstractConfigTestBase {
+    private static final String MAVEN_REPO_LOCAL = "maven.repo.local";
+    private static final String ORG_OPS4J_PAX_URL_MVN_LOCAL_REPOSITORY = "org.ops4j.pax.url.mvn.localRepository";
+    private static final String ETC_ORG_OPS4J_PAX_URL_MVN_CFG = "etc/org.ops4j.pax.url.mvn.cfg";
+    private static final String ETC_ORG_OPS4J_PAX_LOGGING_CFG = "etc/org.ops4j.pax.logging.cfg";
 
     private static final String PAX_EXAM_UNPACK_DIRECTORY = "target/exam";
     private static final String KARAF_DEBUG_PORT = "5005";
@@ -50,9 +53,8 @@ public abstract class AbstractConfigTestBase {
     public static final String ORG_OPS4J_PAX_LOGGING_CFG = "etc/org.ops4j.pax.logging.cfg";
 
     /*
-     * Default values for karaf distro version, type, groupId, and artifactId
+     * Default values for karaf distro type, groupId, and artifactId
      */
-    private static final String KARAF_DISTRO_VERSION = "3.0.2";
     private static final String KARAF_DISTRO_TYPE = "zip";
     private static final String KARAF_DISTRO_ARTIFACTID = "apache-karaf";
     private static final String KARAF_DISTRO_GROUPID = "org.apache.karaf";
@@ -65,6 +67,11 @@ public abstract class AbstractConfigTestBase {
     private static final String KARAF_DISTRO_ARTIFACTID_PROP = "karaf.distro.artifactId";
     private static final String KARAF_DISTRO_GROUPID_PROP = "karaf.distro.groupId";
 
+    /**
+     * Property file used to store the Karaf distribution version
+     */
+    private static final String PROPERTIES_FILENAME = "abstractconfigtestbase.properties";
+
     /*
      * Wait up to 10s for our configured module to come up
      */
@@ -92,8 +99,20 @@ public abstract class AbstractConfigTestBase {
     public String getKarafDistro() {
         String groupId = System.getProperty(KARAF_DISTRO_GROUPID_PROP,KARAF_DISTRO_GROUPID);
         String artifactId = System.getProperty(KARAF_DISTRO_ARTIFACTID_PROP,KARAF_DISTRO_ARTIFACTID);
-        String version = System.getProperty(KARAF_DISTRO_VERSION_PROP,KARAF_DISTRO_VERSION);
+        String version = System.getProperty(KARAF_DISTRO_VERSION_PROP);
         String type = System.getProperty(KARAF_DISTRO_TYPE_PROP,KARAF_DISTRO_TYPE);
+        if (version == null) {
+            // We use a properties file to retrieve ${karaf.version}, instead of .versionAsInProject()
+            // This avoids forcing all users to depend on Karaf in their POMs
+            Properties abstractConfigTestBaseProps = new Properties();
+            try (InputStream abstractConfigTestBaseInputStream = Thread.currentThread().getContextClassLoader()
+                    .getResourceAsStream(PROPERTIES_FILENAME)) {
+                abstractConfigTestBaseProps.load(abstractConfigTestBaseInputStream);
+            } catch (IOException e) {
+                LOG.error("Unable to load {} to determine the Karaf version", PROPERTIES_FILENAME, e);
+            }
+            version = abstractConfigTestBaseProps.getProperty(KARAF_DISTRO_VERSION_PROP);
+        }
         MavenArtifactUrlReference karafUrl = maven()
                 .groupId(groupId)
                 .artifactId(artifactId)
@@ -102,6 +121,13 @@ public abstract class AbstractConfigTestBase {
         return karafUrl.getURL();
     }
 
+    protected Option mvnLocalRepoOption() {
+        String mvnRepoLocal = System.getProperty(MAVEN_REPO_LOCAL, "");
+        LOG.info("mvnLocalRepo \"{}\"", mvnRepoLocal);
+        return editConfigurationFilePut(ETC_ORG_OPS4J_PAX_URL_MVN_CFG, ORG_OPS4J_PAX_URL_MVN_LOCAL_REPOSITORY,
+                mvnRepoLocal);
+    }
+
     @Configuration
     public Option[] config() {
         Option[] options = new Option[] {
@@ -112,7 +138,9 @@ public abstract class AbstractConfigTestBase {
                         .useDeployFolder(false),
                 when(Boolean.getBoolean(KEEP_UNPACK_DIRECTORY_PROP)).useOptions(keepRuntimeFolder()),
                 features(getFeatureRepo(), getFeatureName()),
-                getLoggingOption()};
+                getLoggingOption(),
+                mvnLocalRepoOption(),
+                editConfigurationFilePut(ETC_ORG_OPS4J_PAX_LOGGING_CFG, "log4j.rootLogger", "INFO, stdout, osgi:*")};
         return options;
     }