1 package org.opendaylight.controller.northbound.integrationtest;
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
5 import org.osgi.framework.ServiceReference;
6 import org.osgi.framework.Bundle;
7 import javax.inject.Inject;
8 import org.junit.Assert;
10 import org.junit.Before;
11 import org.junit.runner.RunWith;
12 import org.ops4j.pax.exam.junit.PaxExam;
13 import org.osgi.framework.BundleContext;
14 import static org.junit.Assert.*;
15 import org.ops4j.pax.exam.junit.Configuration;
16 import static org.ops4j.pax.exam.CoreOptions.*;
17 import org.ops4j.pax.exam.Option;
18 import org.ops4j.pax.exam.util.PathUtils;
19 import java.io.BufferedReader;
20 import java.io.InputStream;
21 import java.io.InputStreamReader;
23 import java.net.URLConnection;
24 import java.nio.charset.Charset;
25 import org.apache.commons.codec.binary.Base64;
27 import org.codehaus.jettison.json.JSONObject;
28 import org.codehaus.jettison.json.JSONTokener;
30 import org.opendaylight.controller.usermanager.IUserManager;
32 @RunWith(PaxExam.class)
33 public class NorthboundIntegrationTest {
34 private Logger log = LoggerFactory
35 .getLogger(NorthboundIntegrationTest.class);
36 // get the OSGI bundle context
38 private BundleContext bc;
39 private IUserManager users = null;
41 private String stateToString(int state) {
45 case Bundle.INSTALLED:
49 case Bundle.UNINSTALLED:
52 return "Not CONVERTED";
57 public void areWeReady() {
59 boolean debugit = false;
60 Bundle b[] = bc.getBundles();
61 for (int i = 0; i < b.length; i++) {
62 int state = b[i].getState();
63 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
64 log.debug("Bundle:" + b[i].getSymbolicName() + " state:"
65 + stateToString(state));
70 log.debug("Do some debugging because some bundle is "
73 // Assert if true, if false we are good to go!
76 ServiceReference r = bc.getServiceReference(IUserManager.class
79 this.users = (IUserManager) bc.getService(r);
81 // If UserManager is null, cannot login to run tests.
82 assertNotNull(this.users);
87 public void testStatistics() {
89 System.out.println("Starting Statistics JAXB client.");
91 String baseURL = "http://127.0.0.1:8080/controller/nb/v2/statistics/default/flowstats";
93 URL url = new URL(baseURL);
95 this.users.getAuthorizationList();
96 this.users.authenticate("admin", "admin");
97 String authString = "admin:admin";
98 byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
99 String authStringEnc = new String(authEncBytes);
100 URLConnection connection = url.openConnection();
101 connection.setRequestProperty("Authorization", "Basic "
104 connection.setRequestProperty("Content-Type", "application/json");
105 connection.setRequestProperty("Accept", "application/json");
107 connection.connect();
108 connection.getContentType();
109 InputStream is = connection.getInputStream();
110 // InputStream is = connection.getInputStream();
111 BufferedReader rd = new BufferedReader(new InputStreamReader(is,
112 Charset.forName("UTF-8")));
113 StringBuilder sb = new StringBuilder();
115 while ((cp = rd.read()) != -1) {
116 sb.append((char) cp);
119 JSONTokener jt = new JSONTokener(sb.toString());
120 JSONObject json = new JSONObject(jt);
121 JSONObject flowStatistics = json.getJSONObject("flowStatistics");
122 JSONObject node = flowStatistics.getJSONObject("node");
123 // test that node was returned properly
124 Assert.assertTrue(node.getInt("@id") == 0xCAFE);
125 Assert.assertTrue(node.getString("@type").equals("STUB"));
127 // test that flow statistics results are correct
128 JSONObject flowStat = flowStatistics.getJSONObject("flowStat");
129 Assert.assertTrue(flowStat.getInt("tableId") == 1);
130 Assert.assertTrue(flowStat.getInt("durationSeconds") == 40);
131 Assert.assertTrue(flowStat.getInt("durationNanoseconds") == 400);
132 Assert.assertTrue(flowStat.getInt("packetCount") == 200);
133 Assert.assertTrue(flowStat.getInt("byteCount") == 100);
135 // test that flow information is correct
136 JSONObject flow = flowStat.getJSONObject("flow");
137 Assert.assertTrue(flow.getInt("priority") == 3500);
138 Assert.assertTrue(flow.getInt("idleTimeout") == 1000);
139 Assert.assertTrue(flow.getInt("hardTimeout") == 2000);
140 Assert.assertTrue(flow.getInt("id") == 12345);
142 JSONObject match = (flow.getJSONObject("match")
143 .getJSONObject("matchField"));
144 Assert.assertTrue(match.getString("type").equals("NW_DST"));
145 Assert.assertTrue(match.getString("value").equals("1.1.1.1"));
147 Assert.assertTrue(flow.getJSONObject("actions").getString("@type")
150 } catch (Exception e) {
151 // Got an unexpected exception
152 Assert.assertTrue(false);
157 // Configure the OSGi container
159 public Option[] config() {
162 systemProperty("logback.configurationFile").value(
163 "file:" + PathUtils.getBaseDir()
164 + "/src/test/resources/logback.xml"),
165 // To start OSGi console for inspection remotely
166 systemProperty("osgi.console").value("2401"),
167 systemProperty("org.eclipse.gemini.web.tomcat.config.path")
168 .value(PathUtils.getBaseDir()
169 + "/src/test/resources/tomcat-server.xml"),
171 // setting default level. Jersey bundles will need to be started
173 systemProperty("osgi.bundles.defaultStartLevel").value("4"),
175 // Set the systemPackages (used by clustering)
176 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
177 mavenBundle("javax.servlet", "servlet-api", "2.5"),
179 mavenBundle("org.slf4j", "jcl-over-slf4j", "1.7.2"),
180 mavenBundle("org.slf4j", "slf4j-api", "1.7.2"),
181 mavenBundle("org.slf4j", "log4j-over-slf4j", "1.7.2"),
182 mavenBundle("ch.qos.logback", "logback-core", "1.0.9"),
183 mavenBundle("ch.qos.logback", "logback-classic", "1.0.9"),
184 mavenBundle("org.apache.commons", "commons-lang3", "3.1"),
185 mavenBundle("org.apache.felix",
186 "org.apache.felix.dependencymanager", "3.1.0"),
188 // the plugin stub to get data for the tests
189 mavenBundle("org.opendaylight.controller",
190 "protocol_plugins.stub", "0.4.0-SNAPSHOT"),
192 // List all the opendaylight modules
193 mavenBundle("org.opendaylight.controller", "security",
194 "0.4.0-SNAPSHOT").noStart(),
195 mavenBundle("org.opendaylight.controller", "sal",
197 mavenBundle("org.opendaylight.controller",
198 "sal.implementation", "0.4.0-SNAPSHOT"),
199 mavenBundle("org.opendaylight.controller", "statisticsmanager",
201 mavenBundle("org.opendaylight.controller",
202 "statisticsmanager.implementation", "0.4.0-SNAPSHOT"),
203 mavenBundle("org.opendaylight.controller", "containermanager",
205 mavenBundle("org.opendaylight.controller",
206 "containermanager.implementation", "0.4.0-SNAPSHOT"),
207 mavenBundle("org.opendaylight.controller",
208 "forwardingrulesmanager", "0.4.0-SNAPSHOT"),
209 mavenBundle("org.opendaylight.controller",
210 "forwardingrulesmanager.implementation",
212 mavenBundle("org.opendaylight.controller", "arphandler",
214 mavenBundle("org.opendaylight.controller",
215 "clustering.services", "0.4.0-SNAPSHOT"),
216 mavenBundle("org.opendaylight.controller",
217 "clustering.services-implementation", "0.4.0-SNAPSHOT"),
218 mavenBundle("org.opendaylight.controller", "switchmanager",
220 mavenBundle("org.opendaylight.controller",
221 "switchmanager.implementation", "0.4.0-SNAPSHOT"),
222 mavenBundle("org.opendaylight.controller", "configuration",
224 mavenBundle("org.opendaylight.controller",
225 "configuration.implementation", "0.4.0-SNAPSHOT"),
226 mavenBundle("org.opendaylight.controller", "hosttracker",
228 mavenBundle("org.opendaylight.controller",
229 "hosttracker.implementation", "0.4.0-SNAPSHOT"),
230 mavenBundle("org.opendaylight.controller", "arphandler",
232 mavenBundle("org.opendaylight.controller",
233 "routing.dijkstra_implementation", "0.4.0-SNAPSHOT"),
234 mavenBundle("org.opendaylight.controller", "topologymanager",
237 mavenBundle("org.opendaylight.controller", "usermanager",
239 mavenBundle("org.opendaylight.controller", "logging.bridge",
241 mavenBundle("org.opendaylight.controller", "clustering.test",
244 mavenBundle("org.opendaylight.controller",
245 "forwarding.staticrouting", "0.4.0-SNAPSHOT"),
247 // Northbound bundles
248 mavenBundle("org.opendaylight.controller",
249 "commons.northbound", "0.4.0-SNAPSHOT"),
250 mavenBundle("org.opendaylight.controller",
251 "forwarding.staticrouting.northbound", "0.4.0-SNAPSHOT"),
252 mavenBundle("org.opendaylight.controller",
253 "statistics.northbound", "0.4.0-SNAPSHOT"),
254 mavenBundle("org.opendaylight.controller",
255 "topology.northbound", "0.4.0-SNAPSHOT"),
256 mavenBundle("org.opendaylight.controller",
257 "hosttracker.northbound", "0.4.0-SNAPSHOT"),
258 mavenBundle("org.opendaylight.controller",
259 "switchmanager.northbound", "0.4.0-SNAPSHOT"),
260 mavenBundle("org.opendaylight.controller",
261 "flowprogrammer.northbound", "0.4.0-SNAPSHOT"),
262 mavenBundle("org.opendaylight.controller",
263 "subnets.northbound", "0.4.0-SNAPSHOT"),
265 mavenBundle("org.codehaus.jackson", "jackson-mapper-asl",
267 mavenBundle("org.codehaus.jackson", "jackson-core-asl", "1.9.8"),
268 mavenBundle("org.codehaus.jackson", "jackson-jaxrs", "1.9.8"),
269 mavenBundle("org.codehaus.jettison", "jettison", "1.3.3"),
271 mavenBundle("commons-io", "commons-io", "2.3"),
273 mavenBundle("commons-fileupload", "commons-fileupload", "1.2.2"),
275 mavenBundle("equinoxSDK381", "javax.servlet",
276 "3.0.0.v201112011016"),
277 mavenBundle("equinoxSDK381", "javax.servlet.jsp",
278 "2.2.0.v201112011158"),
279 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds",
280 "1.4.0.v20120522-1841"),
281 mavenBundle("orbit", "javax.xml.rpc", "1.1.0.v201005080400"),
282 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util",
283 "1.0.400.v20120522-2049"),
284 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services",
285 "3.3.100.v20120522-1822"),
286 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command",
287 "0.8.0.v201108120515"),
288 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime",
289 "0.8.0.v201108120515"),
290 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell",
291 "0.8.0.v201110170705"),
292 mavenBundle("equinoxSDK381", "org.eclipse.equinox.cm",
293 "1.0.400.v20120522-1841"),
294 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console",
295 "1.0.0.v20120522-1841"),
296 mavenBundle("equinoxSDK381", "org.eclipse.equinox.launcher",
297 "1.3.0.v20120522-1813"),
299 mavenBundle("geminiweb", "org.eclipse.gemini.web.core",
301 mavenBundle("geminiweb", "org.eclipse.gemini.web.extender",
303 mavenBundle("geminiweb", "org.eclipse.gemini.web.tomcat",
305 mavenBundle("geminiweb",
306 "org.eclipse.virgo.kernel.equinox.extensions",
307 "3.6.0.RELEASE").noStart(),
308 mavenBundle("geminiweb", "org.eclipse.virgo.util.common",
310 mavenBundle("geminiweb", "org.eclipse.virgo.util.io",
312 mavenBundle("geminiweb", "org.eclipse.virgo.util.math",
314 mavenBundle("geminiweb", "org.eclipse.virgo.util.osgi",
316 mavenBundle("geminiweb",
317 "org.eclipse.virgo.util.osgi.manifest", "3.6.0.RELEASE"),
318 mavenBundle("geminiweb",
319 "org.eclipse.virgo.util.parser.manifest",
322 mavenBundle("org.apache.felix",
323 "org.apache.felix.dependencymanager", "3.1.0"),
324 mavenBundle("org.apache.felix",
325 "org.apache.felix.dependencymanager.shell", "3.0.1"),
327 mavenBundle("com.google.code.gson", "gson", "2.1"),
328 mavenBundle("org.jboss.spec.javax.transaction",
329 "jboss-transaction-api_1.1_spec", "1.0.1.Final"),
330 mavenBundle("org.apache.felix", "org.apache.felix.fileinstall",
332 mavenBundle("org.apache.commons", "commons-lang3", "3.1"),
333 mavenBundle("commons-codec", "commons-codec"),
334 mavenBundle("virgomirror",
335 "org.eclipse.jdt.core.compiler.batch",
336 "3.8.0.I20120518-2145"),
337 mavenBundle("eclipselink", "javax.persistence",
338 "2.0.4.v201112161009"),
340 mavenBundle("orbit", "javax.activation", "1.1.0.v201211130549"),
341 mavenBundle("orbit", "javax.annotation", "1.1.0.v201209060031"),
342 mavenBundle("orbit", "javax.ejb", "3.1.1.v201204261316"),
343 mavenBundle("orbit", "javax.el", "2.2.0.v201108011116"),
344 mavenBundle("orbit", "javax.mail.glassfish",
345 "1.4.1.v201108011116"),
346 mavenBundle("orbit", "javax.xml.rpc", "1.1.0.v201005080400"),
347 mavenBundle("orbit", "org.apache.catalina",
348 "7.0.32.v201211201336"),
349 // these are bundle fragments that can't be started on its own
350 mavenBundle("orbit", "org.apache.catalina.ha",
351 "7.0.32.v201211201952").noStart(),
352 mavenBundle("orbit", "org.apache.catalina.tribes",
353 "7.0.32.v201211201952").noStart(),
354 mavenBundle("orbit", "org.apache.coyote",
355 "7.0.32.v201211201952").noStart(),
356 mavenBundle("orbit", "org.apache.jasper",
357 "7.0.32.v201211201952").noStart(),
359 mavenBundle("orbit", "org.apache.el", "7.0.32.v201211081135"),
360 mavenBundle("orbit", "org.apache.juli.extras",
361 "7.0.32.v201211081135"),
362 mavenBundle("orbit", "org.apache.tomcat.api",
363 "7.0.32.v201211081135"),
364 mavenBundle("orbit", "org.apache.tomcat.util",
365 "7.0.32.v201211201952").noStart(),
366 mavenBundle("orbit", "javax.servlet.jsp.jstl",
367 "1.2.0.v201105211821"),
368 mavenBundle("orbit", "javax.servlet.jsp.jstl.impl",
369 "1.2.0.v201210211230"),
371 mavenBundle("org.ops4j.pax.exam", "pax-exam-container-native"),
372 mavenBundle("org.ops4j.pax.exam", "pax-exam-junit4"),
373 mavenBundle("org.ops4j.pax.exam", "pax-exam-link-mvn"),
374 mavenBundle("org.ops4j.pax.url", "pax-url-aether"),
376 mavenBundle("org.springframework", "org.springframework.asm",
378 mavenBundle("org.springframework", "org.springframework.aop",
380 mavenBundle("org.springframework",
381 "org.springframework.context", "3.1.3.RELEASE"),
382 mavenBundle("org.springframework",
383 "org.springframework.context.support", "3.1.3.RELEASE"),
384 mavenBundle("org.springframework", "org.springframework.core",
386 mavenBundle("org.springframework", "org.springframework.beans",
388 mavenBundle("org.springframework",
389 "org.springframework.expression", "3.1.3.RELEASE"),
390 mavenBundle("org.springframework", "org.springframework.web",
393 mavenBundle("org.aopalliance",
394 "com.springsource.org.aopalliance", "1.0.0"),
395 mavenBundle("org.springframework",
396 "org.springframework.web.servlet", "3.1.3.RELEASE"),
397 mavenBundle("org.springframework.security",
398 "spring-security-config", "3.1.3.RELEASE"),
399 mavenBundle("org.springframework.security",
400 "spring-security-core", "3.1.3.RELEASE"),
401 mavenBundle("org.springframework.security",
402 "spring-security-web", "3.1.3.RELEASE"),
403 mavenBundle("org.springframework.security",
404 "spring-security-taglibs", "3.1.3.RELEASE"),
405 mavenBundle("org.springframework",
406 "org.springframework.transaction", "3.1.3.RELEASE"),
408 mavenBundle("org.ow2.chameleon.management", "chameleon-mbeans",
410 mavenBundle("org.opendaylight.controller.thirdparty",
411 "net.sf.jung2", "2.0.1-SNAPSHOT"),
412 mavenBundle("org.opendaylight.controller.thirdparty",
413 "com.sun.jersey.jersey-servlet", "1.17-SNAPSHOT"),
415 // Jersey needs to be started before the northbound application
416 // bundles, using a lower start level
417 mavenBundle("com.sun.jersey", "jersey-client", "1.17"),
418 mavenBundle("com.sun.jersey", "jersey-server", "1.17")
420 mavenBundle("com.sun.jersey", "jersey-core", "1.17")
422 mavenBundle("com.sun.jersey", "jersey-json", "1.17")
423 .startLevel(2), junitBundles());