Use mdsal's base IT classes 68/25968/2
authorStephen Kitt <skitt@redhat.com>
Tue, 25 Aug 2015 14:45:45 +0000 (16:45 +0200)
committerStephen Kitt <skitt@redhat.com>
Tue, 25 Aug 2015 15:34:30 +0000 (17:34 +0200)
Change-Id: I25138bbe1565cf6e33ab67e847ef878b39a624f7
Signed-off-by: Stephen Kitt <skitt@redhat.com>
openstack/net-virt-it/pom.xml
openstack/net-virt-it/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/it/AbstractConfigTestBase.java [deleted file]
openstack/net-virt-it/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/it/AbstractMdsalTestBase.java [deleted file]
openstack/net-virt-it/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/it/NetvirtIT.java
southbound/southbound-it/pom.xml
southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/AbstractConfigTestBase.java [deleted file]
southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/AbstractMdsalTestBase.java [deleted file]
southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java

index a2c1d9e3fad271ca5a05c3c3fdd89234f7d42181..3abe1c2ec0daf68273a21731a33af097715baa61 100644 (file)
@@ -10,8 +10,8 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
 
   <parent>
     <groupId>org.opendaylight.controller</groupId>
-    <artifactId>config-parent</artifactId>
-    <version>0.4.0-SNAPSHOT</version>
+    <artifactId>mdsal-it-parent</artifactId>
+    <version>1.3.0-SNAPSHOT</version>
     <relativePath/>
   </parent>
   <modelVersion>4.0.0</modelVersion>
