AbstractMdsalTestBase: remove derivation from AbstractConfigTestBase 31/72631/2
authorTom Pantelis <tompantelis@gmail.com>
Mon, 4 Jun 2018 00:47:43 +0000 (20:47 -0400)
committerTom Pantelis <tompantelis@gmail.com>
Mon, 4 Jun 2018 01:50:22 +0000 (21:50 -0400)
Copied the code in AbstractConfigTestBase to AbstractMdsalTestBase
as AbstractConfigTestBase will be going away.

Change-Id: I904fa3f60f0e0070e30b0663a1a983201a934cf8
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
opendaylight/md-sal/mdsal-it-base/pom.xml
opendaylight/md-sal/mdsal-it-base/src/main/java/org/opendaylight/controller/mdsal/it/base/AbstractMdsalTestBase.java
opendaylight/md-sal/mdsal-it-parent/pom.xml

index 38380dc..fa9bc03 100644 (file)
@@ -20,9 +20,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
   <artifactId>mdsal-it-base</artifactId>
   <version>1.8.0-SNAPSHOT</version>
   <packaging>bundle</packaging>
-  <properties>
-    <config.version>0.9.0-SNAPSHOT</config.version>
-  </properties>
+
   <dependencyManagement>
     <dependencies>
       <dependency>
@@ -34,12 +32,12 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       </dependency>
     </dependencies>
   </dependencyManagement>
+
   <dependencies>
     <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>config-it-base</artifactId>
-      <version>${config.version}</version>
-      <scope>compile</scope>
+      <groupId>org.opendaylight.odlparent</groupId>
+      <artifactId>opendaylight-karaf-empty</artifactId>
+      <type>zip</type>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
@@ -69,7 +67,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
     <dependency>
         <groupId>javax.inject</groupId>
         <artifactId>javax.inject</artifactId>
-        <version>1</version>
         <scope>compile</scope>
     </dependency>
     <dependency>
index 500ce89..d553fde 100644 (file)
@@ -8,30 +8,67 @@
 
 package org.opendaylight.controller.mdsal.it.base;
 
-import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
 import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.maven;
+import static org.ops4j.pax.exam.CoreOptions.when;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
+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 java.io.File;
 import javax.inject.Inject;
-
 import org.junit.Before;
-import org.opendaylight.controller.config.it.base.AbstractConfigTestBase;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
+import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.exam.karaf.options.KarafDistributionOption;
 import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
