Remove CSS modules
[controller.git] / opendaylight / md-sal / mdsal-it-base / src / main / java / org / opendaylight / controller / mdsal / it / base / AbstractMdsalTestBase.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.mdsal.it.base;
10
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;
19
20 import java.io.File;
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;
33
34 public abstract class AbstractMdsalTestBase {
35
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";
41
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";
46
47     /*
48      * Default values for karaf distro type, groupId, and artifactId
49      */
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";
53
54     /*
55      * Property names to override defaults for karaf distro artifactId, groupId,
56      * version, and type
57      */
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";
61
62     public static final String ORG_OPS4J_PAX_LOGGING_CFG = "etc/org.ops4j.pax.logging.cfg";
63
64     @Inject @Filter(timeout = 60000)
65     private BundleContext context;
66
67     public abstract MavenUrlReference getFeatureRepo();
68
69     public abstract String getFeatureName();
70
71     @Before
72     public void setup() throws Exception {
73     }
74
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()));
82         return option;
83     }
84
85     /**
86      * Override this method to provide more options to config.
87      *
88      * @return An array of additional config options
89      */
90     protected Option[] getAdditionalOptions() {
91         return null;
92     }
93
94     /**
95      * Returns a Log4J logging configuration property name for the given class's package name of the form
96      * "log4j.logger.package_name".
97      *
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.
100      */
101     @Deprecated
102     public String logConfiguration(final Class<?> klazz) {
103         return "log4j.logger." + klazz.getPackage().getName();
104     }
105
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);
110
111         return maven().groupId(groupId).artifactId(artifactId).versionAsInProject().type(type).getURL();
112     }
113
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,
118                 mvnRepoLocal);
119     }
120
121     @Configuration
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());
135     }
136 }

©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.