diff --git a/openstack/net-virt-it/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/it/AbstractConfigTestBase.java b/openstack/net-virt-it/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/it/AbstractConfigTestBase.java
deleted file mode 100644 (file)
index e08c32e..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Copyright (C) 2015 Red Hat, Inc. and others
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.ovsdb.openstack.netvirt.it;
-
-import static org.ops4j.pax.exam.CoreOptions.maven;
-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 com.google.common.collect.ObjectArrays;
-import java.io.File;
-import java.lang.management.ManagementFactory;
-import java.util.Calendar;
-import javax.management.InstanceNotFoundException;
-import org.junit.Rule;
-import org.junit.internal.AssumptionViolatedException;
-import org.junit.rules.TestRule;
-import org.junit.rules.TestWatcher;
-import org.junit.runner.Description;
-import org.opendaylight.controller.config.api.ConfigRegistry;
-import org.opendaylight.controller.config.util.ConfigRegistryJMXClient;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
-import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
-import org.ops4j.pax.exam.options.MavenUrlReference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-//import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
-
-/**
- * @author Sam Hague (shague@redhat.com)
- */
-public abstract class AbstractConfigTestBase {
-    private static final Logger LOG = LoggerFactory.getLogger(AbstractConfigTestBase.class);
-
-    /*
-     * Wait up to 10s for our configured module to come up
-     */
-    private static final int MODULE_TIMEOUT = 10000;
-    private static int configTimes = 0;
-
-    public abstract String getModuleName();
-
-    public abstract String getInstanceName();
-
-    public abstract MavenUrlReference getFeatureRepo();
-
-    public abstract String getFeatureName();
-
-    public Option[] getLoggingOptions() {
-        Option[] options = new Option[] {
-                editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
-                        logConfiguration(AbstractConfigTestBase.class),
-                        LogLevel.INFO.name())
-        };
-        return options;
-    }
-
-    public String logConfiguration(Class<?> klazz) {
-        return "log4j.logger." + klazz.getPackage().getName();
-    }
-
-    public Option[] getFeaturesOptions() {
-        return new Option[]{};
-    }
-
-    public Option[] getPropertiesOptions() {
-        return new Option[]{};
-    }
-
-    public MavenArtifactUrlReference getKarafDistro() {
-        MavenArtifactUrlReference karafUrl;
-        /*karafUrl = maven()
-                .groupId("org.opendaylight.controller")
-                .artifactId("opendaylight-karaf-empty")
-                .version("1.5.0-SNAPSHOT")
-                .type("zip");*/
-
-        karafUrl = maven()
-                .groupId("org.opendaylight.ovsdb")
-                .artifactId("karaf")
-                .versionAsInProject()
-                .type("zip");
-
-        return karafUrl;
-    }
-
-    @Configuration
-    public Option[] config() {
-        LOG.info("Calling config, configTimes: {}", configTimes);
-        configTimes++;
-        Option[] options = new Option[] {
-                //KarafDistributionOption.debugConfiguration("5005", true),
-                karafDistributionConfiguration()
-                        .frameworkUrl(getKarafDistro())
-                        .unpackDirectory(new File("target/exam"))
-                        .useDeployFolder(false),
-                keepRuntimeFolder(),
-                //features(getFeatureRepo() , getFeatureName())
-        };
-        options = ObjectArrays.concat(options, getFeaturesOptions(), Option.class);
-        options = ObjectArrays.concat(options, getLoggingOptions(), Option.class);
-        options = ObjectArrays.concat(options, getPropertiesOptions(), Option.class);
-        return options;
-    }
-
-    public void setup() throws Exception {
-        LOG.info("Module: {} Instance: {} attempting to configure.",
-                getModuleName(),getInstanceName());
-        Calendar start = Calendar.getInstance();
-        ConfigRegistry configRegistryClient = new ConfigRegistryJMXClient(ManagementFactory
-                .getPlatformMBeanServer());
-        for (int timer = 0;timer < MODULE_TIMEOUT;timer++) {
-            try {
-                configRegistryClient.lookupConfigBean(getModuleName(), getInstanceName());
-                Thread.sleep(100);
-            } catch (InstanceNotFoundException e) {
-                if (timer >= MODULE_TIMEOUT) {
-                    throw e;
-                }
-            } catch (InterruptedException e) {
-                LOG.error("Exception: ",e);
-            }
-        }
-        Calendar stop = Calendar.getInstance();
-        LOG.info("Module: {} Instance: {} configured after {} ms",
-                getModuleName(),getInstanceName(),
-                stop.getTimeInMillis() - start.getTimeInMillis());
-    }
-
-    @Rule
-    public TestRule watcher = new TestWatcher() {
-        @Override
-        protected void starting(Description description) {
-            LOG.info("TestWatcher: Starting test:\n{}", description.getDisplayName());
-        }
-
-        @Override
-        protected void finished(Description description) {
-            LOG.info("TestWatcher: Finished test:\n{}", description.getDisplayName());
-        }
-
-        @Override
-        protected void succeeded(Description description) {
-            LOG.info("TestWatcher: Test succeeded:\n{}", description.getDisplayName());
-        }
-
-        @Override
-        protected void failed(Throwable ex, Description description) {
-            LOG.info("TestWatcher: Test failed:\n{} ", description.getDisplayName(), ex);
-        }
-
-        @Override
-        protected void skipped(AssumptionViolatedException ex, Description description) {
-            LOG.info("TestWatcher: Test skipped:\n{} ", description.getDisplayName(), ex);
-        }
-    };
-}
diff --git a/openstack/net-virt-it/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/it/AbstractMdsalTestBase.java b/openstack/net-virt-it/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/it/AbstractMdsalTestBase.java
deleted file mode 100644 (file)
index c2526c9..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2015 Red Hat, Inc. and others
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.ovsdb.openstack.netvirt.it;
-
-import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
-
-import com.google.common.collect.ObjectArrays;
-import java.util.Calendar;
-import javax.inject.Inject;
-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.Option;
-import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
-import org.ops4j.pax.exam.util.Filter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class AbstractMdsalTestBase extends AbstractConfigTestBase implements BindingAwareProvider {
-
-    private static final Logger LOG = LoggerFactory.getLogger(AbstractMdsalTestBase.class);
-    private static final int REGISTRATION_TIMEOUT = 10000;
-    @Inject @Filter(timeout = 120000)
-    private BindingAwareBroker broker;
-    private ProviderContext session = null;
-
-    public ProviderContext getSession() {
-        return session;
-    }
-
-    @Override
-    public void onSessionInitiated(ProviderContext session) {
-        LOG.info("Session Initiated: {}",session);
-        this.session = session;
-    }
-
-    @Override
-    public void setup() throws Exception {
-        super.setup();
-        Calendar start = Calendar.getInstance();
-        broker.registerProvider(this);
-        for (int timer = 0;timer < REGISTRATION_TIMEOUT;timer++) {
-            if (session != null) {
-                Calendar stop = Calendar.getInstance();
-                LOG.info("Registered with the MD-SAL after {} ms",
-                        stop.getTimeInMillis() - start.getTimeInMillis());
-                return;
-            } else {
-                Thread.sleep(1);
-            }
-        }
-        throw new RuntimeException("Session not initiated after " + REGISTRATION_TIMEOUT + " ms");
-    }
-
-    @Override
-    public Option[] getLoggingOptions() {
-        Option[] options = new Option[] {
-                editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
-                        logConfiguration(AbstractMdsalTestBase.class),
-                        LogLevel.INFO.name()),
-        };
-        options = ObjectArrays.concat(options, super.getLoggingOptions(), Option.class);
-        return options;
-    }
-
-}
index 06cd44113631fd52309c026b8a2b68fbe680e78a..9d8cab55e70c7495006d1891a895e212004ebd80 100644 (file)
@@ -8,12 +8,19 @@
 package org.opendaylight.ovsdb.openstack.netvirt.it;
 
 import static org.junit.Assert.fail;