+import org.ops4j.pax.exam.options.MavenUrlReference;
 import org.ops4j.pax.exam.util.Filter;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public abstract class AbstractMdsalTestBase extends AbstractConfigTestBase implements BindingAwareProvider {
+public abstract class AbstractMdsalTestBase implements BindingAwareProvider {
 
     private static final Logger LOG = LoggerFactory.getLogger(AbstractMdsalTestBase.class);
+    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";
+    private static final String KARAF_DEBUG_PROP = "karaf.debug";
+    private static final String KEEP_UNPACK_DIRECTORY_PROP = "karaf.keep.unpack";
     private static final int REGISTRATION_TIMEOUT = 70000;
-    @Inject @Filter(timeout=60000)
+
+    /*
+     * Default values for karaf distro type, groupId, and artifactId
+     */
+    private static final String KARAF_DISTRO_TYPE = "zip";
+    private static final String KARAF_DISTRO_ARTIFACTID = "opendaylight-karaf-empty";
+    private static final String KARAF_DISTRO_GROUPID = "org.opendaylight.odlparent";
+
+    /*
+     * Property names to override defaults for karaf distro artifactId, groupId,
+     * version, and type
+     */
+    private static final String KARAF_DISTRO_VERSION_PROP = "karaf.distro.version";
+    private static final String KARAF_DISTRO_TYPE_PROP = "karaf.distro.type";
+    private static final String KARAF_DISTRO_ARTIFACTID_PROP = "karaf.distro.artifactId";
+    private static final String KARAF_DISTRO_GROUPID_PROP = "karaf.distro.groupId";
+
+    public static final String ORG_OPS4J_PAX_LOGGING_CFG = "etc/org.ops4j.pax.logging.cfg";
+
+    @Inject @Filter(timeout = 60000)
     private BundleContext context;
-    @Inject @Filter(timeout=60000)
+    @Inject @Filter(timeout = 60000)
     private BindingAwareBroker broker;
     private ProviderContext session = null;
 
@@ -39,20 +76,22 @@ public abstract class AbstractMdsalTestBase extends AbstractConfigTestBase imple
         return session;
     }
 
+    public abstract MavenUrlReference getFeatureRepo();
+
+    public abstract String getFeatureName();
+
     @Override
     public void onSessionInitiated(ProviderContext session) {
         LOG.info("Session Initiated: {}",session);
         this.session = session;
     }
 
-    @Override
     @Before
     public void setup() throws Exception {
-        super.setup();
         long start = System.nanoTime();
         broker.registerProvider(this);
-        for(int i=0;i<REGISTRATION_TIMEOUT;i++) {
-            if(session !=null) {
+        for (int i = 0; i < REGISTRATION_TIMEOUT; i++) {
+            if (session != null) {
                 long stop = System.nanoTime();
                 LOG.info("Registered session {} with the MD-SAL after {} ns",
                         session,
@@ -65,7 +104,6 @@ public abstract class AbstractMdsalTestBase extends AbstractConfigTestBase imple
         throw new RuntimeException("Session not initiated after " + REGISTRATION_TIMEOUT + " ms");
     }
 
-    @Override
     public Option getLoggingOption() {
         Option option = editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
                 "log4j2.logger.mdsal-it-base.name",
@@ -73,8 +111,58 @@ public abstract class AbstractMdsalTestBase extends AbstractConfigTestBase imple
         option = composite(option, editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
                 "log4j2.logger.mdsal-it-base.level",
                 LogLevel.INFO.name()));
-        option = composite(option, super.getLoggingOption());
         return option;
     }
 
+    /**
+     * Override this method to provide more options to config.
+     *
+     * @return An array of additional config options
+     */
+    protected Option[] getAdditionalOptions() {
+        return null;
+    }
+
+    /**
+     * Returns a Log4J logging configuration property name for the given class's package name of the form
+     * "log4j.logger.package_name".
+     *
+     * @deprecated The karaf logging provider is now Log4J2 so logging configurations must conform to the Log4J2 style.
+     *     This method is kept for compilation backwards compatibility but will be removed in a future release.
+     */
+    @Deprecated
+    public String logConfiguration(final Class<?> klazz) {
+        return "log4j.logger." + klazz.getPackage().getName();
+    }
+
+    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 type = System.getProperty(KARAF_DISTRO_TYPE_PROP, KARAF_DISTRO_TYPE);
+
+        return maven().groupId(groupId).artifactId(artifactId).versionAsInProject().type(type).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[] {
+                when(Boolean.getBoolean(KARAF_DEBUG_PROP))
+                        .useOptions(KarafDistributionOption.debugConfiguration(KARAF_DEBUG_PORT, true)),
+                karafDistributionConfiguration().frameworkUrl(getKarafDistro())
+                        .unpackDirectory(new File(PAX_EXAM_UNPACK_DIRECTORY)).useDeployFolder(false),
+                when(Boolean.getBoolean(KEEP_UNPACK_DIRECTORY_PROP)).useOptions(keepRuntimeFolder()),
+                features(getFeatureRepo(), getFeatureName()),
+                //mavenBundle("org.apache.aries.quiesce", "org.apache.aries.quiesce.api", "1.0.0"), getLoggingOption(),
+                mvnLocalRepoOption(),
+                configureConsole().ignoreLocalConsole().ignoreRemoteShell(),
+                editConfigurationFilePut(ETC_ORG_OPS4J_PAX_LOGGING_CFG, "log4j2.rootLogger.level", "INFO") };
+        return OptionUtils.combine(options, getAdditionalOptions());
+    }
 }
index 7f835bd..571037e 100644 (file)
@@ -26,7 +26,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
     <mdsal.version>1.8.0-SNAPSHOT</mdsal.version>
     <karaf.distro.groupId>org.opendaylight.odlparent</karaf.distro.groupId>
     <karaf.distro.artifactId>opendaylight-karaf-empty</karaf.distro.artifactId>
-    <karaf.distro.version>3.1.0</karaf.distro.version>
     <karaf.distro.type>zip</karaf.distro.type>
     <karaf.keep.unpack>false</karaf.keep.unpack>
   </properties>
@@ -205,7 +204,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
            <configuration>
             <outputDirectory>${project.build.directory}/test-classes</outputDirectory>
             <groupId>org.opendaylight.controller</groupId>
-            <includeArtifactIds>mockito-core,objenesis,config-it-base,mdsal-it-base</includeArtifactIds>
+            <includeArtifactIds>mockito-core,objenesis,mdsal-it-base</includeArtifactIds>
             <excludes>META-INF\/**</excludes>
             <ignorePermissions>false</ignorePermissions>
            </configuration>

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.