Add HTTP Client library and refactor Northbound IntegrationTest
[controller.git] / opendaylight / northbound / integrationtest / src / test / java / org / opendaylight / controller / northbound / integrationtest / NorthboundIT.java
1 package org.opendaylight.controller.northbound.integrationtest;
2
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;
10
11 import java.util.ArrayList;
12 import java.util.Arrays;
13 import java.util.HashMap;
14 import java.util.HashSet;
15 import java.util.List;
16 import java.util.Map;
17 import java.util.Set;
18
19 import javax.inject.Inject;
20
21 import org.apache.commons.codec.binary.Base64;
22 import org.codehaus.jettison.json.JSONArray;
23 import org.codehaus.jettison.json.JSONException;
24 import org.codehaus.jettison.json.JSONObject;
25 import org.codehaus.jettison.json.JSONTokener;
26 import org.junit.Assert;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.opendaylight.controller.commons.httpclient.HTTPClient;
31 import org.opendaylight.controller.commons.httpclient.HTTPRequest;
32 import org.opendaylight.controller.commons.httpclient.HTTPResponse;
33 import org.opendaylight.controller.hosttracker.IfIptoHost;
34 import org.opendaylight.controller.sal.core.Bandwidth;
35 import org.opendaylight.controller.sal.core.ConstructionException;
36 import org.opendaylight.controller.sal.core.Edge;
37 import org.opendaylight.controller.sal.core.Latency;
38 import org.opendaylight.controller.sal.core.Node;
39 import org.opendaylight.controller.sal.core.NodeConnector;
40 import org.opendaylight.controller.sal.core.Property;
41 import org.opendaylight.controller.sal.core.State;
42 import org.opendaylight.controller.sal.core.UpdateType;
43 import org.opendaylight.controller.sal.topology.IListenTopoUpdates;
44 import org.opendaylight.controller.sal.topology.TopoEdgeUpdate;
45 import org.opendaylight.controller.switchmanager.IInventoryListener;
46 import org.opendaylight.controller.usermanager.IUserManager;
47 import org.ops4j.pax.exam.Option;
48 import org.ops4j.pax.exam.junit.Configuration;
49 import org.ops4j.pax.exam.junit.PaxExam;
50 import org.ops4j.pax.exam.util.PathUtils;
51 import org.osgi.framework.Bundle;
52 import org.osgi.framework.BundleContext;
53 import org.osgi.framework.ServiceReference;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
56
57 @RunWith(PaxExam.class)
58 public class NorthboundIT {
59     private final Logger log = LoggerFactory.getLogger(NorthboundIT.class);
60     // get the OSGI bundle context
61     @Inject
62     private BundleContext bc;
63     private IUserManager userManager = null;
64     private IInventoryListener invtoryListener = null;
65     private IListenTopoUpdates topoUpdates = null;
66
67     private final Boolean debugMsg = false;
68
69     private String stateToString(int state) {
70         switch (state) {
71         case Bundle.ACTIVE:
72             return "ACTIVE";
73         case Bundle.INSTALLED:
74             return "INSTALLED";
75         case Bundle.RESOLVED:
76             return "RESOLVED";
77         case Bundle.UNINSTALLED:
78             return "UNINSTALLED";
79         default:
80             return "Not CONVERTED";
81         }
82     }
83
84     @Before
85     public void areWeReady() {
86         assertNotNull(bc);
87         boolean debugit = false;
88         Bundle b[] = bc.getBundles();
89         for (Bundle element : b) {
90             int state = element.getState();
91             if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
92                 log.debug("Bundle:" + element.getSymbolicName() + " state:" + stateToString(state));
93                 debugit = true;
94             }
95         }
96         if (debugit) {
97             log.debug("Do some debugging because some bundle is " + "unresolved");
98         }
99         // Assert if true, if false we are good to go!
100         assertFalse(debugit);
101
102         ServiceReference r = bc.getServiceReference(IUserManager.class.getName());
103         if (r != null) {
104             this.userManager = (IUserManager) bc.getService(r);
105         }
106         // If UserManager is null, cannot login to run tests.
107         assertNotNull(this.userManager);
108
109         r = bc.getServiceReference(IfIptoHost.class.getName());
110         if (r != null) {
111             this.invtoryListener = (IInventoryListener) bc.getService(r);
112         }
113
114         // If inventoryListener is null, cannot run hosttracker tests.
115         assertNotNull(this.invtoryListener);
116
117         r = bc.getServiceReference(IListenTopoUpdates.class.getName());
118         if (r != null) {
119             this.topoUpdates = (IListenTopoUpdates) bc.getService(r);
120         }
121
122         // If topologyManager is null, cannot run topology North tests.
123         assertNotNull(this.topoUpdates);
124
125     }
126
127     // static variable to pass response code from getJsonResult()
128     private static Integer httpResponseCode = null;
129
130     private String getJsonResult(String restUrl) {
131         return getJsonResult(restUrl, "GET", null);
132     }
133
134     private String getJsonResult(String restUrl, String method) {
135         return getJsonResult(restUrl, method, null);
136     }
137
138     private String getJsonResult(String restUrl, String method, String body) {
139         // initialize response code to indicate error
140         httpResponseCode = 400;
141
142         if (debugMsg) {
143             System.out.println("HTTP method: " + method + " url: " + restUrl.toString());
144             if (body != null) {
145                 System.out.println("body: " + body);
146             }
147         }
148
149         try {
150             this.userManager.getAuthorizationList();
151             this.userManager.authenticate("admin", "admin");
152             HTTPRequest request = new HTTPRequest();
153
154             request.setUri(restUrl);
155             request.setMethod(method);
156             request.setTimeout(5000);  // HostTracker doesn't respond within 3 seconds
157
158             Map<String, List<String>> headers = new HashMap<String, List<String>>();
159             String authString = "admin:admin";
160             byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
161             String authStringEnc = new String(authEncBytes);
162             List<String> header = new ArrayList<String>();
163             header.add("Basic "+authStringEnc);
164             headers.put("Authorization", header);
165             header = new ArrayList<String>();
166             header.add("application/json");
167             headers.put("Accept", header);
168             request.setHeaders(headers);
169             request.setContentType("application/json");
170             if (body != null) {
171                 request.setEntity(body);
172             }
173
174             HTTPResponse response = HTTPClient.sendRequest(request);
175
176             // Response code for success should be 2xx
177             httpResponseCode = response.getStatus();
178             if (httpResponseCode > 299) {
179                 return httpResponseCode.toString();
180             }
181
182             if (debugMsg) {
183                 System.out.println("HTTP response code: " + response.getStatus());
184                 System.out.println("HTTP response message: " + response.getEntity());
185             }
186
187             return response.getEntity();
188         } catch (Exception e) {
189             if (debugMsg) {
190                 e.printStackTrace();
191             }
192             return null;
193         }
194     }
195
196     private void testNodeProperties(JSONObject node, Integer nodeId, String nodeType, Integer timestamp,
197             String timestampName, Integer actionsValue, Integer capabilitiesValue, Integer tablesValue,
198             Integer buffersValue) throws JSONException {
199
200         JSONObject nodeInfo = node.getJSONObject("node");
201         Assert.assertEquals(nodeId, (Integer) nodeInfo.getInt("id"));
202         Assert.assertEquals(nodeType, nodeInfo.getString("type"));
203
204         JSONObject properties = node.getJSONObject("properties");
205
206         if (timestamp == null || timestampName == null) {
207             Assert.assertFalse(properties.has("timeStamp"));
208         } else {
209             Assert.assertEquals(timestamp, (Integer) properties.getJSONObject("timeStamp").getInt("value"));
210             Assert.assertEquals(timestampName, properties.getJSONObject("timeStamp").getString("name"));
211         }
212         if (actionsValue == null) {
213             Assert.assertFalse(properties.has("actions"));
214         } else {
215             Assert.assertEquals(actionsValue, (Integer) properties.getJSONObject("actions").getInt("value"));
216         }
217         if (capabilitiesValue == null) {
218             Assert.assertFalse(properties.has("capabilities"));
219         } else {
220             Assert.assertEquals(capabilitiesValue,
221                     (Integer) properties.getJSONObject("capabilities").getInt("value"));
222         }
223         if (tablesValue == null) {
224             Assert.assertFalse(properties.has("tables"));
225         } else {
226             Assert.assertEquals(tablesValue, (Integer) properties.getJSONObject("tables").getInt("value"));
227         }
228         if (buffersValue == null) {
229             Assert.assertFalse(properties.has("buffers"));
230         } else {
231             Assert.assertEquals(buffersValue, (Integer) properties.getJSONObject("buffers").getInt("value"));
232         }
233     }
234
235     private void testNodeConnectorProperties(JSONObject nodeConnectorProperties, Integer ncId, String ncType,
236             Integer nodeId, String nodeType, Integer state, Integer capabilities, Integer bandwidth)
237             throws JSONException {
238
239         JSONObject nodeConnector = nodeConnectorProperties.getJSONObject("nodeconnector");
240         JSONObject node = nodeConnector.getJSONObject("node");
241         JSONObject properties = nodeConnectorProperties.getJSONObject("properties");
242
243         Assert.assertEquals(ncId, (Integer) nodeConnector.getInt("id"));
244         Assert.assertEquals(ncType, nodeConnector.getString("type"));
245         Assert.assertEquals(nodeId, (Integer) node.getInt("id"));
246         Assert.assertEquals(nodeType, node.getString("type"));
247         if (state == null) {
248             Assert.assertFalse(properties.has("state"));
249         } else {
250             Assert.assertEquals(state, (Integer) properties.getJSONObject("state").getInt("value"));
251         }
252         if (capabilities == null) {
253             Assert.assertFalse(properties.has("capabilities"));
254         } else {
255             Assert.assertEquals(capabilities,
256                     (Integer) properties.getJSONObject("capabilities").getInt("value"));
257         }
258         if (bandwidth == null) {
259             Assert.assertFalse(properties.has("bandwidth"));
260         } else {
261             Assert.assertEquals(bandwidth, (Integer) properties.getJSONObject("bandwidth").getInt("value"));
262         }
263     }
264
265     @Test
266     public void testSubnetsNorthbound() throws JSONException, ConstructionException {
267         System.out.println("Starting Subnets JAXB client.");
268         String baseURL = "http://127.0.0.1:8080/controller/nb/v2/subnetservice/";
269
270         String name1 = "testSubnet1";
271         String subnet1 = "1.1.1.1/24";
272
273         String name2 = "testSubnet2";
274         String subnet2 = "2.2.2.2/24";
275
276         String name3 = "testSubnet3";
277         String subnet3 = "3.3.3.3/24";
278
279         /*
280          * Create the node connector string list for the two subnets as:
281          * portList2 = {"OF|1@OF|00:00:00:00:00:00:00:02", "OF|2@OF|00:00:00:00:00:00:00:02", "OF|3@OF|00:00:00:00:00:00:00:02", "OF|4@OF|00:00:00:00:00:00:00:02"};
282          * portList3 = {"OF|1@OF|00:00:00:00:00:00:00:03", "OF|2@OF|00:00:00:00:00:00:00:03", "OF|3@OF|00:00:00:00:00:00:00:03"};
283          */
284         Node node2 = new Node(Node.NodeIDType.OPENFLOW, 2L);
285         List<String> portList2 = new ArrayList<String>();
286         NodeConnector nc21 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)1, node2);
287         NodeConnector nc22 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)2, node2);
288         NodeConnector nc23 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)3, node2);
289         NodeConnector nc24 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)3, node2);
290         portList2.add(nc21.toString());
291         portList2.add(nc22.toString());
292         portList2.add(nc23.toString());
293         portList2.add(nc24.toString());
294
295         List<String> portList3 = new ArrayList<String>();
296         Node node3 = new Node(Node.NodeIDType.OPENFLOW, 3L);
297         NodeConnector nc31 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)1, node3);
298         NodeConnector nc32 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)2, node3);
299         NodeConnector nc33 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)3, node3);
300         portList3.add(nc31.toString());
301         portList3.add(nc32.toString());
302         portList3.add(nc33.toString());
303
304         // Test GET subnets in default container
305         String result = getJsonResult(baseURL + "default/subnets");
306         JSONTokener jt = new JSONTokener(result);
307         JSONObject json = new JSONObject(jt);
308         JSONArray subnetConfigs = json.getJSONArray("subnetConfig");
309         Assert.assertEquals(subnetConfigs.length(), 0);
310
311         // Test GET subnet1 expecting 404
312         result = getJsonResult(baseURL + "default/subnet/" + name1);
313         Assert.assertEquals(404, httpResponseCode.intValue());
314
315         // Test POST subnet1
316         JSONObject jo = new JSONObject().put("name", name1).put("subnet", subnet1);
317         // execute HTTP request and verify response code
318         result = getJsonResult(baseURL + "default/subnet/" + name1, "PUT", jo.toString());
319         Assert.assertTrue(httpResponseCode == 201);
320
321         // Test GET subnet1
322         result = getJsonResult(baseURL + "default/subnet/" + name1);
323         jt = new JSONTokener(result);
324         json = new JSONObject(jt);
325         Assert.assertEquals(200, httpResponseCode.intValue());
326         Assert.assertEquals(name1, json.getString("name"));
327         Assert.assertEquals(subnet1, json.getString("subnet"));
328
329         // Test PUT subnet2
330         JSONObject jo2 = new JSONObject().put("name", name2).put("subnet", subnet2).put("nodeConnectors", portList2);
331         // execute HTTP request and verify response code
332         result = getJsonResult(baseURL + "default/subnet/" + name2, "PUT", jo2.toString());
333         Assert.assertEquals(201, httpResponseCode.intValue());
334         // Test PUT subnet3
335         JSONObject jo3 = new JSONObject().put("name", name3).put("subnet", subnet3);
336         // execute HTTP request and verify response code
337         result = getJsonResult(baseURL + "default/subnet/" + name3, "PUT", jo3.toString());
338         Assert.assertEquals(201, httpResponseCode.intValue());
339         // Test POST subnet3 (modify port list: add)
340         JSONObject jo3New = new JSONObject().put("name", name3).put("subnet", subnet3).put("nodeConnectors", portList3);
341         // execute HTTP request and verify response code
342         result = getJsonResult(baseURL + "default/subnet/" + name3, "POST", jo3New.toString());
343         Assert.assertEquals(200, httpResponseCode.intValue());
344
345         // Test GET all subnets in default container
346         result = getJsonResult(baseURL + "default/subnets");
347         jt = new JSONTokener(result);
348         json = new JSONObject(jt);
349         JSONArray subnetConfigArray = json.getJSONArray("subnetConfig");
350         JSONObject subnetConfig;
351         Assert.assertEquals(3, subnetConfigArray.length());
352         for (int i = 0; i < subnetConfigArray.length(); i++) {
353             subnetConfig = subnetConfigArray.getJSONObject(i);
354             if (subnetConfig.getString("name").equals(name1)) {
355                 Assert.assertEquals(subnet1, subnetConfig.getString("subnet"));
356             } else if (subnetConfig.getString("name").equals(name2)) {
357                 Assert.assertEquals(subnet2, subnetConfig.getString("subnet"));
358                 JSONArray portListGet = subnetConfig.getJSONArray("nodeConnectors");
359                 Assert.assertEquals(portList2.get(0), portListGet.get(0));
360                 Assert.assertEquals(portList2.get(1), portListGet.get(1));
361                 Assert.assertEquals(portList2.get(2), portListGet.get(2));
362                 Assert.assertEquals(portList2.get(3), portListGet.get(3));
363             } else if (subnetConfig.getString("name").equals(name3)) {
364                 Assert.assertEquals(subnet3, subnetConfig.getString("subnet"));
365                 JSONArray portListGet = subnetConfig.getJSONArray("nodeConnectors");
366                 Assert.assertEquals(portList3.get(0), portListGet.get(0));
367                 Assert.assertEquals(portList3.get(1), portListGet.get(1));
368                 Assert.assertEquals(portList3.get(2), portListGet.get(2));
369             } else {
370                 // Unexpected config name
371                 Assert.assertTrue(false);
372             }
373         }
374
375         // Test POST subnet2 (modify port list: remove one port only)
376         List<String> newPortList2 = new ArrayList<String>(portList2);
377         newPortList2.remove(3);
378         JSONObject jo2New = new JSONObject().put("name", name2).put("subnet", subnet2).put("nodeConnectors", newPortList2);
379         // execute HTTP request and verify response code
380         result = getJsonResult(baseURL + "default/subnet/" + name2, "POST", jo2New.toString());
381         Assert.assertEquals(200, httpResponseCode.intValue());
382
383         // Test GET subnet2: verify contains only the first three ports
384         result = getJsonResult(baseURL + "default/subnet/" + name2);
385         jt = new JSONTokener(result);
386         subnetConfig = new JSONObject(jt);
387         Assert.assertEquals(200, httpResponseCode.intValue());
388         JSONArray portListGet2 = subnetConfig.getJSONArray("nodeConnectors");
389         Assert.assertEquals(portList2.get(0), portListGet2.get(0));
390         Assert.assertEquals(portList2.get(1), portListGet2.get(1));
391         Assert.assertEquals(portList2.get(2), portListGet2.get(2));
392         Assert.assertTrue(portListGet2.length() == 3);
393
394         // Test DELETE subnet1
395         result = getJsonResult(baseURL + "default/subnet/" + name1, "DELETE");
396         Assert.assertEquals(204, httpResponseCode.intValue());
397
398         // Test GET deleted subnet1
399         result = getJsonResult(baseURL + "default/subnet/" + name1);
400         Assert.assertEquals(404, httpResponseCode.intValue());
401
402         // TEST PUT bad subnet, expect 400, validate JSON exception mapper
403         JSONObject joBad = new JSONObject().put("foo", "bar");
404         result = getJsonResult(baseURL + "default/subnet/foo", "PUT", joBad.toString());
405         Assert.assertEquals(400, httpResponseCode.intValue());
406   }
407
408     @Test
409     public void testStaticRoutingNorthbound() throws JSONException {
410         System.out.println("Starting StaticRouting JAXB client.");
411         String baseURL = "http://127.0.0.1:8080/controller/nb/v2/staticroute/";
412
413         String name1 = "testRoute1";
414         String prefix1 = "192.168.1.1/24";
415         String nextHop1 = "0.0.0.0";
416         String name2 = "testRoute2";
417         String prefix2 = "192.168.1.1/16";
418         String nextHop2 = "1.1.1.1";
419
420         // Test GET static routes in default container, expecting no results
421         String result = getJsonResult(baseURL + "default/routes");
422         JSONTokener jt = new JSONTokener(result);
423         JSONObject json = new JSONObject(jt);
424         JSONArray staticRoutes = json.getJSONArray("staticRoute");
425         Assert.assertEquals(staticRoutes.length(), 0);
426
427         // Test insert static route
428         String requestBody = "{\"name\":\"" + name1 + "\", \"prefix\":\"" + prefix1 + "\", \"nextHop\":\"" + nextHop1
429                 + "\"}";
430         result = getJsonResult(baseURL + "default/route/" + name1, "PUT", requestBody);
431         Assert.assertEquals(201, httpResponseCode.intValue());
432
433         requestBody = "{\"name\":\"" + name2 + "\", \"prefix\":\"" + prefix2 + "\", \"nextHop\":\"" + nextHop2 + "\"}";
434         result = getJsonResult(baseURL + "default/route/" + name2, "PUT", requestBody);
435         Assert.assertEquals(201, httpResponseCode.intValue());
436
437         // Test Get all static routes
438         result = getJsonResult(baseURL + "default/routes");
439         jt = new JSONTokener(result);
440         json = new JSONObject(jt);
441         JSONArray staticRouteArray = json.getJSONArray("staticRoute");
442         Assert.assertEquals(2, staticRouteArray.length());
443         JSONObject route;
444         for (int i = 0; i < staticRoutes.length(); i++) {
445             route = staticRoutes.getJSONObject(i);
446             if (route.getString("name").equals(name1)) {
447                 Assert.assertEquals(prefix1, route.getString("prefix"));
448                 Assert.assertEquals(nextHop1, route.getString("nextHop"));
449             } else if (route.getString("name").equals(name2)) {
450                 Assert.assertEquals(prefix2, route.getString("prefix"));
451                 Assert.assertEquals(nextHop2, route.getString("nextHop"));
452             } else {
453                 // static route has unknown name
454                 Assert.assertTrue(false);
455             }
456         }
457
458         // Test get specific static route
459         result = getJsonResult(baseURL + "default/route/" + name1);
460         jt = new JSONTokener(result);
461         json = new JSONObject(jt);
462
463         Assert.assertEquals(name1, json.getString("name"));
464         Assert.assertEquals(prefix1, json.getString("prefix"));
465         Assert.assertEquals(nextHop1, json.getString("nextHop"));
466
467         result = getJsonResult(baseURL + "default/route/" + name2);
468         jt = new JSONTokener(result);
469         json = new JSONObject(jt);
470
471         Assert.assertEquals(name2, json.getString("name"));
472         Assert.assertEquals(prefix2, json.getString("prefix"));
473         Assert.assertEquals(nextHop2, json.getString("nextHop"));
474
475         // Test delete static route
476         result = getJsonResult(baseURL + "default/route/" + name1, "DELETE");
477         Assert.assertEquals(204, httpResponseCode.intValue());
478
479         result = getJsonResult(baseURL + "default/routes");
480         jt = new JSONTokener(result);
481         json = new JSONObject(jt);
482
483         staticRouteArray = json.getJSONArray("staticRoute");
484         JSONObject singleStaticRoute = staticRouteArray.getJSONObject(0);
485         Assert.assertEquals(name2, singleStaticRoute.getString("name"));
486
487     }
488
489     @Test
490     public void testSwitchManager() throws JSONException {
491         System.out.println("Starting SwitchManager JAXB client.");
492         String baseURL = "http://127.0.0.1:8080/controller/nb/v2/switchmanager/default/";
493
494         // define Node/NodeConnector attributes for test
495         int nodeId_1 = 51966;
496         int nodeId_2 = 3366;
497         int nodeId_3 = 4477;
498         int nodeConnectorId_1 = 51966;
499         int nodeConnectorId_2 = 12;
500         int nodeConnectorId_3 = 34;
501         String nodeType = "STUB";
502         String ncType = "STUB";
503         int timestamp_1 = 100000;
504         String timestampName_1 = "connectedSince";
505         int actionsValue_1 = 2;
506         int capabilitiesValue_1 = 3;
507         int tablesValue_1 = 1;
508         int buffersValue_1 = 1;
509         int ncState = 1;
510         int ncCapabilities = 1;
511         int ncBandwidth = 1000000000;
512
513         // Test GET all nodes
514
515         String result = getJsonResult(baseURL + "nodes");
516         JSONTokener jt = new JSONTokener(result);
517         JSONObject json = new JSONObject(jt);
518
519         // Test for first node
520         JSONObject node = getJsonInstance(json, "nodeProperties", nodeId_1);
521         Assert.assertNotNull(node);
522         testNodeProperties(node, nodeId_1, nodeType, timestamp_1, timestampName_1, actionsValue_1, capabilitiesValue_1,
523                 tablesValue_1, buffersValue_1);
524
525         // Test 2nd node, properties of 2nd node same as first node
526         node = getJsonInstance(json, "nodeProperties", nodeId_2);
527         Assert.assertNotNull(node);
528         testNodeProperties(node, nodeId_2, nodeType, timestamp_1, timestampName_1, actionsValue_1, capabilitiesValue_1,
529                 tablesValue_1, buffersValue_1);
530
531         // Test 3rd node, properties of 3rd node same as first node
532         node = getJsonInstance(json, "nodeProperties", nodeId_3);
533         Assert.assertNotNull(node);
534         testNodeProperties(node, nodeId_3, nodeType, timestamp_1, timestampName_1, actionsValue_1, capabilitiesValue_1,
535                 tablesValue_1, buffersValue_1);
536
537         // Test GET nodeConnectors of a node
538         // Test first node
539         result = getJsonResult(baseURL + "node/STUB/" + nodeId_1);
540         jt = new JSONTokener(result);
541         json = new JSONObject(jt);
542         JSONArray nodeConnectorPropertiesArray = json.getJSONArray("nodeConnectorProperties");
543         JSONObject nodeConnectorProperties = nodeConnectorPropertiesArray.getJSONObject(0);
544
545         testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_1, ncType, nodeId_1, nodeType, ncState,
546                 ncCapabilities, ncBandwidth);
547
548         // Test second node
549         result = getJsonResult(baseURL + "node/STUB/" + nodeId_2);
550         jt = new JSONTokener(result);
551         json = new JSONObject(jt);
552
553         nodeConnectorPropertiesArray = json.getJSONArray("nodeConnectorProperties");
554         nodeConnectorProperties = nodeConnectorPropertiesArray.getJSONObject(0);
555
556
557         testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_2, ncType, nodeId_2, nodeType, ncState,
558                 ncCapabilities, ncBandwidth);
559
560         // Test third node
561         result = getJsonResult(baseURL + "node/STUB/" + nodeId_3);
562         jt = new JSONTokener(result);
563         json = new JSONObject(jt);
564
565         nodeConnectorPropertiesArray = json.getJSONArray("nodeConnectorProperties");
566         nodeConnectorProperties = nodeConnectorPropertiesArray.getJSONObject(0);
567         testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_3, ncType, nodeId_3, nodeType, ncState,
568                 ncCapabilities, ncBandwidth);
569
570         // Test add property to node
571         // Add Tier and Description property to node1
572         result = getJsonResult(baseURL + "node/STUB/" + nodeId_1 + "/property/tier/1001", "PUT");
573         Assert.assertEquals(201, httpResponseCode.intValue());
574         result = getJsonResult(baseURL + "node/STUB/" + nodeId_1 + "/property/description/node1", "PUT");
575         Assert.assertEquals(201, httpResponseCode.intValue());
576
577         // Test for first node
578         result = getJsonResult(baseURL + "nodes");
579         jt = new JSONTokener(result);
580         json = new JSONObject(jt);
581         node = getJsonInstance(json, "nodeProperties", nodeId_1);
582         Assert.assertNotNull(node);
583         Assert.assertEquals(1001, node.getJSONObject("properties").getJSONObject("tier").getInt("value"));
584         Assert.assertEquals("node1", node.getJSONObject("properties").getJSONObject("description").getString("value"));
585
586         // Test delete nodeConnector property
587         // Delete state property of nodeconnector1
588         result = getJsonResult(baseURL + "nodeconnector/STUB/" + nodeId_1 + "/STUB/" + nodeConnectorId_1
589                 + "/property/state", "DELETE");
590         Assert.assertEquals(204, httpResponseCode.intValue());
591
592         result = getJsonResult(baseURL + "node/STUB/" + nodeId_1);
593         jt = new JSONTokener(result);
594         json = new JSONObject(jt);
595         nodeConnectorPropertiesArray = json.getJSONArray("nodeConnectorProperties");
596         nodeConnectorProperties = nodeConnectorPropertiesArray.getJSONObject(0);
597
598         testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_1, ncType, nodeId_1, nodeType, null,
599                 ncCapabilities, ncBandwidth);
600
601         // Delete capabilities property of nodeconnector2
602         result = getJsonResult(baseURL + "nodeconnector/STUB/" + nodeId_2 + "/STUB/" + nodeConnectorId_2
603                 + "/property/capabilities", "DELETE");
604         Assert.assertEquals(204, httpResponseCode.intValue());
605
606         result = getJsonResult(baseURL + "node/STUB/" + nodeId_2);
607         jt = new JSONTokener(result);
608         json = new JSONObject(jt);
609         nodeConnectorPropertiesArray = json.getJSONArray("nodeConnectorProperties");
610         nodeConnectorProperties = nodeConnectorPropertiesArray.getJSONObject(0);
611
612         testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_2, ncType, nodeId_2, nodeType, ncState,
613                 null, ncBandwidth);
614
615         // Test PUT nodeConnector property
616         int newBandwidth = 1001;
617
618         // Add Name/Bandwidth property to nodeConnector1
619         result = getJsonResult(baseURL + "nodeconnector/STUB/" + nodeId_1 + "/STUB/" + nodeConnectorId_1
620                 + "/property/bandwidth/" + newBandwidth, "PUT");
621         Assert.assertEquals(201, httpResponseCode.intValue());
622
623         result = getJsonResult(baseURL + "node/STUB/" + nodeId_1);
624         jt = new JSONTokener(result);
625         json = new JSONObject(jt);
626         nodeConnectorPropertiesArray = json.getJSONArray("nodeConnectorProperties");
627         nodeConnectorProperties = nodeConnectorPropertiesArray.getJSONObject(0);
628
629         // Check for new bandwidth value, state value removed from previous
630         // test
631         testNodeConnectorProperties(nodeConnectorProperties, nodeConnectorId_1, ncType, nodeId_1, nodeType, null,
632                 ncCapabilities, newBandwidth);
633
634     }
635
636     @Test
637     public void testStatistics() throws JSONException {
638         final String actionTypes[] = { "DROP", "LOOPBACK", "FLOOD", "FLOOD_ALL", "CONTROLLER", "SW_PATH", "HW_PATH", "OUTPUT",
639                 "SET_DL_SRC", "SET_DL_DST", "SET_DL_TYPE", "SET_VLAN_ID", "SET_VLAN_PCP", "SET_VLAN_CFI", "POP_VLAN", "PUSH_VLAN",
640                 "SET_NW_SRC", "SET_NW_DST", "SET_NW_TOS", "SET_TP_SRC", "SET_TP_DST" };
641         System.out.println("Starting Statistics JAXB client.");
642
643         String baseURL = "http://127.0.0.1:8080/controller/nb/v2/statistics/default/";
644
645         String result = getJsonResult(baseURL + "flow");
646         JSONTokener jt = new JSONTokener(result);
647         JSONObject json = new JSONObject(jt);
648         JSONObject flowStatistics = getJsonInstance(json, "flowStatistics", 0xCAFE);
649         JSONObject node = flowStatistics.getJSONObject("node");
650         // test that node was returned properly
651         Assert.assertTrue(node.getInt("id") == 0xCAFE);
652         Assert.assertEquals(node.getString("type"), "STUB");
653
654         // test that flow statistics results are correct
655         JSONArray flowStats = flowStatistics.getJSONArray("flowStatistic");
656         for (int i = 0; i < flowStats.length(); i++) {
657
658             JSONObject flowStat = flowStats.getJSONObject(i);
659             testFlowStat(flowStat, actionTypes[i], i);
660
661         }
662
663         // for /controller/nb/v2/statistics/default/port
664         result = getJsonResult(baseURL + "port");
665         jt = new JSONTokener(result);
666         json = new JSONObject(jt);
667         JSONObject portStatistics = getJsonInstance(json, "portStatistics", 0xCAFE);
668         JSONObject node2 = portStatistics.getJSONObject("node");
669         // test that node was returned properly
670         Assert.assertTrue(node2.getInt("id") == 0xCAFE);
671         Assert.assertEquals(node2.getString("type"), "STUB");
672
673         // test that port statistic results are correct
674         JSONArray portStatArray = portStatistics.getJSONArray("portStatistic");
675         JSONObject portStat = portStatArray.getJSONObject(0);
676         Assert.assertTrue(portStat.getInt("receivePackets") == 250);
677         Assert.assertTrue(portStat.getInt("transmitPackets") == 500);
678         Assert.assertTrue(portStat.getInt("receiveBytes") == 1000);
679         Assert.assertTrue(portStat.getInt("transmitBytes") == 5000);
680         Assert.assertTrue(portStat.getInt("receiveDrops") == 2);
681         Assert.assertTrue(portStat.getInt("transmitDrops") == 50);
682         Assert.assertTrue(portStat.getInt("receiveErrors") == 3);
683         Assert.assertTrue(portStat.getInt("transmitErrors") == 10);
684         Assert.assertTrue(portStat.getInt("receiveFrameError") == 5);
685         Assert.assertTrue(portStat.getInt("receiveOverRunError") == 6);
686         Assert.assertTrue(portStat.getInt("receiveCrcError") == 1);
687         Assert.assertTrue(portStat.getInt("collisionCount") == 4);
688
689         // test for getting one specific node's stats
690         result = getJsonResult(baseURL + "flow/node/STUB/51966");
691         jt = new JSONTokener(result);
692         json = new JSONObject(jt);
693         node = json.getJSONObject("node");
694         // test that node was returned properly
695         Assert.assertTrue(node.getInt("id") == 0xCAFE);
696         Assert.assertEquals(node.getString("type"), "STUB");
697
698         // test that flow statistics results are correct
699         flowStats = json.getJSONArray("flowStatistic");
700         for (int i = 0; i < flowStats.length(); i++) {
701             JSONObject flowStat = flowStats.getJSONObject(i);
702             testFlowStat(flowStat, actionTypes[i], i);
703         }
704
705         result = getJsonResult(baseURL + "port/node/STUB/51966");
706         jt = new JSONTokener(result);
707         json = new JSONObject(jt);
708         node2 = json.getJSONObject("node");
709         // test that node was returned properly
710         Assert.assertTrue(node2.getInt("id") == 0xCAFE);
711         Assert.assertEquals(node2.getString("type"), "STUB");
712
713         // test that port statistic results are correct
714         portStatArray = json.getJSONArray("portStatistic");
715         portStat = portStatArray.getJSONObject(0);
716
717         Assert.assertTrue(portStat.getInt("receivePackets") == 250);
718         Assert.assertTrue(portStat.getInt("transmitPackets") == 500);
719         Assert.assertTrue(portStat.getInt("receiveBytes") == 1000);
720         Assert.assertTrue(portStat.getInt("transmitBytes") == 5000);
721         Assert.assertTrue(portStat.getInt("receiveDrops") == 2);
722         Assert.assertTrue(portStat.getInt("transmitDrops") == 50);
723         Assert.assertTrue(portStat.getInt("receiveErrors") == 3);
724         Assert.assertTrue(portStat.getInt("transmitErrors") == 10);
725         Assert.assertTrue(portStat.getInt("receiveFrameError") == 5);
726         Assert.assertTrue(portStat.getInt("receiveOverRunError") == 6);
727         Assert.assertTrue(portStat.getInt("receiveCrcError") == 1);
728         Assert.assertTrue(portStat.getInt("collisionCount") == 4);
729     }
730
731     private void testFlowStat(JSONObject flowStat, String actionType, int actIndex) throws JSONException {
732         Assert.assertTrue(flowStat.getInt("tableId") == 1);
733         Assert.assertTrue(flowStat.getInt("durationSeconds") == 40);
734         Assert.assertTrue(flowStat.getInt("durationNanoseconds") == 400);
735         Assert.assertTrue(flowStat.getInt("packetCount") == 200);
736         Assert.assertTrue(flowStat.getInt("byteCount") == 100);
737
738         // test that flow information is correct
739         JSONObject flow = flowStat.getJSONObject("flow");
740         Assert.assertTrue(flow.getInt("priority") == (3500 + actIndex));
741         Assert.assertTrue(flow.getInt("idleTimeout") == 1000);
742         Assert.assertTrue(flow.getInt("hardTimeout") == 2000);
743         Assert.assertTrue(flow.getInt("id") == 12345);
744
745         JSONArray matches = (flow.getJSONObject("match").getJSONArray("matchField"));
746         Assert.assertEquals(matches.length(), 1);
747         JSONObject match = matches.getJSONObject(0);
748         Assert.assertTrue(match.getString("type").equals("NW_DST"));
749         Assert.assertTrue(match.getString("value").equals("1.1.1.1"));
750
751         JSONArray actionsArray = flow.getJSONArray("actions");
752         Assert.assertEquals(actionsArray.length(), 1);
753         JSONObject act = actionsArray.getJSONObject(0);
754         Assert.assertTrue(act.getString("type").equals(actionType));
755
756         if (act.getString("type").equals("OUTPUT")) {
757             JSONObject port = act.getJSONObject("port");
758             JSONObject port_node = port.getJSONObject("node");
759             Assert.assertTrue(port.getInt("id") == 51966);
760             Assert.assertTrue(port.getString("type").equals("STUB"));
761             Assert.assertTrue(port_node.getInt("id") == 51966);
762             Assert.assertTrue(port_node.getString("type").equals("STUB"));
763         }
764
765         if (act.getString("type").equals("SET_DL_SRC")) {
766             byte srcMatch[] = { (byte) 5, (byte) 4, (byte) 3, (byte) 2, (byte) 1 };
767             String src = act.getString("address");
768             byte srcBytes[] = new byte[5];
769             srcBytes[0] = Byte.parseByte(src.substring(0, 2));
770             srcBytes[1] = Byte.parseByte(src.substring(2, 4));
771             srcBytes[2] = Byte.parseByte(src.substring(4, 6));
772             srcBytes[3] = Byte.parseByte(src.substring(6, 8));
773             srcBytes[4] = Byte.parseByte(src.substring(8, 10));
774             Assert.assertTrue(Arrays.equals(srcBytes, srcMatch));
775         }
776
777         if (act.getString("type").equals("SET_DL_DST")) {
778             byte dstMatch[] = { (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5 };
779             String dst = act.getString("address");
780             byte dstBytes[] = new byte[5];
781             dstBytes[0] = Byte.parseByte(dst.substring(0, 2));
782             dstBytes[1] = Byte.parseByte(dst.substring(2, 4));
783             dstBytes[2] = Byte.parseByte(dst.substring(4, 6));
784             dstBytes[3] = Byte.parseByte(dst.substring(6, 8));
785             dstBytes[4] = Byte.parseByte(dst.substring(8, 10));
786             Assert.assertTrue(Arrays.equals(dstBytes, dstMatch));
787         }
788         if (act.getString("type").equals("SET_DL_TYPE")) {
789             Assert.assertTrue(act.getInt("dlType") == 10);
790         }
791         if (act.getString("type").equals("SET_VLAN_ID")) {
792             Assert.assertTrue(act.getInt("vlanId") == 2);
793         }
794         if (act.getString("type").equals("SET_VLAN_PCP")) {
795             Assert.assertTrue(act.getInt("pcp") == 3);
796         }
797         if (act.getString("type").equals("SET_VLAN_CFI")) {
798             Assert.assertTrue(act.getInt("cfi") == 1);
799         }
800
801         if (act.getString("type").equals("SET_NW_SRC")) {
802             Assert.assertTrue(act.getString("address").equals("2.2.2.2"));
803         }
804         if (act.getString("type").equals("SET_NW_DST")) {
805             Assert.assertTrue(act.getString("address").equals("1.1.1.1"));
806         }
807
808         if (act.getString("type").equals("PUSH_VLAN")) {
809             int head = act.getInt("VlanHeader");
810             // parsing vlan header
811             int id = head & 0xfff;
812             int cfi = (head >> 12) & 0x1;
813             int pcp = (head >> 13) & 0x7;
814             int tag = (head >> 16) & 0xffff;
815             Assert.assertTrue(id == 1234);
816             Assert.assertTrue(cfi == 1);
817             Assert.assertTrue(pcp == 1);
818             Assert.assertTrue(tag == 0x8100);
819         }
820         if (act.getString("type").equals("SET_NW_TOS")) {
821             Assert.assertTrue(act.getInt("tos") == 16);
822         }
823         if (act.getString("type").equals("SET_TP_SRC")) {
824             Assert.assertTrue(act.getInt("port") == 4201);
825         }
826         if (act.getString("type").equals("SET_TP_DST")) {
827             Assert.assertTrue(act.getInt("port") == 8080);
828         }
829     }
830
831     @Test
832     public void testFlowProgrammer() throws JSONException {
833         System.out.println("Starting FlowProgrammer JAXB client.");
834         String baseURL = "http://127.0.0.1:8080/controller/nb/v2/flowprogrammer/default/";
835         // Attempt to get a flow that doesn't exit. Should return 404
836         // status.
837         String result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test1", "GET");
838         Assert.assertTrue(result.equals("404"));
839
840         // test add flow1
841         String fc = "{\"name\":\"test1\", \"node\":{\"id\":\"51966\",\"type\":\"STUB\"}, \"actions\":[\"DROP\"]}";
842         result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test1", "PUT", fc);
843         Assert.assertTrue(httpResponseCode == 201);
844
845         // test get returns flow that was added.
846         result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test1", "GET");
847         // check that result came out fine.
848         Assert.assertTrue(httpResponseCode == 200);
849         JSONTokener jt = new JSONTokener(result);
850         JSONObject json = new JSONObject(jt);
851         Assert.assertEquals(json.getString("name"), "test1");
852         JSONArray actionsArray = json.getJSONArray("actions");
853         Assert.assertEquals(actionsArray.getString(0), "DROP");
854         Assert.assertEquals(json.getString("installInHw"), "true");
855         JSONObject node = json.getJSONObject("node");
856         Assert.assertEquals(node.getString("type"), "STUB");
857         Assert.assertEquals(node.getString("id"), "51966");
858         // test adding same flow again fails due to repeat name..return 409
859         // code
860         result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test1", "PUT", fc);
861         Assert.assertTrue(result.equals("409"));
862
863         fc = "{\"name\":\"test2\", \"node\":{\"id\":\"51966\",\"type\":\"STUB\"}, \"actions\":[\"DROP\"]}";
864         result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test2", "PUT", fc);
865         // test should return 409 for error due to same flow being added.
866         Assert.assertTrue(result.equals("409"));
867
868         // add second flow that's different
869         fc = "{\"name\":\"test2\", \"nwSrc\":\"1.1.1.1\", \"node\":{\"id\":\"51966\",\"type\":\"STUB\"}, \"actions\":[\"DROP\"]}";
870         result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test2", "PUT", fc);
871         Assert.assertTrue(httpResponseCode == 201);
872
873         // check that request returns both flows given node.
874         result = getJsonResult(baseURL + "node/STUB/51966/", "GET");
875         jt = new JSONTokener(result);
876         json = new JSONObject(jt);
877         Assert.assertTrue(json.get("flowConfig") instanceof JSONArray);
878         JSONArray ja = json.getJSONArray("flowConfig");
879         Integer count = ja.length();
880         Assert.assertTrue(count == 2);
881
882         // check that request returns both flows given just container.
883         result = getJsonResult(baseURL);
884         jt = new JSONTokener(result);
885         json = new JSONObject(jt);
886         Assert.assertTrue(json.get("flowConfig") instanceof JSONArray);
887         ja = json.getJSONArray("flowConfig");
888         count = ja.length();
889         Assert.assertTrue(count == 2);
890
891         // delete a flow, check that it's no longer in list.
892         result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test2", "DELETE");
893         Assert.assertTrue(httpResponseCode == 204);
894
895         result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test2", "GET");
896         Assert.assertTrue(result.equals("404"));
897     }
898
899     // method to extract a JSONObject with specified node ID from a JSONObject
900     // that may contain an array of JSONObjects
901     // This is specifically written for statistics manager northbound REST
902     // interface
903     // array_name should be either "flowStatistics" or "portStatistics"
904     private JSONObject getJsonInstance(JSONObject json, String array_name, Integer nodeId) throws JSONException {
905         JSONObject result = null;
906         if (json.get(array_name) instanceof JSONArray) {
907             JSONArray json_array = json.getJSONArray(array_name);
908             for (int i = 0; i < json_array.length(); i++) {
909                 result = json_array.getJSONObject(i);
910                 Integer nid = result.getJSONObject("node").getInt("id");
911                 if (nid.equals(nodeId)) {
912                     break;
913                 }
914             }
915         } else {
916             result = json.getJSONObject(array_name);
917             Integer nid = result.getJSONObject("node").getInt("id");
918             if (!nid.equals(nodeId)) {
919                 result = null;
920             }
921         }
922         return result;
923     }
924
925     // a class to construct query parameter for HTTP request
926     private class QueryParameter {
927         StringBuilder queryString = null;
928
929         // constructor
930         QueryParameter(String key, String value) {
931             queryString = new StringBuilder();
932             queryString.append("?").append(key).append("=").append(value);
933         }
934
935         // method to add more query parameter
936         QueryParameter add(String key, String value) {
937             this.queryString.append("&").append(key).append("=").append(value);
938             return this;
939         }
940
941         // method to get the query parameter string
942         String getString() {
943             return this.queryString.toString();
944         }
945
946     }
947
948     @Test
949     public void testHostTracker() throws JSONException {
950
951         System.out.println("Starting HostTracker JAXB client.");
952
953         // setup 2 host models for @POST method
954         // 1st host
955         String networkAddress_1 = "192.168.0.8";
956         String dataLayerAddress_1 = "11:22:33:44:55:66";
957         String nodeType_1 = "STUB";
958         Integer nodeId_1 = 3366;
959         String nodeConnectorType_1 = "STUB";
960         Integer nodeConnectorId_1 = 12;
961         String vlan_1 = "";
962
963         // 2nd host
964         String networkAddress_2 = "10.1.1.1";
965         String dataLayerAddress_2 = "1A:2B:3C:4D:5E:6F";
966         String nodeType_2 = "STUB";
967         Integer nodeId_2 = 4477;
968         String nodeConnectorType_2 = "STUB";
969         Integer nodeConnectorId_2 = 34;
970         String vlan_2 = "123";
971
972         String baseURL = "http://127.0.0.1:8080/controller/nb/v2/hosttracker/default";
973
974         // test PUT method: addHost()
975         JSONObject fc_json = new JSONObject();
976         fc_json.put("dataLayerAddress", dataLayerAddress_1);
977         fc_json.put("nodeType", nodeType_1);
978         fc_json.put("nodeId", nodeId_1);
979         fc_json.put("nodeConnectorType", nodeType_1);
980         fc_json.put("nodeConnectorId", nodeConnectorId_1.toString());
981         fc_json.put("vlan", vlan_1);
982         fc_json.put("staticHost", "true");
983         fc_json.put("networkAddress", networkAddress_1);
984
985         String result = getJsonResult(baseURL + "/address/" + networkAddress_1, "PUT", fc_json.toString());
986         Assert.assertTrue(httpResponseCode == 201);
987
988         fc_json = new JSONObject();
989         fc_json.put("dataLayerAddress", dataLayerAddress_2);
990         fc_json.put("nodeType", nodeType_2);
991         fc_json.put("nodeId", nodeId_2);
992         fc_json.put("nodeConnectorType", nodeType_2);
993         fc_json.put("nodeConnectorId", nodeConnectorId_2.toString());
994         fc_json.put("vlan", vlan_2);
995         fc_json.put("staticHost", "true");
996         fc_json.put("networkAddress", networkAddress_2);
997
998         result = getJsonResult(baseURL + "/address/" + networkAddress_2 , "PUT", fc_json.toString());
999         Assert.assertTrue(httpResponseCode == 201);
1000
1001         // define variables for decoding returned strings
1002         String networkAddress;
1003         JSONObject host_jo;
1004
1005         // the two hosts should be in inactive host DB
1006         // test GET method: getInactiveHosts()
1007         result = getJsonResult(baseURL + "/hosts/inactive", "GET");
1008         Assert.assertTrue(httpResponseCode == 200);
1009
1010         JSONTokener jt = new JSONTokener(result);
1011         JSONObject json = new JSONObject(jt);
1012         // there should be at least two hosts in the DB
1013         Assert.assertTrue(json.get("hostConfig") instanceof JSONArray);
1014         JSONArray ja = json.getJSONArray("hostConfig");
1015         Integer count = ja.length();
1016         Assert.assertTrue(count == 2);
1017
1018         for (int i = 0; i < count; i++) {
1019             host_jo = ja.getJSONObject(i);
1020             networkAddress = host_jo.getString("networkAddress");
1021             if (networkAddress.equalsIgnoreCase(networkAddress_1)) {
1022                 Assert.assertTrue(host_jo.getString("dataLayerAddress").equalsIgnoreCase(dataLayerAddress_1));
1023                 Assert.assertTrue(host_jo.getString("nodeConnectorType").equalsIgnoreCase(nodeConnectorType_1));
1024                 Assert.assertTrue(host_jo.getInt("nodeConnectorId") == nodeConnectorId_1);
1025                 Assert.assertTrue(host_jo.getString("nodeType").equalsIgnoreCase(nodeType_1));
1026                 Assert.assertTrue(host_jo.getInt("nodeId") == nodeId_1);
1027                 Assert.assertTrue(host_jo.getString("vlan").equals("0"));
1028                 Assert.assertTrue(host_jo.getBoolean("staticHost"));
1029             } else if (networkAddress.equalsIgnoreCase(networkAddress_2)) {
1030                 Assert.assertTrue(host_jo.getString("dataLayerAddress").equalsIgnoreCase(dataLayerAddress_2));
1031                 Assert.assertTrue(host_jo.getString("nodeConnectorType").equalsIgnoreCase(nodeConnectorType_2));
1032                 Assert.assertTrue(host_jo.getInt("nodeConnectorId") == nodeConnectorId_2);
1033                 Assert.assertTrue(host_jo.getString("nodeType").equalsIgnoreCase(nodeType_2));
1034                 Assert.assertTrue(host_jo.getInt("nodeId") == nodeId_2);
1035                 Assert.assertTrue(host_jo.getString("vlan").equalsIgnoreCase(vlan_2));
1036                 Assert.assertTrue(host_jo.getBoolean("staticHost"));
1037             } else {
1038                 Assert.assertTrue(false);
1039             }
1040         }
1041
1042         // test GET method: getActiveHosts() - no host expected
1043         result = getJsonResult(baseURL + "/hosts/active", "GET");
1044         Assert.assertTrue(httpResponseCode == 200);
1045
1046         jt = new JSONTokener(result);
1047         json = new JSONObject(jt);
1048         Assert.assertFalse(hostInJson(json, networkAddress_1));
1049         Assert.assertFalse(hostInJson(json, networkAddress_2));
1050
1051         // put the 1st host into active host DB
1052         Node nd;
1053         NodeConnector ndc;
1054         try {
1055             nd = new Node(nodeType_1, nodeId_1);
1056             ndc = new NodeConnector(nodeConnectorType_1, nodeConnectorId_1, nd);
1057             this.invtoryListener.notifyNodeConnector(ndc, UpdateType.ADDED, null);
1058         } catch (ConstructionException e) {
1059             ndc = null;
1060             nd = null;
1061         }
1062
1063         // verify the host shows up in active host DB
1064
1065         result = getJsonResult(baseURL + "/hosts/active", "GET");
1066         Assert.assertTrue(httpResponseCode == 200);
1067
1068         jt = new JSONTokener(result);
1069         json = new JSONObject(jt);
1070
1071         Assert.assertTrue(hostInJson(json, networkAddress_1));
1072
1073         // test GET method for getHostDetails()
1074
1075         result = getJsonResult(baseURL + "/address/" + networkAddress_1, "GET");
1076         Assert.assertTrue(httpResponseCode == 200);
1077
1078         jt = new JSONTokener(result);
1079         json = new JSONObject(jt);
1080
1081         Assert.assertFalse(json.length() == 0);
1082
1083         Assert.assertTrue(json.getString("dataLayerAddress").equalsIgnoreCase(dataLayerAddress_1));
1084         Assert.assertTrue(json.getString("nodeConnectorType").equalsIgnoreCase(nodeConnectorType_1));
1085         Assert.assertTrue(json.getInt("nodeConnectorId") == nodeConnectorId_1);
1086         Assert.assertTrue(json.getString("nodeType").equalsIgnoreCase(nodeType_1));
1087         Assert.assertTrue(json.getInt("nodeId") == nodeId_1);
1088         Assert.assertTrue(json.getString("vlan").equals("0"));
1089         Assert.assertTrue(json.getBoolean("staticHost"));
1090
1091         // test DELETE method for deleteFlow()
1092
1093         result = getJsonResult(baseURL + "/address/" + networkAddress_1, "DELETE");
1094         Assert.assertTrue(httpResponseCode == 204);
1095
1096         // verify host_1 removed from active host DB
1097         // test GET method: getActiveHosts() - no host expected
1098
1099         result = getJsonResult(baseURL + "/hosts/active", "GET");
1100         Assert.assertTrue(httpResponseCode == 200);
1101
1102         jt = new JSONTokener(result);
1103         json = new JSONObject(jt);
1104
1105         Assert.assertFalse(hostInJson(json, networkAddress_1));
1106
1107     }
1108
1109     private Boolean hostInJson(JSONObject json, String hostIp) throws JSONException {
1110         // input JSONObject may be empty
1111         if (json.length() == 0) {
1112             return false;
1113         }
1114         if (json.get("hostConfig") instanceof JSONArray) {
1115             JSONArray ja = json.getJSONArray("hostConfig");
1116             for (int i = 0; i < ja.length(); i++) {
1117                 String na = ja.getJSONObject(i).getString("networkAddress");
1118                 if (na.equalsIgnoreCase(hostIp)) {
1119                     return true;
1120                 }
1121             }
1122             return false;
1123         } else {
1124             JSONObject ja = json.getJSONObject("hostConfig");
1125             String na = ja.getString("networkAddress");
1126             return (na.equalsIgnoreCase(hostIp)) ? true : false;
1127         }
1128     }
1129
1130     @Test
1131     public void testTopology() throws JSONException, ConstructionException {
1132         System.out.println("Starting Topology JAXB client.");
1133         String baseURL = "http://127.0.0.1:8080/controller/nb/v2/topology/default";
1134
1135         // === test GET method for getTopology()
1136         short state_1 = State.EDGE_UP, state_2 = State.EDGE_DOWN;
1137         long bw_1 = Bandwidth.BW10Gbps, bw_2 = Bandwidth.BW100Mbps;
1138         long lat_1 = Latency.LATENCY100ns, lat_2 = Latency.LATENCY1ms;
1139         String nodeType = "STUB";
1140         String nodeConnType = "STUB";
1141         int headNC1_nodeId = 1, headNC1_nodeConnId = 11;
1142         int tailNC1_nodeId = 2, tailNC1_nodeConnId = 22;
1143         int headNC2_nodeId = 2, headNC2_nodeConnId = 21;
1144         int tailNC2_nodeId = 1, tailNC2_nodeConnId = 12;
1145
1146         List<TopoEdgeUpdate> topoedgeupdateList = new ArrayList<TopoEdgeUpdate>();
1147         NodeConnector headnc1 = new NodeConnector(nodeConnType, headNC1_nodeConnId, new Node(nodeType, headNC1_nodeId));
1148         NodeConnector tailnc1 = new NodeConnector(nodeConnType, tailNC1_nodeConnId, new Node(nodeType, tailNC1_nodeId));
1149         Edge e1 = new Edge(tailnc1, headnc1);
1150         Set<Property> props_1 = new HashSet<Property>();
1151         props_1.add(new State(state_1));
1152         props_1.add(new Bandwidth(bw_1));
1153         props_1.add(new Latency(lat_1));
1154         TopoEdgeUpdate teu1 = new TopoEdgeUpdate(e1, props_1, UpdateType.ADDED);
1155         topoedgeupdateList.add(teu1);
1156
1157         NodeConnector headnc2 = new NodeConnector(nodeConnType, headNC2_nodeConnId, new Node(nodeType, headNC2_nodeId));
1158         NodeConnector tailnc2 = new NodeConnector(nodeConnType, tailNC2_nodeConnId, new Node(nodeType, tailNC2_nodeId));
1159         Edge e2 = new Edge(tailnc2, headnc2);
1160         Set<Property> props_2 = new HashSet<Property>();
1161         props_2.add(new State(state_2));
1162         props_2.add(new Bandwidth(bw_2));
1163         props_2.add(new Latency(lat_2));
1164
1165         TopoEdgeUpdate teu2 = new TopoEdgeUpdate(e2, props_2, UpdateType.ADDED);
1166         topoedgeupdateList.add(teu2);
1167
1168         topoUpdates.edgeUpdate(topoedgeupdateList);
1169
1170         // HTTP request
1171         String result = getJsonResult(baseURL, "GET");
1172         Assert.assertTrue(httpResponseCode == 200);
1173         if (debugMsg) {
1174             System.out.println("Get Topology: " + result);
1175         }
1176
1177         // returned data must be an array of edges
1178         JSONTokener jt = new JSONTokener(result);
1179         JSONObject json = new JSONObject(jt);
1180         Assert.assertTrue(json.get("edgeProperties") instanceof JSONArray);
1181         JSONArray ja = json.getJSONArray("edgeProperties");
1182
1183         for (int i = 0; i < ja.length(); i++) {
1184             JSONObject edgeProp = ja.getJSONObject(i);
1185             JSONObject edge = edgeProp.getJSONObject("edge");
1186             JSONObject tailNC = edge.getJSONObject("tailNodeConnector");
1187             JSONObject tailNode = tailNC.getJSONObject("node");
1188
1189             JSONObject headNC = edge.getJSONObject("headNodeConnector");
1190             JSONObject headNode = headNC.getJSONObject("node");
1191             JSONObject Props = edgeProp.getJSONObject("properties");
1192             JSONObject bandw = Props.getJSONObject("bandwidth");
1193             JSONObject stt = Props.getJSONObject("state");
1194             JSONObject ltc = Props.getJSONObject("latency");
1195
1196             if (headNC.getInt("id") == headNC1_nodeConnId) {
1197                 Assert.assertEquals(headNode.getString("type"), nodeType);
1198                 Assert.assertEquals(headNode.getLong("id"), headNC1_nodeId);
1199                 Assert.assertEquals(headNC.getString("type"), nodeConnType);
1200                 Assert.assertEquals(tailNode.getString("type"),nodeType);
1201                 Assert.assertEquals(tailNode.getString("type"), nodeConnType);
1202                 Assert.assertEquals(tailNC.getLong("id"), tailNC1_nodeConnId);
1203                 Assert.assertEquals(bandw.getLong("value"), bw_1);
1204                 Assert.assertTrue((short) stt.getInt("value") == state_1);
1205                 Assert.assertEquals(ltc.getLong("value"), lat_1);
1206             } else if (headNC.getInt("id") == headNC2_nodeConnId) {
1207                 Assert.assertEquals(headNode.getString("type"),nodeType);
1208                 Assert.assertEquals(headNode.getLong("id"), headNC2_nodeId);
1209                 Assert.assertEquals(headNC.getString("type"), nodeConnType);
1210                 Assert.assertEquals(tailNode.getString("type"), nodeType);
1211                 Assert.assertTrue(tailNode.getInt("id") == tailNC2_nodeId);
1212                 Assert.assertEquals(tailNC.getString("type"), nodeConnType);
1213                 Assert.assertEquals(tailNC.getLong("id"), tailNC2_nodeConnId);
1214                 Assert.assertEquals(bandw.getLong("value"), bw_2);
1215                 Assert.assertTrue((short) stt.getInt("value") == state_2);
1216                 Assert.assertEquals(ltc.getLong("value"), lat_2);
1217             }
1218         }
1219
1220         // === test POST method for addUserLink()
1221         // define 2 sample nodeConnectors for user link configuration tests
1222         String nodeType_1 = "STUB";
1223         Integer nodeId_1 = 3366;
1224         String nodeConnectorType_1 = "STUB";
1225         Integer nodeConnectorId_1 = 12;
1226         String nodeType_2 = "STUB";
1227         Integer nodeId_2 = 4477;
1228         String nodeConnectorType_2 = "STUB";
1229         Integer nodeConnectorId_2 = 34;
1230
1231         JSONObject jo = new JSONObject()
1232                 .put("name", "userLink_1")
1233                 .put("srcNodeConnector",
1234                         nodeConnectorType_1 + "|" + nodeConnectorId_1 + "@" + nodeType_1 + "|" + nodeId_1)
1235                 .put("dstNodeConnector",
1236                         nodeConnectorType_2 + "|" + nodeConnectorId_2 + "@" + nodeType_2 + "|" + nodeId_2);
1237         // execute HTTP request and verify response code
1238         result = getJsonResult(baseURL + "/userLink/userLink_1", "PUT", jo.toString());
1239         Assert.assertTrue(httpResponseCode == 201);
1240
1241         // === test GET method for getUserLinks()
1242         result = getJsonResult(baseURL + "/userLinks", "GET");
1243         Assert.assertTrue(httpResponseCode == 200);
1244         if (debugMsg) {
1245             System.out.println("result:" + result);
1246         }
1247
1248         jt = new JSONTokener(result);
1249         json = new JSONObject(jt);
1250
1251         // should have at least one object returned
1252         Assert.assertFalse(json.length() == 0);
1253         JSONObject userlink = new JSONObject();
1254
1255         if (json.get("userLinks") instanceof JSONArray) {
1256             ja = json.getJSONArray("userLinks");
1257             int i;
1258             for (i = 0; i < ja.length(); i++) {
1259                 userlink = ja.getJSONObject(i);
1260                 if (userlink.getString("name").equalsIgnoreCase("userLink_1")) {
1261                     break;
1262                 }
1263             }
1264             Assert.assertFalse(i == ja.length());
1265         } else {
1266             userlink = json.getJSONObject("userLinks");
1267             Assert.assertTrue(userlink.getString("name").equalsIgnoreCase("userLink_1"));
1268         }
1269
1270         String[] level_1, level_2;
1271         level_1 = userlink.getString("srcNodeConnector").split("\\@");
1272         level_2 = level_1[0].split("\\|");
1273         Assert.assertTrue(level_2[0].equalsIgnoreCase(nodeConnectorType_1));
1274         Assert.assertTrue(Integer.parseInt(level_2[1]) == nodeConnectorId_1);
1275         level_2 = level_1[1].split("\\|");
1276         Assert.assertTrue(level_2[0].equalsIgnoreCase(nodeType_1));
1277         Assert.assertTrue(Integer.parseInt(level_2[1]) == nodeId_1);
1278         level_1 = userlink.getString("dstNodeConnector").split("\\@");
1279         level_2 = level_1[0].split("\\|");
1280         Assert.assertTrue(level_2[0].equalsIgnoreCase(nodeConnectorType_2));
1281         Assert.assertTrue(Integer.parseInt(level_2[1]) == nodeConnectorId_2);
1282         level_2 = level_1[1].split("\\|");
1283         Assert.assertTrue(level_2[0].equalsIgnoreCase(nodeType_2));
1284         Assert.assertTrue(Integer.parseInt(level_2[1]) == nodeId_2);
1285
1286         // === test DELETE method for deleteUserLink()
1287         String userName = "userLink_1";
1288         result = getJsonResult(baseURL + "/userLink/" + userName, "DELETE");
1289         Assert.assertTrue(httpResponseCode == 204);
1290
1291         // execute another getUserLinks() request to verify that userLink_1 is
1292         // removed
1293         result = getJsonResult(baseURL + "/userLinks", "GET");
1294         Assert.assertTrue(httpResponseCode == 200);
1295         if (debugMsg) {
1296             System.out.println("result:" + result);
1297         }
1298         jt = new JSONTokener(result);
1299         json = new JSONObject(jt);
1300
1301         if (json.length() != 0) {
1302             if (json.get("userLinks") instanceof JSONArray) {
1303                 ja = json.getJSONArray("userLinks");
1304                 for (int i = 0; i < ja.length(); i++) {
1305                     userlink = ja.getJSONObject(i);
1306                     Assert.assertFalse(userlink.getString("name").equalsIgnoreCase("userLink_1"));
1307                 }
1308             } else {
1309                 userlink = json.getJSONObject("userLinks");
1310                 Assert.assertFalse(userlink.getString("name").equalsIgnoreCase("userLink_1"));
1311             }
1312         }
1313     }
1314     // Configure the OSGi container
1315     @Configuration
1316     public Option[] config() {
1317         return options(
1318                 //
1319                 systemProperty("logback.configurationFile").value(
1320                         "file:" + PathUtils.getBaseDir() + "/src/test/resources/logback.xml"),
1321                 // To start OSGi console for inspection remotely
1322                 systemProperty("osgi.console").value("2401"),
1323                 systemProperty("org.eclipse.gemini.web.tomcat.config.path").value(
1324                         PathUtils.getBaseDir() + "/src/test/resources/tomcat-server.xml"),
1325
1326                 // setting default level. Jersey bundles will need to be started
1327                 // earlier.
1328                 systemProperty("osgi.bundles.defaultStartLevel").value("4"),
1329
1330                 // Set the systemPackages (used by clustering)
1331                 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
1332                 mavenBundle("org.slf4j", "jcl-over-slf4j").versionAsInProject(),
1333                 mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
1334                 mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(),
1335                 mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(),
1336                 mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(),
1337                 mavenBundle("org.apache.commons", "commons-lang3").versionAsInProject(),
1338                 mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager").versionAsInProject(),
1339
1340                 // the plugin stub to get data for the tests
1341                 mavenBundle("org.opendaylight.controller", "protocol_plugins.stub").versionAsInProject(),
1342
1343                 // List all the opendaylight modules
1344                 mavenBundle("org.opendaylight.controller", "configuration").versionAsInProject(),
1345                 mavenBundle("org.opendaylight.controller", "configuration.implementation").versionAsInProject(),
1346                 mavenBundle("org.opendaylight.controller", "containermanager").versionAsInProject(),
1347                 mavenBundle("org.opendaylight.controller", "containermanager.it.implementation").versionAsInProject(),
1348                 mavenBundle("org.opendaylight.controller", "clustering.services").versionAsInProject(),
1349                 mavenBundle("org.opendaylight.controller", "clustering.services-implementation").versionAsInProject(),
1350                 mavenBundle("org.opendaylight.controller", "security").versionAsInProject().noStart(),
1351                 mavenBundle("org.opendaylight.controller", "sal").versionAsInProject(),
1352                 mavenBundle("org.opendaylight.controller", "sal.implementation").versionAsInProject(),
1353                 mavenBundle("org.opendaylight.controller", "sal.connection").versionAsInProject(),
1354                 mavenBundle("org.opendaylight.controller", "sal.connection.implementation").versionAsInProject(),
1355                 mavenBundle("org.opendaylight.controller", "switchmanager").versionAsInProject(),
1356                 mavenBundle("org.opendaylight.controller", "connectionmanager").versionAsInProject(),
1357                 mavenBundle("org.opendaylight.controller", "connectionmanager.implementation").versionAsInProject(),
1358                 mavenBundle("org.opendaylight.controller", "switchmanager.implementation").versionAsInProject(),
1359                 mavenBundle("org.opendaylight.controller", "forwardingrulesmanager").versionAsInProject(),
1360                 mavenBundle("org.opendaylight.controller",
1361                             "forwardingrulesmanager.implementation").versionAsInProject(),
1362                 mavenBundle("org.opendaylight.controller", "statisticsmanager").versionAsInProject(),
1363                 mavenBundle("org.opendaylight.controller", "statisticsmanager.implementation").versionAsInProject(),
1364                 mavenBundle("org.opendaylight.controller", "arphandler").versionAsInProject(),
1365                 mavenBundle("org.opendaylight.controller", "hosttracker").versionAsInProject(),
1366                 mavenBundle("org.opendaylight.controller", "hosttracker.implementation").versionAsInProject(),
1367                 mavenBundle("org.opendaylight.controller", "arphandler").versionAsInProject(),
1368                 mavenBundle("org.opendaylight.controller", "routing.dijkstra_implementation").versionAsInProject(),
1369                 mavenBundle("org.opendaylight.controller", "topologymanager").versionAsInProject(),
1370                 mavenBundle("org.opendaylight.controller", "usermanager").versionAsInProject(),
1371                 mavenBundle("org.opendaylight.controller", "usermanager.implementation").versionAsInProject(),
1372                 mavenBundle("org.opendaylight.controller", "logging.bridge").versionAsInProject(),
1373 //                mavenBundle("org.opendaylight.controller", "clustering.test").versionAsInProject(),
1374                 mavenBundle("org.opendaylight.controller", "forwarding.staticrouting").versionAsInProject(),
1375                 mavenBundle("org.opendaylight.controller", "bundlescanner").versionAsInProject(),
1376                 mavenBundle("org.opendaylight.controller", "bundlescanner.implementation").versionAsInProject(),
1377                 mavenBundle("org.opendaylight.controller", "commons.httpclient").versionAsInProject(),
1378
1379                 // Northbound bundles
1380                 mavenBundle("org.opendaylight.controller", "commons.northbound").versionAsInProject(),
1381                 mavenBundle("org.opendaylight.controller", "forwarding.staticrouting.northbound").versionAsInProject(),
1382                 mavenBundle("org.opendaylight.controller", "statistics.northbound").versionAsInProject(),
1383                 mavenBundle("org.opendaylight.controller", "topology.northbound").versionAsInProject(),
1384                 mavenBundle("org.opendaylight.controller", "hosttracker.northbound").versionAsInProject(),
1385                 mavenBundle("org.opendaylight.controller", "switchmanager.northbound").versionAsInProject(),
1386                 mavenBundle("org.opendaylight.controller", "flowprogrammer.northbound").versionAsInProject(),
1387                 mavenBundle("org.opendaylight.controller", "subnets.northbound").versionAsInProject(),
1388
1389                 mavenBundle("org.codehaus.jackson", "jackson-mapper-asl").versionAsInProject(),
1390                 mavenBundle("org.codehaus.jackson", "jackson-core-asl").versionAsInProject(),
1391                 mavenBundle("org.codehaus.jackson", "jackson-jaxrs").versionAsInProject(),
1392                 mavenBundle("org.codehaus.jackson", "jackson-xc").versionAsInProject(),
1393                 mavenBundle("org.codehaus.jettison", "jettison").versionAsInProject(),
1394
1395                 mavenBundle("commons-io", "commons-io").versionAsInProject(),
1396
1397                 mavenBundle("commons-fileupload", "commons-fileupload").versionAsInProject(),
1398
1399                 mavenBundle("equinoxSDK381", "javax.servlet").versionAsInProject(),
1400                 mavenBundle("equinoxSDK381", "javax.servlet.jsp").versionAsInProject(),
1401                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds").versionAsInProject(),
1402                 mavenBundle("orbit", "javax.xml.rpc").versionAsInProject(),
1403                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util").versionAsInProject(),
1404                 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services").versionAsInProject(),
1405                 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command").versionAsInProject(),
1406                 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime").versionAsInProject(),
1407                 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell").versionAsInProject(),
1408                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.cm").versionAsInProject(),
1409                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console").versionAsInProject(),
1410                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.launcher").versionAsInProject(),
1411
1412                 mavenBundle("geminiweb", "org.eclipse.gemini.web.core").versionAsInProject(),
1413                 mavenBundle("geminiweb", "org.eclipse.gemini.web.extender").versionAsInProject(),
1414                 mavenBundle("geminiweb", "org.eclipse.gemini.web.tomcat").versionAsInProject(),
1415                 mavenBundle("geminiweb", "org.eclipse.virgo.kernel.equinox.extensions").versionAsInProject().noStart(),
1416                 mavenBundle("geminiweb", "org.eclipse.virgo.util.common").versionAsInProject(),
1417                 mavenBundle("geminiweb", "org.eclipse.virgo.util.io").versionAsInProject(),
1418                 mavenBundle("geminiweb", "org.eclipse.virgo.util.math").versionAsInProject(),
1419                 mavenBundle("geminiweb", "org.eclipse.virgo.util.osgi").versionAsInProject(),
1420                 mavenBundle("geminiweb", "org.eclipse.virgo.util.osgi.manifest").versionAsInProject(),
1421                 mavenBundle("geminiweb", "org.eclipse.virgo.util.parser.manifest").versionAsInProject(),
1422
1423                 mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager").versionAsInProject(),
1424                 mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager.shell").versionAsInProject(),
1425
1426                 mavenBundle("com.google.code.gson", "gson").versionAsInProject(),
1427                 mavenBundle("org.jboss.spec.javax.transaction", "jboss-transaction-api_1.1_spec").versionAsInProject(),
1428                 mavenBundle("org.apache.felix", "org.apache.felix.fileinstall").versionAsInProject(),
1429                 mavenBundle("org.apache.commons", "commons-lang3").versionAsInProject(),
1430                 mavenBundle("commons-codec", "commons-codec").versionAsInProject(),
1431                 mavenBundle("virgomirror", "org.eclipse.jdt.core.compiler.batch").versionAsInProject(),
1432                 mavenBundle("eclipselink", "javax.persistence").versionAsInProject(),
1433                 mavenBundle("eclipselink", "javax.resource").versionAsInProject(),
1434
1435                 mavenBundle("orbit", "javax.activation").versionAsInProject(),
1436                 mavenBundle("orbit", "javax.annotation").versionAsInProject(),
1437                 mavenBundle("orbit", "javax.ejb").versionAsInProject(),
1438                 mavenBundle("orbit", "javax.el").versionAsInProject(),
1439                 mavenBundle("orbit", "javax.mail.glassfish").versionAsInProject(),
1440                 mavenBundle("orbit", "javax.xml.rpc").versionAsInProject(),
1441                 mavenBundle("orbit", "org.apache.catalina").versionAsInProject(),
1442                 // these are bundle fragments that can't be started on its own
1443                 mavenBundle("orbit", "org.apache.catalina.ha").versionAsInProject().noStart(),
1444                 mavenBundle("orbit", "org.apache.catalina.tribes").versionAsInProject().noStart(),
1445                 mavenBundle("orbit", "org.apache.coyote").versionAsInProject().noStart(),
1446                 mavenBundle("orbit", "org.apache.jasper").versionAsInProject().noStart(),
1447
1448                 mavenBundle("orbit", "org.apache.el").versionAsInProject(),
1449                 mavenBundle("orbit", "org.apache.juli.extras").versionAsInProject(),
1450                 mavenBundle("orbit", "org.apache.tomcat.api").versionAsInProject(),
1451                 mavenBundle("orbit", "org.apache.tomcat.util").versionAsInProject().noStart(),
1452                 mavenBundle("orbit", "javax.servlet.jsp.jstl").versionAsInProject(),
1453                 mavenBundle("orbit", "javax.servlet.jsp.jstl.impl").versionAsInProject(),
1454
1455                 mavenBundle("org.ops4j.pax.exam", "pax-exam-container-native").versionAsInProject(),
1456                 mavenBundle("org.ops4j.pax.exam", "pax-exam-junit4").versionAsInProject(),
1457                 mavenBundle("org.ops4j.pax.exam", "pax-exam-link-mvn").versionAsInProject(),
1458                 mavenBundle("org.ops4j.pax.url", "pax-url-aether").versionAsInProject(),
1459
1460                 mavenBundle("org.ow2.asm", "asm-all").versionAsInProject(),
1461
1462                 mavenBundle("org.springframework", "org.springframework.asm").versionAsInProject(),
1463                 mavenBundle("org.springframework", "org.springframework.aop").versionAsInProject(),
1464                 mavenBundle("org.springframework", "org.springframework.context").versionAsInProject(),
1465                 mavenBundle("org.springframework", "org.springframework.context.support").versionAsInProject(),
1466                 mavenBundle("org.springframework", "org.springframework.core").versionAsInProject(),
1467                 mavenBundle("org.springframework", "org.springframework.beans").versionAsInProject(),
1468                 mavenBundle("org.springframework", "org.springframework.expression").versionAsInProject(),
1469                 mavenBundle("org.springframework", "org.springframework.web").versionAsInProject(),
1470
1471                 mavenBundle("org.aopalliance", "com.springsource.org.aopalliance").versionAsInProject(),
1472                 mavenBundle("org.springframework", "org.springframework.web.servlet").versionAsInProject(),
1473                 mavenBundle("org.springframework.security", "spring-security-config").versionAsInProject(),
1474                 mavenBundle("org.springframework.security", "spring-security-core").versionAsInProject(),
1475                 mavenBundle("org.springframework.security", "spring-security-web").versionAsInProject(),
1476                 mavenBundle("org.springframework.security", "spring-security-taglibs").versionAsInProject(),
1477                 mavenBundle("org.springframework", "org.springframework.transaction").versionAsInProject(),
1478
1479                 mavenBundle("org.ow2.chameleon.management", "chameleon-mbeans").versionAsInProject(),
1480                 mavenBundle("org.opendaylight.controller.thirdparty", "net.sf.jung2").versionAsInProject(),
1481                 mavenBundle("org.opendaylight.controller.thirdparty", "com.sun.jersey.jersey-servlet")
1482                 .versionAsInProject(),
1483                 mavenBundle("org.opendaylight.controller.thirdparty", "org.apache.catalina.filters.CorsFilter")
1484                 .versionAsInProject().noStart(),
1485
1486                 // Jersey needs to be started before the northbound application
1487                 // bundles, using a lower start level
1488                 mavenBundle("com.sun.jersey", "jersey-client").versionAsInProject(),
1489                 mavenBundle("com.sun.jersey", "jersey-server").versionAsInProject().startLevel(2),
1490                 mavenBundle("com.sun.jersey", "jersey-core").versionAsInProject().startLevel(2),
1491                 mavenBundle("com.sun.jersey", "jersey-json").versionAsInProject().startLevel(2), junitBundles());
1492     }
1493
1494 }