2 * Copyright (c) 2014 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.controller.configuration.internal;
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertNotNull;
12 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
13 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
14 import static org.ops4j.pax.exam.CoreOptions.options;
15 import static org.ops4j.pax.exam.CoreOptions.systemPackages;
16 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
20 import javax.inject.Inject;
22 import org.junit.Assert;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.opendaylight.controller.configuration.IConfigurationService;
27 import org.opendaylight.controller.sal.utils.GlobalConstants;
28 import org.opendaylight.controller.sal.utils.Status;
29 import org.opendaylight.controller.sal.utils.StatusCode;
30 import org.ops4j.pax.exam.Option;
31 import org.ops4j.pax.exam.Configuration;
32 import org.ops4j.pax.exam.junit.PaxExam;
33 import org.ops4j.pax.exam.util.PathUtils;
34 import org.osgi.framework.Bundle;
35 import org.osgi.framework.BundleContext;
36 import org.osgi.framework.ServiceReference;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
40 @RunWith(PaxExam.class)
41 public class ConfigurationIT {
42 private final Logger logger = LoggerFactory
43 .getLogger(ConfigurationIT.class);
44 // get the OSGI bundle context
46 private BundleContext bc;
47 private IConfigurationService configService = null;
49 // Configure the OSGi container
51 public Option[] config() {
53 systemProperty("logback.configurationFile").value(
54 "file:" + PathUtils.getBaseDir()
55 + "/src/test/resources/logback.xml"),
56 // To start OSGi console for inspection remotely
57 systemProperty("osgi.console").value("2401"),
58 // Set the systemPackages (used by clustering)
59 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
60 // List framework bundles
61 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console").versionAsInProject(),
62 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util").versionAsInProject(),
63 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services").versionAsInProject(),
64 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds").versionAsInProject(),
65 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command").versionAsInProject(),
66 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime").versionAsInProject(),
67 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell").versionAsInProject(),
68 // List logger bundles
69 mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
70 mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(),
71 mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(),
72 mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(),
73 mavenBundle("org.apache.commons", "commons-lang3").versionAsInProject(),
74 mavenBundle("org.jboss.spec.javax.transaction", "jboss-transaction-api_1.1_spec").versionAsInProject(),
75 mavenBundle("eclipselink", "javax.resource").versionAsInProject(),
76 mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager").versionAsInProject(),
77 // List all the bundles on which the test case depends
78 mavenBundle("org.opendaylight.controller", "sal").versionAsInProject(),
79 mavenBundle("org.opendaylight.controller", "sal.implementation").versionAsInProject(),
80 mavenBundle("org.opendaylight.controller", "protocol_plugins.stub").versionAsInProject(),
81 // needed bundles by switchmanager
82 mavenBundle("org.opendaylight.controller", "containermanager").versionAsInProject(),
83 mavenBundle("org.opendaylight.controller", "containermanager.it.implementation").versionAsInProject(),
84 // needed bundles by configuration
85 mavenBundle("org.opendaylight.controller", "clustering.services").versionAsInProject(),
86 mavenBundle("org.opendaylight.controller", "clustering.stub").versionAsInProject(),
87 mavenBundle("org.opendaylight.controller", "configuration").versionAsInProject(),
88 mavenBundle("org.opendaylight.controller", "configuration.implementation").versionAsInProject(),
92 private String stateToString(int state) {
96 case Bundle.INSTALLED:
100 case Bundle.UNINSTALLED:
101 return "UNINSTALLED";
103 return "Not CONVERTED";
108 public void areWeReadyForClustering() {
110 boolean debugit = false;
111 Bundle b[] = bc.getBundles();
112 for (int i = 0; i < b.length; i++) {
113 int state = b[i].getState();
114 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
115 logger.debug("Bundle:" + b[i].getSymbolicName() + " state:"
116 + stateToString(state));
121 logger.debug("Do some debugging because some bundle is unresolved");
124 // Assert if true, if false we are good to go!
125 assertFalse(debugit);
129 public void areWeReadyForConfiguration() {
131 boolean debugit = false;
132 Bundle b[] = bc.getBundles();
133 for (int i = 0; i < b.length; i++) {
134 int state = b[i].getState();
135 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
136 logger.debug("Bundle:" + b[i].getSymbolicName() + " state:"
137 + stateToString(state));
142 logger.debug("Do some debugging because some bundle is unresolved");
145 // Assert if true, if false we are good to go!
146 assertFalse(debugit);
147 ServiceReference r = bc.getServiceReference(IConfigurationService.class
150 this.configService = (IConfigurationService) bc.getService(r);
152 // If StatisticsManager is null, cannot run tests.
153 assertNotNull(this.configService);
158 public void saveConfiguration() {
159 File f = new File(GlobalConstants.STARTUPHOME.toString());
160 boolean success = f.exists();
162 success = f.mkdirs();
165 Status status = new Status(StatusCode.SUCCESS, null);
166 if (this.configService != null) {
167 status = this.configService.saveConfigurations();
169 if (status.getCode().equals(StatusCode.SUCCESS)) {
170 Assert.assertTrue("Successfully saved config for "
171 + configService.getClass().getSimpleName(), status
172 .getCode().equals(StatusCode.SUCCESS));
174 Assert.assertFalse("Failed to save config for "
175 + configService.getClass().getSimpleName(), status
176 .getCode().equals(StatusCode.INTERNALERROR));