+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.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 com.google.common.collect.ImmutableBiMap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.ObjectArrays;
+
+import java.io.File;
 import java.net.InetAddress;
 import java.net.NetworkInterface;
 import java.net.UnknownHostException;
@@ -30,6 +37,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
 import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
@@ -54,6 +62,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.karaf.options.KarafDistributionOption;
 import org.ops4j.pax.exam.karaf.options.LogLevelOption;
 import org.ops4j.pax.exam.options.MavenUrlReference;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
@@ -83,12 +92,42 @@ public class NetvirtIT extends AbstractMdsalTestBase {
     private static final String NETVIRT = "org.opendaylight.ovsdb.openstack.net-virt";
     private static final String NETVIRTPROVIDERS = "org.opendaylight.ovsdb.openstack.net-virt-providers";
 
+    // TODO Constants copied frmo AbstractConfigTestBase, need to be removed (see TODO below)
+    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";
+
     @Inject
     private BundleContext bundleContext;
 
     @Configuration
     public Option[] config() {
-        return super.config();
+        // TODO Figure out how to use the parent Karaf setup, then just use super.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()),
+                // Works only if we don't specify the feature repo and name
+                getLoggingOption()};
+        Option[] propertyOptions = getPropertiesOptions();
+        Option[] combinedOptions = new Option[options.length + propertyOptions.length];
+        System.arraycopy(options, 0, combinedOptions, 0, options.length);
+        System.arraycopy(propertyOptions, 0, combinedOptions, options.length, propertyOptions.length);
+        return combinedOptions;
+    }
+
+    @Override
+    public String getKarafDistro() {
+        return maven()
+                .groupId("org.opendaylight.ovsdb")
+                .artifactId("karaf")
+                .versionAsInProject()
+                .type("zip")
+                .getURL();
     }
 
     @Override
@@ -123,32 +162,21 @@ public class NetvirtIT extends AbstractMdsalTestBase {
     }
 
     @Override
-    public Option[] getFeaturesOptions() {
-        return new Option[]{};
-    }
-
-    @Override
-    public Option[] getLoggingOptions() {
-        Option[] options;
-
-        options = new Option[] {
-            editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
-                    "log4j.logger.org.opendaylight.ovsdb",
-                    LogLevelOption.LogLevel.DEBUG.name()),
-            editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
-                    "log4j.logger.org.opendaylight.ovsdb.lib",
-                    LogLevelOption.LogLevel.INFO.name()),
+    public Option getLoggingOption() {
+        return composite(
+                editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
+                        "log4j.logger.org.opendaylight.ovsdb",
+                        LogLevelOption.LogLevel.DEBUG.name()),
+                editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
+                        "log4j.logger.org.opendaylight.ovsdb.lib",
+                        LogLevelOption.LogLevel.INFO.name()),
+                super.getLoggingOption());
             /*editConfigurationFilePut(NetvirtITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
                     "log4j.logger.org.opendaylight.ovsdb.openstack.net-virt",
                     LogLevelOption.LogLevel.DEBUG.name())*/
