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.clustering.services.IClusterServices;
20 import org.opendaylight.controller.configuration.IConfigurationService;
21 import org.opendaylight.controller.sal.utils.GlobalConstants;
22 import org.opendaylight.controller.sal.utils.Status;
23 import org.opendaylight.controller.sal.utils.StatusCode;
24 import org.ops4j.pax.exam.Option;
25 import org.ops4j.pax.exam.junit.Configuration;
26 import org.ops4j.pax.exam.junit.PaxExam;
27 import org.ops4j.pax.exam.util.PathUtils;
28 import org.osgi.framework.Bundle;
29 import org.osgi.framework.BundleContext;
30 import org.osgi.framework.ServiceReference;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 @RunWith(PaxExam.class)
35 public class ConfigurationIT {
36 private Logger logger = LoggerFactory
37 .getLogger(ConfigurationIT.class);
38 // get the OSGI bundle context
40 private BundleContext bc;
41 private IClusterServices clusterService = null;
42 private IConfigurationService configService = null;
44 // Configure the OSGi container
46 public Option[] config() {
48 systemProperty("logback.configurationFile").value(
49 "file:" + PathUtils.getBaseDir()
50 + "/src/test/resources/logback.xml"),
51 // To start OSGi console for inspection remotely
52 systemProperty("osgi.console").value("2401"),
53 // Set the systemPackages (used by clustering)
54 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
55 // List framework bundles
56 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console",
57 "1.0.0.v20120522-1841"),
58 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util",
59 "1.0.400.v20120522-2049"),
60 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services",
61 "3.3.100.v20120522-1822"),
62 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds",
63 "1.4.0.v20120522-1841"),
64 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command",
65 "0.8.0.v201108120515"),
66 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime",
67 "0.8.0.v201108120515"),
68 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell",
69 "0.8.0.v201110170705"),
70 // List logger bundles
71 mavenBundle("org.slf4j", "slf4j-api", "1.7.2"),
72 mavenBundle("org.slf4j", "log4j-over-slf4j", "1.7.2"),
73 mavenBundle("ch.qos.logback", "logback-core", "1.0.9"),
74 mavenBundle("ch.qos.logback", "logback-classic", "1.0.9"),
75 mavenBundle("org.apache.commons", "commons-lang3", "3.1"),
76 mavenBundle("org.jboss.spec.javax.transaction",
77 "jboss-transaction-api_1.1_spec", "1.0.1.Final"),
78 mavenBundle("org.apache.felix",
79 "org.apache.felix.dependencymanager", "3.1.0"),
80 // List all the bundles on which the test case depends
81 mavenBundle("org.opendaylight.controller", "sal",
82 "0.5.0-SNAPSHOT"), // SAL connects the protocols
83 // plug-ins to other stuff
84 mavenBundle("org.opendaylight.controller",
85 "sal.implementation", "0.4.0-SNAPSHOT"),
86 mavenBundle("org.opendaylight.controller",
87 "protocol_plugins.stub", "0.4.0-SNAPSHOT"),
88 // needed bundles by switchmanager
89 mavenBundle("org.opendaylight.controller", "containermanager",
91 mavenBundle("org.opendaylight.controller",
92 "containermanager.implementation", "0.4.0-SNAPSHOT"),
93 mavenBundle("org.opendaylight.controller", "switchmanager",
95 mavenBundle("org.opendaylight.controller",
96 "switchmanager.implementation", "0.4.0-SNAPSHOT"),
97 // needed bundles by configuration
98 mavenBundle("org.opendaylight.controller",
99 "clustering.services", "0.4.0-SNAPSHOT"), // what are
104 mavenBundle("org.opendaylight.controller", "clustering.stub",
106 mavenBundle("org.opendaylight.controller",
107 "clustering.services-implementation", "0.4.0-SNAPSHOT"),
108 mavenBundle("org.opendaylight.controller", "configuration",
110 mavenBundle("org.opendaylight.controller",
111 "configuration.implementation", "0.4.0-SNAPSHOT"),
115 private String stateToString(int state) {
119 case Bundle.INSTALLED:
121 case Bundle.RESOLVED:
123 case Bundle.UNINSTALLED:
124 return "UNINSTALLED";
126 return "Not CONVERTED";
131 public void areWeReadyForClustering() {
133 boolean debugit = false;
134 Bundle b[] = bc.getBundles();
135 for (int i = 0; i < b.length; i++) {
136 int state = b[i].getState();
137 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
138 logger.debug("Bundle:" + b[i].getSymbolicName() + " state:"
139 + stateToString(state));
144 logger.debug("Do some debugging because some bundle is unresolved");
147 // Assert if true, if false we are good to go!
148 assertFalse(debugit);
149 ServiceReference r = bc.getServiceReference(IClusterServices.class
152 this.clusterService = (IClusterServices) bc.getService(r);
154 // If StatisticsManager is null, cannot run tests.
155 assertNotNull(this.clusterService);
160 public void areWeReadyForConfiguration() {
162 boolean debugit = false;
163 Bundle b[] = bc.getBundles();
164 for (int i = 0; i < b.length; i++) {
165 int state = b[i].getState();
166 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
167 logger.debug("Bundle:" + b[i].getSymbolicName() + " state:"
168 + stateToString(state));
173 logger.debug("Do some debugging because some bundle is unresolved");
176 // Assert if true, if false we are good to go!
177 assertFalse(debugit);
178 ServiceReference r = bc.getServiceReference(IConfigurationService.class
181 this.configService = (IConfigurationService) bc.getService(r);
183 // If StatisticsManager is null, cannot run tests.
184 assertNotNull(this.configService);
189 public void saveConfiguration() {
190 File f = new File(GlobalConstants.STARTUPHOME.toString());
191 boolean success = f.exists();
193 success = f.mkdirs();
196 Status status = new Status(StatusCode.SUCCESS, null);
197 if (this.configService != null) {
198 status = this.configService.saveConfigurations();
200 if (status.getCode().equals(StatusCode.SUCCESS)) {
201 Assert.assertTrue("Successfully saved config for "
202 + configService.getClass().getSimpleName(), status
203 .getCode().equals(StatusCode.SUCCESS));
205 Assert.assertFalse("Failed to save config for "
206 + configService.getClass().getSimpleName(), status
207 .getCode().equals(StatusCode.INTERNALERROR));