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.rules.TestRule;
26 import org.junit.rules.TestWatcher;
27 import org.junit.runner.Description;
28 import org.opendaylight.controller.config.api.ConfigRegistry;
29 import org.opendaylight.controller.config.util.ConfigRegistryJMXClient;
30 import org.ops4j.pax.exam.Configuration;
31 import org.ops4j.pax.exam.Option;
32 import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
33 import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
34 import org.ops4j.pax.exam.options.MavenUrlReference;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
38 public abstract class AbstractConfigTestBase {
39 private static final Logger LOG = LoggerFactory.getLogger(AbstractConfigTestBase.class);
42 * Wait up to 10s for our configured module to come up
44 private static final int MODULE_TIMEOUT = 10000;
46 public abstract String getModuleName();
48 public abstract String getInstanceName();
50 public abstract MavenUrlReference getFeatureRepo();
52 public abstract String getFeatureName();
54 public Option[] getLoggingOptions() {
55 Option[] options = new Option[] {
56 editConfigurationFilePut(SouthboundITConstants.ORG_OPS4J_PAX_LOGGING_CFG,
57 logConfiguration(AbstractConfigTestBase.class),
63 public String logConfiguration(Class<?> klazz) {
64 return "log4j.logger." + klazz.getPackage().getName();
67 public Option[] getFeaturesOptions() {
68 return new Option[]{};
71 public Option[] getPropertiesOptions() {
72 return new Option[]{};
75 public MavenArtifactUrlReference getKarafDistro() {
76 /*MavenArtifactUrlReference karafUrl = maven()
77 .groupId("org.opendaylight.controller")
78 .artifactId("opendaylight-karaf-empty")
79 .version("1.5.0-SNAPSHOT")
81 MavenArtifactUrlReference karafUrl = maven()
82 .groupId("org.opendaylight.ovsdb")
83 .artifactId("southbound-karaf")
84 .version("1.1.0-SNAPSHOT")
90 public Option[] config() {
91 Option[] options = new Option[] {
92 // KarafDistributionOption.debugConfiguration("5005", true),
93 karafDistributionConfiguration()
94 .frameworkUrl(getKarafDistro())
95 .unpackDirectory(new File("target/exam"))
96 .useDeployFolder(false),
98 //features(getFeatureRepo() , getFeatureName())
100 options = ObjectArrays.concat(options, getFeaturesOptions(), Option.class);
101 options = ObjectArrays.concat(options, getLoggingOptions(), Option.class);
102 options = ObjectArrays.concat(options, getPropertiesOptions(), Option.class);
106 public void setup() throws Exception {
107 LOG.info("Module: {} Instance: {} attempting to configure.",
108 getModuleName(),getInstanceName());
109 Calendar start = Calendar.getInstance();
110 ConfigRegistry configRegistryClient = new ConfigRegistryJMXClient(ManagementFactory
111 .getPlatformMBeanServer());
112 for (int timer = 0;timer < MODULE_TIMEOUT;timer++) {
114 configRegistryClient.lookupConfigBean(getModuleName(), getInstanceName());
116 } catch (InstanceNotFoundException e) {
117 if (timer >= MODULE_TIMEOUT) {
120 } catch (InterruptedException e) {
121 LOG.error("Exception: ",e);
124 Calendar stop = Calendar.getInstance();
125 LOG.info("Module: {} Instance: {} configured after {} ms",
126 getModuleName(),getInstanceName(),
127 stop.getTimeInMillis() - start.getTimeInMillis());
131 public TestRule watcher = new TestWatcher() {
133 protected void starting(Description description) {
134 LOG.info("TestWatcher: Starting test: {}",
135 description.getDisplayName());
139 protected void finished(Description description) {
140 LOG.info("TestWatcher: Finished test: {}", description.getDisplayName());