-        };
-
-        options = ObjectArrays.concat(options, super.getLoggingOptions(), Option.class);
-        return options;
     }
 
-    @Override
-    public Option[] getPropertiesOptions() {
+    private Option[] getPropertiesOptions() {
         Properties props = new Properties(System.getProperties());
         String addressStr = props.getProperty(NetvirtITConstants.SERVER_IPADDRESS,
                 NetvirtITConstants.DEFAULT_SERVER_IPADDRESS);
@@ -172,7 +200,8 @@ public class NetvirtIT extends AbstractMdsalTestBase {
     }
 
     @Before
-    public void setUp() throws InterruptedException {
+    @Override
+    public void setup() throws InterruptedException {
         if (setup.get()) {
             LOG.info("Skipping setUp, already initialized");
             return;
index 954752f1a38241d61ed748b8c389699d5e719e39..8240fb7f5e42fdca84f5f14724786c4a5f3dbd41 100644 (file)
@@ -10,8 +10,8 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
 
   <parent>
     <groupId>org.opendaylight.controller</groupId>
-    <artifactId>config-parent</artifactId>
-    <version>0.4.0-SNAPSHOT</version>
+    <artifactId>mdsal-it-parent</artifactId>
+    <version>1.3.0-SNAPSHOT</version>
     <relativePath/>
   </parent>
   <modelVersion>4.0.0</modelVersion>
diff --git a/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/AbstractConfigTestBase.java b/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/AbstractConfigTestBase.java
deleted file mode 100644 (file)
index f4f8053..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.ovsdb.southbound.it;
-
-import static org.ops4j.pax.exam.CoreOptions.maven;
-import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
-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 java.lang.management.ManagementFactory;
-import java.util.Calendar;
-
-import javax.management.InstanceNotFoundException;
-
-import org.junit.Rule;
-import org.junit.internal.AssumptionViolatedException;
-import org.junit.rules.TestRule;
-import org.junit.rules.TestWatcher;
-import org.junit.runner.Description;
-import org.opendaylight.controller.config.api.ConfigRegistry;
-import org.opendaylight.controller.config.util.ConfigRegistryJMXClient;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
-import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
-import org.ops4j.pax.exam.options.MavenUrlReference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.ObjectArrays;
-
-public abstract class AbstractConfigTestBase {
-    private static final Logger LOG = LoggerFactory.getLogger(AbstractConfigTestBase.class);
-
-    /*
-     * Wait up to 10s for our configured module to come up
-     */
-    private static final int MODULE_TIMEOUT = 10000;
-    private static int configTimes = 0;
-
-    public abstract String getModuleName();
-
-    public abstract String getInstanceName();
-
-    public abstract MavenUrlReference getFeatureRepo();
-
-    public abstract String getFeatureName();
-
-    public Option[] getLoggingOptions() {
-        Option[] options = new Option[] {
-                editConfigurationFilePut(SouthboundITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
-                        logConfiguration(AbstractConfigTestBase.class),
-                        LogLevel.INFO.name())
-        };
-        return options;
-    }
-
-    public String logConfiguration(Class<?> klazz) {
-        return "log4j.logger." + klazz.getPackage().getName();
-    }
-
-    public Option[] getFeaturesOptions() {
-        return new Option[]{};
-    }
-
-    public Option[] getPropertiesOptions() {
-        return new Option[]{};
-    }
-
-    public MavenArtifactUrlReference getKarafDistro() {
-        MavenArtifactUrlReference karafUrl;
-        karafUrl = maven()
-                // karaf-empty is busted
-                //.groupId("org.opendaylight.controller")
-                //.artifactId("opendaylight-karaf-empty")
-                //.version("1.5.0-SNAPSHOT")
-                .groupId("org.opendaylight.ovsdb")
-                .artifactId("southbound-karaf")
-                .versionAsInProject()
-                .type("zip");
-        return karafUrl;
-    }
-
-    @Configuration
-    public Option[] config() {
-        LOG.info("Calling config, configTimes: {}", configTimes);
-        configTimes++;
-        Option[] options = new Option[] {
-                //KarafDistributionOption.debugConfiguration("5005", true),
-                karafDistributionConfiguration()
-                        .frameworkUrl(getKarafDistro())
-                        .unpackDirectory(new File("target/exam"))
-                        .useDeployFolder(false),
-                keepRuntimeFolder(),
-                //debugConfiguration("5005", true),
-                //features(getFeatureRepo() , getFeatureName())
-        };
-        options = ObjectArrays.concat(options, getFeaturesOptions(), Option.class);
-        options = ObjectArrays.concat(options, getLoggingOptions(), Option.class);
-        options = ObjectArrays.concat(options, getPropertiesOptions(), Option.class);
-        return options;
-    }
-
-    public void setup() throws Exception {
-        LOG.info("Module: {} Instance: {} attempting to configure.",
-                getModuleName(),getInstanceName());
-        Calendar start = Calendar.getInstance();
-        ConfigRegistry configRegistryClient = new ConfigRegistryJMXClient(ManagementFactory
-                .getPlatformMBeanServer());
-        for (int timer = 0;timer < MODULE_TIMEOUT;timer++) {
-            try {
-                configRegistryClient.lookupConfigBean(getModuleName(), getInstanceName());
-                Thread.sleep(1);
-            } catch (InstanceNotFoundException e) {
-                if (timer >= MODULE_TIMEOUT) {
-                    throw e;
-                }
-            } catch (InterruptedException e) {
-                LOG.error("Exception: ",e);
-            }
-        }
-        Calendar stop = Calendar.getInstance();
-        LOG.info("Module: {} Instance: {} configured after {} ms",
-                getModuleName(),getInstanceName(),
-                stop.getTimeInMillis() - start.getTimeInMillis());
-    }
-
-    @Rule
-    public TestRule watcher = new TestWatcher() {
-        @Override
-        protected void starting(Description description) {
-            LOG.info("TestWatcher: Starting test:\n{}", description.getDisplayName());
-        }
-
-        @Override
-        protected void finished(Description description) {
-            LOG.info("TestWatcher: Finished test:\n{}", description.getDisplayName());
-        }
-
-        @Override
-        protected void succeeded(Description description) {
-            LOG.info("TestWatcher: Test succeeded:\n{}", description.getDisplayName());
-        }
-
-        @Override
-        protected void failed(Throwable ex, Description description) {
-            LOG.info("TestWatcher: Test failed:\n{} ", description.getDisplayName(), ex);
-        }
-
-        @Override
-        protected void skipped(AssumptionViolatedException ex, Description description) {
-            LOG.info("TestWatcher: Test skipped:\n{} ", description.getDisplayName(), ex);
-        }
-    };
-}
diff --git a/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/AbstractMdsalTestBase.java b/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/AbstractMdsalTestBase.java
deleted file mode 100644 (file)
index 72f0c24..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.ovsdb.southbound.it;
-
-import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
-
-import java.util.Calendar;
-
-import javax.inject.Inject;
-
-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.Option;
-import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
-import org.ops4j.pax.exam.util.Filter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.ObjectArrays;
-
-public abstract class AbstractMdsalTestBase extends AbstractConfigTestBase implements BindingAwareProvider {
-
-    private static final Logger LOG = LoggerFactory.getLogger(AbstractMdsalTestBase.class);
-    private static final int REGISTRATION_TIMEOUT = 10000;
-    @Inject @Filter(timeout = 60000)
-    private BindingAwareBroker broker;
-    private ProviderContext session = null;
-
-    public ProviderContext getSession() {
-        return session;
-    }
-
-    @Override
-    public void onSessionInitiated(ProviderContext session) {
-        LOG.info("Session Initiated: {}",session);
-        this.session = session;
-    }
-
-    @Override
-    public void setup() throws Exception {
-        super.setup();
-        Calendar start = Calendar.getInstance();
-        broker.registerProvider(this);
-        for (int timer = 0;timer < REGISTRATION_TIMEOUT;timer++) {
-            if (session != null) {
-                Calendar stop = Calendar.getInstance();
-                LOG.info("Registered with the MD-SAL after {} ms",
-                        stop.getTimeInMillis() - start.getTimeInMillis());
-                return;
-            } else {
-                Thread.sleep(1);
-            }
-        }
-        throw new RuntimeException("Session not initiated after " + REGISTRATION_TIMEOUT + " ms");
-    }
-
-    @Override
-    public Option[] getLoggingOptions() {
-        Option[] options = new Option[] {
-                editConfigurationFilePut(SouthboundITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
-                        logConfiguration(AbstractMdsalTestBase.class),
-                        LogLevel.INFO.name()),
-        };
-        options = ObjectArrays.concat(options, super.getLoggingOptions(), Option.class);
-        return options;
-    }
-
-}
index ae3aa7d9f3b3642dec4db3653fdfe26c423e993e..b3ef1a4b21f207aba8f7fb8b75460acf8fdd3ecf 100644 (file)
@@ -9,15 +9,19 @@ package org.opendaylight.ovsdb.southbound.it;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
+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.editConfigurationFilePut;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
 
 import com.google.common.collect.ImmutableBiMap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
-import com.google.common.collect.ObjectArrays;
 import com.google.common.collect.Sets;
 
+import java.io.File;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
@@ -36,6 +40,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
 import org.opendaylight.ovsdb.southbound.SouthboundProvider;
@@ -97,6 +102,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.karaf.options.KarafDistributionOption;
 import org.ops4j.pax.exam.karaf.options.LogLevelOption;
 import org.ops4j.pax.exam.options.MavenUrlReference;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
@@ -125,12 +131,42 @@ public class SouthboundIT extends AbstractMdsalTestBase {
     private static Boolean setup = false;
     private static MdsalUtils mdsalUtils = null;
 
+    // TODO Constants copied frmo AbstractConfigTestBase, need to be removed (see TODO below)
+    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";
+
     @Inject
     private BundleContext bundleContext;
 
     @Configuration
     public Option[] config() {
-        return super.config();
+        // TODO Figure out how to use the parent Karaf setup, then just use super.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()),
+                // Works only if we don't specify the feature repo and name
+                getLoggingOption()};
+        Option[] propertyOptions = getPropertiesOptions();
+        Option[] combinedOptions = new Option[options.length + propertyOptions.length];
+        System.arraycopy(options, 0, combinedOptions, 0, options.length);
+        System.arraycopy(propertyOptions, 0, combinedOptions, options.length, propertyOptions.length);
+        return combinedOptions;
+    }
+
+    @Override
+    public String getKarafDistro() {
+        return maven()
+                .groupId("org.opendaylight.ovsdb")
+                .artifactId("southbound-karaf")
+                .versionAsInProject()
+                .type("zip")
+                .getURL();
     }
 
     @Override
@@ -165,24 +201,15 @@ public class SouthboundIT extends AbstractMdsalTestBase {
     }
 
     @Override
-    public Option[] getFeaturesOptions() {
-        return new Option[]{};
-    }
-
-    @Override
-    public Option[] getLoggingOptions() {
-        Option[] options = new Option[] {
+    public Option getLoggingOption() {
+        return composite(
                 editConfigurationFilePut(SouthboundITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
                         "log4j.logger.org.opendaylight.ovsdb",
-                        LogLevelOption.LogLevel.TRACE.name())
-        };
-
-        options = ObjectArrays.concat(options, super.getLoggingOptions(), Option.class);
-        return options;
+                        LogLevelOption.LogLevel.TRACE.name()),
+                super.getLoggingOption());
     }
 
-    @Override
-    public Option[] getPropertiesOptions() {
+    private Option[] getPropertiesOptions() {
         Properties props = new Properties(System.getProperties());
         String addressStr = props.getProperty(SouthboundITConstants.SERVER_IPADDRESS,
                 SouthboundITConstants.DEFAULT_SERVER_IPADDRESS);
@@ -206,8 +233,9 @@ public class SouthboundIT extends AbstractMdsalTestBase {
     }
 
     @Before
-    public void setUp() throws InterruptedException {
-        if (setup == true) {
+    @Override
+    public void setup() throws InterruptedException {
+        if (setup) {
             LOG.info("Skipping setUp, already initialized");
             return;
         }