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
9 package org.opendaylight.controller.mdsal.it.base;
11 import static org.ops4j.pax.exam.CoreOptions.composite;
12 import static org.ops4j.pax.exam.CoreOptions.maven;
13 import static org.ops4j.pax.exam.CoreOptions.when;
14 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
15 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
16 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
17 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
18 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
21 import javax.inject.Inject;
22 import org.junit.Before;
23 import org.ops4j.pax.exam.Configuration;
24 import org.ops4j.pax.exam.Option;
25 import org.ops4j.pax.exam.OptionUtils;
26 import org.ops4j.pax.exam.karaf.options.KarafDistributionOption;
27 import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
28 import org.ops4j.pax.exam.options.MavenUrlReference;
29 import org.ops4j.pax.exam.util.Filter;
30 import org.osgi.framework.BundleContext;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public abstract class AbstractMdsalTestBase {
36 private static final Logger LOG = LoggerFactory.getLogger(AbstractMdsalTestBase.class);
37 private static final String MAVEN_REPO_LOCAL = "maven.repo.local";
38 private static final String ORG_OPS4J_PAX_URL_MVN_LOCAL_REPOSITORY = "org.ops4j.pax.url.mvn.localRepository";
39 private static final String ETC_ORG_OPS4J_PAX_URL_MVN_CFG = "etc/org.ops4j.pax.url.mvn.cfg";
40 private static final String ETC_ORG_OPS4J_PAX_LOGGING_CFG = "etc/org.ops4j.pax.logging.cfg";
42 private static final String PAX_EXAM_UNPACK_DIRECTORY = "target/exam";
43 private static final String KARAF_DEBUG_PORT = "5005";
44 private static final String KARAF_DEBUG_PROP = "karaf.debug";
45 private static final String KEEP_UNPACK_DIRECTORY_PROP = "karaf.keep.unpack";
48 * Default values for karaf distro type, groupId, and artifactId
50 private static final String KARAF_DISTRO_TYPE = "zip";
51 private static final String KARAF_DISTRO_ARTIFACTID = "opendaylight-karaf-empty";
52 private static final String KARAF_DISTRO_GROUPID = "org.opendaylight.odlparent";
55 * Property names to override defaults for karaf distro artifactId, groupId,
58 private static final String KARAF_DISTRO_TYPE_PROP = "karaf.distro.type";
59 private static final String KARAF_DISTRO_ARTIFACTID_PROP = "karaf.distro.artifactId";
60 private static final String KARAF_DISTRO_GROUPID_PROP = "karaf.distro.groupId";
62 public static final String ORG_OPS4J_PAX_LOGGING_CFG = "etc/org.ops4j.pax.logging.cfg";
64 @Inject @Filter(timeout = 60000)
65 private BundleContext context;
67 public abstract MavenUrlReference getFeatureRepo();
69 public abstract String getFeatureName();
72 public void setup() throws Exception {
75 public Option getLoggingOption() {
76 Option option = editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
77 "log4j2.logger.mdsal-it-base.name",
78 AbstractMdsalTestBase.class.getPackage().getName());
79 option = composite(option, editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
80 "log4j2.logger.mdsal-it-base.level",
81 LogLevel.INFO.name()));
86 * Override this method to provide more options to config.
88 * @return An array of additional config options
90 protected Option[] getAdditionalOptions() {
95 * Returns a Log4J logging configuration property name for the given class's package name of the form
96 * "log4j.logger.package_name".
98 * @deprecated The karaf logging provider is now Log4J2 so logging configurations must conform to the Log4J2 style.
99 * This method is kept for compilation backwards compatibility but will be removed in a future release.
102 public String logConfiguration(final Class<?> klazz) {
103 return "log4j.logger." + klazz.getPackage().getName();
106 public String getKarafDistro() {
107 String groupId = System.getProperty(KARAF_DISTRO_GROUPID_PROP, KARAF_DISTRO_GROUPID);
108 String artifactId = System.getProperty(KARAF_DISTRO_ARTIFACTID_PROP, KARAF_DISTRO_ARTIFACTID);
109 String type = System.getProperty(KARAF_DISTRO_TYPE_PROP, KARAF_DISTRO_TYPE);
111 return maven().groupId(groupId).artifactId(artifactId).versionAsInProject().type(type).getURL();
114 protected Option mvnLocalRepoOption() {
115 String mvnRepoLocal = System.getProperty(MAVEN_REPO_LOCAL, "");
116 LOG.info("mvnLocalRepo \"{}\"", mvnRepoLocal);
117 return editConfigurationFilePut(ETC_ORG_OPS4J_PAX_URL_MVN_CFG, ORG_OPS4J_PAX_URL_MVN_LOCAL_REPOSITORY,
122 public Option[] config() {
123 Option[] options = new Option[] {
124 when(Boolean.getBoolean(KARAF_DEBUG_PROP))
125 .useOptions(KarafDistributionOption.debugConfiguration(KARAF_DEBUG_PORT, true)),
126 karafDistributionConfiguration().frameworkUrl(getKarafDistro())
127 .unpackDirectory(new File(PAX_EXAM_UNPACK_DIRECTORY)).useDeployFolder(false),
128 when(Boolean.getBoolean(KEEP_UNPACK_DIRECTORY_PROP)).useOptions(keepRuntimeFolder()),
129 features(getFeatureRepo(), getFeatureName()),
130 //mavenBundle("org.apache.aries.quiesce", "org.apache.aries.quiesce.api", "1.0.0"), getLoggingOption(),
131 mvnLocalRepoOption(),
132 configureConsole().ignoreLocalConsole().ignoreRemoteShell(),
133 editConfigurationFilePut(ETC_ORG_OPS4J_PAX_LOGGING_CFG, "log4j2.rootLogger.level", "INFO") };
134 return OptionUtils.combine(options, getAdditionalOptions());