2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.ovsdb.southbound.it;
10 import static org.ops4j.pax.exam.CoreOptions.maven;
11 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
12 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
13 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
14 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
16 import com.google.common.collect.ObjectArrays;
19 import java.lang.management.ManagementFactory;
20 import java.util.Calendar;
22 import javax.management.InstanceNotFoundException;
24 import org.junit.Rule;
25 import org.junit.internal.AssumptionViolatedException;
26 import org.junit.rules.TestRule;
27 import org.junit.rules.TestWatcher;
28 import org.junit.runner.Description;
29 import org.opendaylight.controller.config.api.ConfigRegistry;
30 import org.opendaylight.controller.config.util.ConfigRegistryJMXClient;
31 import org.ops4j.pax.exam.Configuration;
32 import org.ops4j.pax.exam.Option;
33 import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
34 import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
35 import org.ops4j.pax.exam.options.MavenUrlReference;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
39 public abstract class AbstractConfigTestBase {
40 private static final Logger LOG = LoggerFactory.getLogger(AbstractConfigTestBase.class);
43 * Wait up to 10s for our configured module to come up
45 private static final int MODULE_TIMEOUT = 10000;
47 public abstract String getModuleName();
49 public abstract String getInstanceName();
51 public abstract MavenUrlReference getFeatureRepo();
53 public abstract String getFeatureName();
55 public void setExtras() {}
57 public Option[] getLoggingOptions() {
58 Option[] options = new Option[] {
59 editConfigurationFilePut(SouthboundITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
60 logConfiguration(AbstractConfigTestBase.class),
66 public String logConfiguration(Class<?> klazz) {
67 return "log4j.logger." + klazz.getPackage().getName();
70 public Option[] getFeaturesOptions() {
71 return new Option[]{};
74 public Option[] getPropertiesOptions() {
75 return new Option[]{};
78 public MavenArtifactUrlReference getKarafDistro() {
79 /*MavenArtifactUrlReference karafUrl = maven()
80 .groupId("org.opendaylight.controller")
81 .artifactId("opendaylight-karaf-empty")
82 .version("1.5.0-SNAPSHOT")
84 MavenArtifactUrlReference karafUrl = maven()
85 .groupId("org.opendaylight.ovsdb")
86 //.artifactId("southbound-karaf")
88 .version("1.1.0-SNAPSHOT")
94 public Option[] config() {
96 Option[] options = new Option[] {
97 // KarafDistributionOption.debugConfiguration("5005", true),
98 karafDistributionConfiguration()
99 .frameworkUrl(getKarafDistro())
100 .unpackDirectory(new File("target/exam"))
101 .useDeployFolder(false),
103 //features(getFeatureRepo() , getFeatureName())
105 //options = ObjectArrays.concat(options, getFeaturesOptions(), Option.class);
106 options = ObjectArrays.concat(options, getLoggingOptions(), Option.class);
107 options = ObjectArrays.concat(options, getPropertiesOptions(), Option.class);
108 LOG.info("options: {}", options);
112 public void setup() throws Exception {
113 LOG.info("Module: {} Instance: {} attempting to configure.",
114 getModuleName(),getInstanceName());
115 Calendar start = Calendar.getInstance();
116 ConfigRegistry configRegistryClient = new ConfigRegistryJMXClient(ManagementFactory
117 .getPlatformMBeanServer());
118 for (int timer = 0;timer < MODULE_TIMEOUT;timer++) {
120 configRegistryClient.lookupConfigBean(getModuleName(), getInstanceName());
122 } catch (InstanceNotFoundException e) {
123 if (timer >= MODULE_TIMEOUT) {
126 } catch (InterruptedException e) {
127 LOG.error("Exception: ",e);
130 Calendar stop = Calendar.getInstance();
131 LOG.info("Module: {} Instance: {} configured after {} ms",
132 getModuleName(),getInstanceName(),
133 stop.getTimeInMillis() - start.getTimeInMillis());
137 public TestRule watcher = new TestWatcher() {
139 protected void starting(Description description) {
140 LOG.info("TestWatcher: Starting test:\n{}", description.getDisplayName());
144 protected void finished(Description description) {
145 LOG.info("TestWatcher: Finished test:\n{}", description.getDisplayName());
149 protected void succeeded(Description description) {
150 LOG.info("TestWatcher: Test succeeded:\n{}", description.getDisplayName());
154 protected void failed(Throwable ex, Description description) {
155 LOG.info("TestWatcher: Test failed:\n{} ", description.getDisplayName(), ex);
159 protected void skipped(AssumptionViolatedException ex, Description description) {
160 LOG.info("TestWatcher: Test skipped:\n{} ", description.getDisplayName(), ex);