1 package org.opendaylight.controller.configuration.internal;
3 import static org.junit.Assert.assertFalse;
4 import static org.junit.Assert.assertNotNull;
5 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
6 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
7 import static org.ops4j.pax.exam.CoreOptions.options;
8 import static org.ops4j.pax.exam.CoreOptions.systemPackages;
9 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
13 import javax.inject.Inject;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.opendaylight.controller.configuration.IConfigurationService;
20 import org.opendaylight.controller.sal.utils.GlobalConstants;
21 import org.opendaylight.controller.sal.utils.Status;
22 import org.opendaylight.controller.sal.utils.StatusCode;
23 import org.ops4j.pax.exam.Option;
24 import org.ops4j.pax.exam.junit.Configuration;
25 import org.ops4j.pax.exam.junit.PaxExam;
26 import org.ops4j.pax.exam.util.PathUtils;
27 import org.osgi.framework.Bundle;
28 import org.osgi.framework.BundleContext;
29 import org.osgi.framework.ServiceReference;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 @RunWith(PaxExam.class)
34 public class ConfigurationIT {
35 private final Logger logger = LoggerFactory
36 .getLogger(ConfigurationIT.class);
37 // get the OSGI bundle context
39 private BundleContext bc;
40 private IConfigurationService configService = null;
42 // Configure the OSGi container
44 public Option[] config() {
46 systemProperty("logback.configurationFile").value(
47 "file:" + PathUtils.getBaseDir()
48 + "/src/test/resources/logback.xml"),
49 // To start OSGi console for inspection remotely
50 systemProperty("osgi.console").value("2401"),
51 // Set the systemPackages (used by clustering)
52 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
53 // List framework bundles
54 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console").versionAsInProject(),
55 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util").versionAsInProject(),
56 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services").versionAsInProject(),
57 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds").versionAsInProject(),
58 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command").versionAsInProject(),
59 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime").versionAsInProject(),
60 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell").versionAsInProject(),
61 // List logger bundles
62 mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
63 mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(),
64 mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(),
65 mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(),
66 mavenBundle("org.apache.commons", "commons-lang3").versionAsInProject(),
67 mavenBundle("org.jboss.spec.javax.transaction", "jboss-transaction-api_1.1_spec").versionAsInProject(),
68 mavenBundle("eclipselink", "javax.resource").versionAsInProject(),
69 mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager").versionAsInProject(),
70 // List all the bundles on which the test case depends
71 mavenBundle("org.opendaylight.controller", "sal").versionAsInProject(),
72 mavenBundle("org.opendaylight.controller", "sal.implementation").versionAsInProject(),
73 mavenBundle("org.opendaylight.controller", "protocol_plugins.stub").versionAsInProject(),
74 // needed bundles by switchmanager
75 mavenBundle("org.opendaylight.controller", "containermanager").versionAsInProject(),
76 mavenBundle("org.opendaylight.controller", "containermanager.implementation").versionAsInProject(),
77 // needed bundles by configuration
78 mavenBundle("org.opendaylight.controller", "clustering.services").versionAsInProject(),
79 mavenBundle("org.opendaylight.controller", "clustering.stub").versionAsInProject(),
80 mavenBundle("org.opendaylight.controller", "configuration").versionAsInProject(),
81 mavenBundle("org.opendaylight.controller", "configuration.implementation").versionAsInProject(),
85 private String stateToString(int state) {
89 case Bundle.INSTALLED:
93 case Bundle.UNINSTALLED:
96 return "Not CONVERTED";
101 public void areWeReadyForClustering() {
103 boolean debugit = false;
104 Bundle b[] = bc.getBundles();
105 for (int i = 0; i < b.length; i++) {
106 int state = b[i].getState();
107 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
108 logger.debug("Bundle:" + b[i].getSymbolicName() + " state:"
109 + stateToString(state));
114 logger.debug("Do some debugging because some bundle is unresolved");
117 // Assert if true, if false we are good to go!
118 assertFalse(debugit);
122 public void areWeReadyForConfiguration() {
124 boolean debugit = false;
125 Bundle b[] = bc.getBundles();
126 for (int i = 0; i < b.length; i++) {
127 int state = b[i].getState();
128 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
129 logger.debug("Bundle:" + b[i].getSymbolicName() + " state:"
130 + stateToString(state));
135 logger.debug("Do some debugging because some bundle is unresolved");
138 // Assert if true, if false we are good to go!
139 assertFalse(debugit);
140 ServiceReference r = bc.getServiceReference(IConfigurationService.class
143 this.configService = (IConfigurationService) bc.getService(r);
145 // If StatisticsManager is null, cannot run tests.
146 assertNotNull(this.configService);
151 public void saveConfiguration() {
152 File f = new File(GlobalConstants.STARTUPHOME.toString());
153 boolean success = f.exists();
155 success = f.mkdirs();
158 Status status = new Status(StatusCode.SUCCESS, null);
159 if (this.configService != null) {
160 status = this.configService.saveConfigurations();
162 if (status.getCode().equals(StatusCode.SUCCESS)) {
163 Assert.assertTrue("Successfully saved config for "
164 + configService.getClass().getSimpleName(), status
165 .getCode().equals(StatusCode.SUCCESS));
167 Assert.assertFalse("Failed to save config for "
168 + configService.getClass().getSimpleName(), status
169 .getCode().equals(StatusCode.INTERNALERROR));