X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnorthbound%2Fintegrationtest%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnorthbound%2Fintegrationtest%2FNorthboundIT.java;h=6829fadff566b452e0ec92f96d79cd92d905b45f;hp=27a50c015dfce73040afd8453f54bb02b26139d9;hb=0408539088240d4899667c83c8c192d2299d66da;hpb=74c92401812b8e77e8ceade6e8714d0fc1c35d3a diff --git a/opendaylight/northbound/integrationtest/src/test/java/org/opendaylight/controller/northbound/integrationtest/NorthboundIT.java b/opendaylight/northbound/integrationtest/src/test/java/org/opendaylight/controller/northbound/integrationtest/NorthboundIT.java index 27a50c015d..6829fadff5 100644 --- a/opendaylight/northbound/integrationtest/src/test/java/org/opendaylight/controller/northbound/integrationtest/NorthboundIT.java +++ b/opendaylight/northbound/integrationtest/src/test/java/org/opendaylight/controller/northbound/integrationtest/NorthboundIT.java @@ -8,17 +8,12 @@ import static org.ops4j.pax.exam.CoreOptions.options; import static org.ops4j.pax.exam.CoreOptions.systemPackages; import static org.ops4j.pax.exam.CoreOptions.systemProperty; -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import javax.inject.Inject; @@ -32,6 +27,9 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.opendaylight.controller.commons.httpclient.HTTPClient; +import org.opendaylight.controller.commons.httpclient.HTTPRequest; +import org.opendaylight.controller.commons.httpclient.HTTPResponse; import org.opendaylight.controller.hosttracker.IfIptoHost; import org.opendaylight.controller.sal.core.Bandwidth; import org.opendaylight.controller.sal.core.ConstructionException; @@ -47,7 +45,7 @@ import org.opendaylight.controller.sal.topology.TopoEdgeUpdate; import org.opendaylight.controller.switchmanager.IInventoryListener; import org.opendaylight.controller.usermanager.IUserManager; import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.Configuration; +import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.util.PathUtils; import org.osgi.framework.Bundle; @@ -88,10 +86,10 @@ public class NorthboundIT { assertNotNull(bc); boolean debugit = false; Bundle b[] = bc.getBundles(); - for (int i = 0; i < b.length; i++) { - int state = b[i].getState(); + for (Bundle element : b) { + int state = element.getState(); if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) { - log.debug("Bundle:" + b[i].getSymbolicName() + " state:" + stateToString(state)); + log.debug("Bundle:" + element.getSymbolicName() + " state:" + stateToString(state)); debugit = true; } } @@ -143,57 +141,58 @@ public class NorthboundIT { if (debugMsg) { System.out.println("HTTP method: " + method + " url: " + restUrl.toString()); - if (body != null) + if (body != null) { System.out.println("body: " + body); + } } try { - URL url = new URL(restUrl); this.userManager.getAuthorizationList(); this.userManager.authenticate("admin", "admin"); + HTTPRequest request = new HTTPRequest(); + + request.setUri(restUrl); + request.setMethod(method); + request.setTimeout(0); // HostTracker doesn't respond + // within default timeout during + // IT so setting an indefinite + // timeout till the issue is + // sorted out + + Map> headers = new HashMap>(); String authString = "admin:admin"; byte[] authEncBytes = Base64.encodeBase64(authString.getBytes()); String authStringEnc = new String(authEncBytes); - - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod(method); - connection.setRequestProperty("Authorization", "Basic " + authStringEnc); - connection.setRequestProperty("Content-Type", "application/json"); - connection.setRequestProperty("Accept", "application/json"); - + List header = new ArrayList(); + header.add("Basic "+authStringEnc); + headers.put("Authorization", header); + header = new ArrayList(); + header.add("application/json"); + headers.put("Accept", header); + request.setHeaders(headers); + request.setContentType("application/json"); if (body != null) { - connection.setDoOutput(true); - OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream()); - wr.write(body); - wr.flush(); + request.setEntity(body); } - connection.connect(); - connection.getContentType(); + + HTTPResponse response = HTTPClient.sendRequest(request); // Response code for success should be 2xx - httpResponseCode = connection.getResponseCode(); - if (httpResponseCode > 299) + httpResponseCode = response.getStatus(); + if (httpResponseCode > 299) { return httpResponseCode.toString(); + } if (debugMsg) { - System.out.println("HTTP response code: " + connection.getResponseCode()); - System.out.println("HTTP response message: " + connection.getResponseMessage()); + System.out.println("HTTP response code: " + response.getStatus()); + System.out.println("HTTP response message: " + response.getEntity()); } - InputStream is = connection.getInputStream(); - BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); - StringBuilder sb = new StringBuilder(); - int cp; - while ((cp = rd.read()) != -1) { - sb.append((char) cp); - } - is.close(); - connection.disconnect(); + return response.getEntity(); + } catch (Exception e) { if (debugMsg) { - System.out.println("Response : "+sb.toString()); + e.printStackTrace(); } - return sb.toString(); - } catch (Exception e) { return null; } } @@ -206,47 +205,34 @@ public class NorthboundIT { Assert.assertEquals(nodeId, (Integer) nodeInfo.getInt("id")); Assert.assertEquals(nodeType, nodeInfo.getString("type")); - JSONArray propsArray = node.getJSONArray("properties"); - - for (int j = 0; j < propsArray.length(); j++) { - JSONObject properties = propsArray.getJSONObject(j); - String propName = properties.getString("name"); - if (propName.equals("timeStamp")) { - if (timestamp == null || timestampName == null) { - Assert.assertFalse("Timestamp exist", true); - } else { - Assert.assertEquals(timestamp, (Integer) properties.getInt("value")); - Assert.assertEquals(timestampName, properties.getString("timestampName")); - } - } - if (propName.equals("actions")) { - if (actionsValue == null) { - Assert.assertFalse("Actions exist", true); - } else { - Assert.assertEquals(actionsValue, (Integer) properties.getInt("value")); - } - } - if (propName.equals("capabilities")) { - if (capabilitiesValue == null) { - Assert.assertFalse("Capabilities exist", true); - } else { - Assert.assertEquals(capabilitiesValue, (Integer) properties.getInt("value")); - } - } - if (propName.equals("tables")) { - if (tablesValue == null) { - Assert.assertFalse("Tables exist", true); - } else { - Assert.assertEquals(tablesValue, (Integer) properties.getInt("value")); - } - } - if (propName.equals("buffers")) { - if (buffersValue == null) { - Assert.assertFalse("Buffers exist", true); - } else { - Assert.assertEquals(buffersValue, (Integer) properties.getInt("value")); - } - } + JSONObject properties = node.getJSONObject("properties"); + + if (timestamp == null || timestampName == null) { + Assert.assertFalse(properties.has("timeStamp")); + } else { + Assert.assertEquals(timestamp, (Integer) properties.getJSONObject("timeStamp").getInt("value")); + Assert.assertEquals(timestampName, properties.getJSONObject("timeStamp").getString("name")); + } + if (actionsValue == null) { + Assert.assertFalse(properties.has("actions")); + } else { + Assert.assertEquals(actionsValue, (Integer) properties.getJSONObject("actions").getInt("value")); + } + if (capabilitiesValue == null) { + Assert.assertFalse(properties.has("capabilities")); + } else { + Assert.assertEquals(capabilitiesValue, + (Integer) properties.getJSONObject("capabilities").getInt("value")); + } + if (tablesValue == null) { + Assert.assertFalse(properties.has("tables")); + } else { + Assert.assertEquals(tablesValue, (Integer) properties.getJSONObject("tables").getInt("value")); + } + if (buffersValue == null) { + Assert.assertFalse(properties.has("buffers")); + } else { + Assert.assertEquals(buffersValue, (Integer) properties.getJSONObject("buffers").getInt("value")); } } @@ -256,64 +242,71 @@ public class NorthboundIT { JSONObject nodeConnector = nodeConnectorProperties.getJSONObject("nodeconnector"); JSONObject node = nodeConnector.getJSONObject("node"); + JSONObject properties = nodeConnectorProperties.getJSONObject("properties"); Assert.assertEquals(ncId, (Integer) nodeConnector.getInt("id")); Assert.assertEquals(ncType, nodeConnector.getString("type")); Assert.assertEquals(nodeId, (Integer) node.getInt("id")); Assert.assertEquals(nodeType, node.getString("type")); - - JSONArray propsArray = nodeConnectorProperties.getJSONArray("properties"); - for (int j = 0; j < propsArray.length(); j++) { - JSONObject properties = propsArray.getJSONObject(j); - String propName = properties.getString("name"); - if (propName.equals("state")) { - if (state == null) { - Assert.assertFalse("State exist", true); - } else { - Assert.assertEquals(state, (Integer) properties.getInt("value")); - } - } - if (propName.equals("capabilities")) { - if (capabilities == null) { - Assert.assertFalse("Capabilities exist", true); - } else { - Assert.assertEquals(capabilities, (Integer) properties.getInt("value")); - } - } - if (propName.equals("bandwidth")) { - if (bandwidth == null) { - Assert.assertFalse("bandwidth exist", true); - } else { - Assert.assertEquals(bandwidth, (Integer) properties.getInt("value")); - } - } + if (state == null) { + Assert.assertFalse(properties.has("state")); + } else { + Assert.assertEquals(state, (Integer) properties.getJSONObject("state").getInt("value")); + } + if (capabilities == null) { + Assert.assertFalse(properties.has("capabilities")); + } else { + Assert.assertEquals(capabilities, + (Integer) properties.getJSONObject("capabilities").getInt("value")); + } + if (bandwidth == null) { + Assert.assertFalse(properties.has("bandwidth")); + } else { + Assert.assertEquals(bandwidth, (Integer) properties.getJSONObject("bandwidth").getInt("value")); } } @Test - public void testSubnetsNorthbound() throws JSONException { + public void testSubnetsNorthbound() throws JSONException, ConstructionException { System.out.println("Starting Subnets JAXB client."); - String baseURL = "http://127.0.0.1:8080/controller/nb/v2/subnet/"; + String baseURL = "http://127.0.0.1:8080/controller/nb/v2/subnetservice/"; String name1 = "testSubnet1"; String subnet1 = "1.1.1.1/24"; String name2 = "testSubnet2"; String subnet2 = "2.2.2.2/24"; - String[] nodePorts2 = {"2/1", "2/2", "2/3", "2/4"}; - StringBuilder nodePortsJson2 = new StringBuilder(); - nodePortsJson2.append(nodePorts2[0] + "," + nodePorts2[1] + "," + nodePorts2[2] + "," + nodePorts2[3]); String name3 = "testSubnet3"; String subnet3 = "3.3.3.3/24"; - String[] nodePorts3 = {"3/1", "3/2", "3/3"}; - StringBuilder nodePortsJson3 = new StringBuilder(); - nodePortsJson3.append(nodePorts3[0] + "," + nodePorts3[1] + "," + nodePorts3[2]); - StringBuilder nodePortsJson3_1 = new StringBuilder(); - nodePortsJson3_1.append(nodePortsJson3).append(",").append(nodePortsJson2); + + /* + * Create the node connector string list for the two subnets as: + * 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"}; + * 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"}; + */ + Node node2 = new Node(Node.NodeIDType.OPENFLOW, 2L); + List portList2 = new ArrayList(); + NodeConnector nc21 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)1, node2); + NodeConnector nc22 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)2, node2); + NodeConnector nc23 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)3, node2); + NodeConnector nc24 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)3, node2); + portList2.add(nc21.toString()); + portList2.add(nc22.toString()); + portList2.add(nc23.toString()); + portList2.add(nc24.toString()); + + List portList3 = new ArrayList(); + Node node3 = new Node(Node.NodeIDType.OPENFLOW, 3L); + NodeConnector nc31 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)1, node3); + NodeConnector nc32 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)2, node3); + NodeConnector nc33 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)3, node3); + portList3.add(nc31.toString()); + portList3.add(nc32.toString()); + portList3.add(nc33.toString()); // Test GET subnets in default container - String result = getJsonResult(baseURL + "default/subnet/all"); + String result = getJsonResult(baseURL + "default/subnets"); JSONTokener jt = new JSONTokener(result); JSONObject json = new JSONObject(jt); JSONArray subnetConfigs = json.getJSONArray("subnetConfig"); @@ -326,7 +319,7 @@ public class NorthboundIT { // Test POST subnet1 JSONObject jo = new JSONObject().put("name", name1).put("subnet", subnet1); // execute HTTP request and verify response code - result = getJsonResult(baseURL + "default/subnet/" + name1, "POST", jo.toString()); + result = getJsonResult(baseURL + "default/subnet/" + name1, "PUT", jo.toString()); Assert.assertTrue(httpResponseCode == 201); // Test GET subnet1 @@ -337,34 +330,24 @@ public class NorthboundIT { Assert.assertEquals(name1, json.getString("name")); Assert.assertEquals(subnet1, json.getString("subnet")); - // Test POST subnet2 - JSONObject jo2 = new JSONObject().put("name", name2).put("subnet", subnet2); + // Test PUT subnet2 + JSONObject jo2 = new JSONObject().put("name", name2).put("subnet", subnet2).put("nodeConnectors", portList2); // execute HTTP request and verify response code - result = getJsonResult(baseURL + "default/subnet/" + name2, "POST", jo2.toString()); + result = getJsonResult(baseURL + "default/subnet/" + name2, "PUT", jo2.toString()); Assert.assertEquals(201, httpResponseCode.intValue()); - // Test POST nodePorts - jo2.append("nodePorts", nodePortsJson2); - // execute HTTP request and verify response code - result = getJsonResult(baseURL + "default/subnet/" + name2 + "/node-ports", "POST", jo2.toString()); - Assert.assertEquals(200, httpResponseCode.intValue()); - // Test POST subnet3 + // Test PUT subnet3 JSONObject jo3 = new JSONObject().put("name", name3).put("subnet", subnet3); // execute HTTP request and verify response code - result = getJsonResult(baseURL + "default/subnet/" + name3, "POST", jo3.toString()); + result = getJsonResult(baseURL + "default/subnet/" + name3, "PUT", jo3.toString()); Assert.assertEquals(201, httpResponseCode.intValue()); - // Test POST nodePorts - jo3.append("nodePorts", nodePortsJson3); + // Test POST subnet3 (modify port list: add) + JSONObject jo3New = new JSONObject().put("name", name3).put("subnet", subnet3).put("nodeConnectors", portList3); // execute HTTP request and verify response code - result = getJsonResult(baseURL + "default/subnet/" + name3 + "/node-ports", "POST", jo3.toString()); - Assert.assertEquals(200, httpResponseCode.intValue()); - // Test PUT nodePorts - jo3.remove("nodePorts"); - jo3.append("nodePorts", nodePortsJson3_1); - result = getJsonResult(baseURL + "default/subnet/" + name3 + "/node-ports", "PUT", jo3.toString()); + result = getJsonResult(baseURL + "default/subnet/" + name3, "POST", jo3New.toString()); Assert.assertEquals(200, httpResponseCode.intValue()); // Test GET all subnets in default container - result = getJsonResult(baseURL + "default/subnet/all"); + result = getJsonResult(baseURL + "default/subnets"); jt = new JSONTokener(result); json = new JSONObject(jt); JSONArray subnetConfigArray = json.getJSONArray("subnetConfig"); @@ -376,27 +359,42 @@ public class NorthboundIT { Assert.assertEquals(subnet1, subnetConfig.getString("subnet")); } else if (subnetConfig.getString("name").equals(name2)) { Assert.assertEquals(subnet2, subnetConfig.getString("subnet")); - String[] nodePortsGet2 = subnetConfig.getJSONArray("nodePorts").getString(0).split(","); - Assert.assertEquals(nodePorts2[0], nodePortsGet2[0]); - Assert.assertEquals(nodePorts2[1], nodePortsGet2[1]); - Assert.assertEquals(nodePorts2[2], nodePortsGet2[2]); - Assert.assertEquals(nodePorts2[3], nodePortsGet2[3]); + JSONArray portListGet = subnetConfig.getJSONArray("nodeConnectors"); + Assert.assertEquals(portList2.get(0), portListGet.get(0)); + Assert.assertEquals(portList2.get(1), portListGet.get(1)); + Assert.assertEquals(portList2.get(2), portListGet.get(2)); + Assert.assertEquals(portList2.get(3), portListGet.get(3)); } else if (subnetConfig.getString("name").equals(name3)) { Assert.assertEquals(subnet3, subnetConfig.getString("subnet")); - String[] nodePortsGet = subnetConfig.getJSONArray("nodePorts").getString(0).split(","); - Assert.assertEquals(nodePorts3[0], nodePortsGet[0]); - Assert.assertEquals(nodePorts3[1], nodePortsGet[1]); - Assert.assertEquals(nodePorts3[2], nodePortsGet[2]); - Assert.assertEquals(nodePorts2[0], nodePortsGet[3]); - Assert.assertEquals(nodePorts2[1], nodePortsGet[4]); - Assert.assertEquals(nodePorts2[2], nodePortsGet[5]); - Assert.assertEquals(nodePorts2[3], nodePortsGet[6]); + JSONArray portListGet = subnetConfig.getJSONArray("nodeConnectors"); + Assert.assertEquals(portList3.get(0), portListGet.get(0)); + Assert.assertEquals(portList3.get(1), portListGet.get(1)); + Assert.assertEquals(portList3.get(2), portListGet.get(2)); } else { // Unexpected config name Assert.assertTrue(false); } } + // Test POST subnet2 (modify port list: remove one port only) + List newPortList2 = new ArrayList(portList2); + newPortList2.remove(3); + JSONObject jo2New = new JSONObject().put("name", name2).put("subnet", subnet2).put("nodeConnectors", newPortList2); + // execute HTTP request and verify response code + result = getJsonResult(baseURL + "default/subnet/" + name2, "POST", jo2New.toString()); + Assert.assertEquals(200, httpResponseCode.intValue()); + + // Test GET subnet2: verify contains only the first three ports + result = getJsonResult(baseURL + "default/subnet/" + name2); + jt = new JSONTokener(result); + subnetConfig = new JSONObject(jt); + Assert.assertEquals(200, httpResponseCode.intValue()); + JSONArray portListGet2 = subnetConfig.getJSONArray("nodeConnectors"); + Assert.assertEquals(portList2.get(0), portListGet2.get(0)); + Assert.assertEquals(portList2.get(1), portListGet2.get(1)); + Assert.assertEquals(portList2.get(2), portListGet2.get(2)); + Assert.assertTrue(portListGet2.length() == 3); + // Test DELETE subnet1 result = getJsonResult(baseURL + "default/subnet/" + name1, "DELETE"); Assert.assertEquals(204, httpResponseCode.intValue()); @@ -404,6 +402,11 @@ public class NorthboundIT { // Test GET deleted subnet1 result = getJsonResult(baseURL + "default/subnet/" + name1); Assert.assertEquals(404, httpResponseCode.intValue()); + + // TEST PUT bad subnet, expect 400, validate JSON exception mapper + JSONObject joBad = new JSONObject().put("foo", "bar"); + result = getJsonResult(baseURL + "default/subnet/foo", "PUT", joBad.toString()); + Assert.assertEquals(400, httpResponseCode.intValue()); } @Test @@ -419,7 +422,7 @@ public class NorthboundIT { String nextHop2 = "1.1.1.1"; // Test GET static routes in default container, expecting no results - String result = getJsonResult(baseURL + "default"); + String result = getJsonResult(baseURL + "default/routes"); JSONTokener jt = new JSONTokener(result); JSONObject json = new JSONObject(jt); JSONArray staticRoutes = json.getJSONArray("staticRoute"); @@ -428,15 +431,15 @@ public class NorthboundIT { // Test insert static route String requestBody = "{\"name\":\"" + name1 + "\", \"prefix\":\"" + prefix1 + "\", \"nextHop\":\"" + nextHop1 + "\"}"; - result = getJsonResult(baseURL + "default/route/" + name1, "POST", requestBody); + result = getJsonResult(baseURL + "default/route/" + name1, "PUT", requestBody); Assert.assertEquals(201, httpResponseCode.intValue()); requestBody = "{\"name\":\"" + name2 + "\", \"prefix\":\"" + prefix2 + "\", \"nextHop\":\"" + nextHop2 + "\"}"; - result = getJsonResult(baseURL + "default/route/" + name2, "POST", requestBody); + result = getJsonResult(baseURL + "default/route/" + name2, "PUT", requestBody); Assert.assertEquals(201, httpResponseCode.intValue()); // Test Get all static routes - result = getJsonResult(baseURL + "default"); + result = getJsonResult(baseURL + "default/routes"); jt = new JSONTokener(result); json = new JSONObject(jt); JSONArray staticRouteArray = json.getJSONArray("staticRoute"); @@ -475,9 +478,9 @@ public class NorthboundIT { // Test delete static route result = getJsonResult(baseURL + "default/route/" + name1, "DELETE"); - Assert.assertEquals(200, httpResponseCode.intValue()); + Assert.assertEquals(204, httpResponseCode.intValue()); - result = getJsonResult(baseURL + "default"); + result = getJsonResult(baseURL + "default/routes"); jt = new JSONTokener(result); json = new JSONObject(jt); @@ -490,7 +493,7 @@ public class NorthboundIT { @Test public void testSwitchManager() throws JSONException { System.out.println("Starting SwitchManager JAXB client."); - String baseURL = "http://127.0.0.1:8080/controller/nb/v2/switch/default/"; + String baseURL = "http://127.0.0.1:8080/controller/nb/v2/switchmanager/default/"; // define Node/NodeConnector attributes for test int nodeId_1 = 51966; @@ -581,25 +584,14 @@ public class NorthboundIT { json = new JSONObject(jt); node = getJsonInstance(json, "nodeProperties", nodeId_1); Assert.assertNotNull(node); - - JSONArray propsArray = node.getJSONArray("properties"); - - for (int j = 0; j < propsArray.length(); j++) { - JSONObject properties = propsArray.getJSONObject(j); - String propName = properties.getString("name"); - if (propName.equals("tier")) { - Assert.assertEquals(1001, properties.getInt("value")); - } - if (propName.equals("description")) { - Assert.assertEquals("node1", properties.getString("value")); - } - } + Assert.assertEquals(1001, node.getJSONObject("properties").getJSONObject("tier").getInt("value")); + Assert.assertEquals("node1", node.getJSONObject("properties").getJSONObject("description").getString("value")); // Test delete nodeConnector property // Delete state property of nodeconnector1 result = getJsonResult(baseURL + "nodeconnector/STUB/" + nodeId_1 + "/STUB/" + nodeConnectorId_1 + "/property/state", "DELETE"); - Assert.assertEquals(200, httpResponseCode.intValue()); + Assert.assertEquals(204, httpResponseCode.intValue()); result = getJsonResult(baseURL + "node/STUB/" + nodeId_1); jt = new JSONTokener(result); @@ -613,7 +605,7 @@ public class NorthboundIT { // Delete capabilities property of nodeconnector2 result = getJsonResult(baseURL + "nodeconnector/STUB/" + nodeId_2 + "/STUB/" + nodeConnectorId_2 + "/property/capabilities", "DELETE"); - Assert.assertEquals(200, httpResponseCode.intValue()); + Assert.assertEquals(204, httpResponseCode.intValue()); result = getJsonResult(baseURL + "node/STUB/" + nodeId_2); jt = new JSONTokener(result); @@ -797,19 +789,25 @@ public class NorthboundIT { dstBytes[4] = Byte.parseByte(dst.substring(8, 10)); Assert.assertTrue(Arrays.equals(dstBytes, dstMatch)); } - if (act.getString("type").equals("SET_DL_TYPE")) + if (act.getString("type").equals("SET_DL_TYPE")) { Assert.assertTrue(act.getInt("dlType") == 10); - if (act.getString("type").equals("SET_VLAN_ID")) + } + if (act.getString("type").equals("SET_VLAN_ID")) { Assert.assertTrue(act.getInt("vlanId") == 2); - if (act.getString("type").equals("SET_VLAN_PCP")) + } + if (act.getString("type").equals("SET_VLAN_PCP")) { Assert.assertTrue(act.getInt("pcp") == 3); - if (act.getString("type").equals("SET_VLAN_CFI")) + } + if (act.getString("type").equals("SET_VLAN_CFI")) { Assert.assertTrue(act.getInt("cfi") == 1); + } - if (act.getString("type").equals("SET_NW_SRC")) + if (act.getString("type").equals("SET_NW_SRC")) { Assert.assertTrue(act.getString("address").equals("2.2.2.2")); - if (act.getString("type").equals("SET_NW_DST")) + } + if (act.getString("type").equals("SET_NW_DST")) { Assert.assertTrue(act.getString("address").equals("1.1.1.1")); + } if (act.getString("type").equals("PUSH_VLAN")) { int head = act.getInt("VlanHeader"); @@ -823,30 +821,33 @@ public class NorthboundIT { Assert.assertTrue(pcp == 1); Assert.assertTrue(tag == 0x8100); } - if (act.getString("type").equals("SET_NW_TOS")) + if (act.getString("type").equals("SET_NW_TOS")) { Assert.assertTrue(act.getInt("tos") == 16); - if (act.getString("type").equals("SET_TP_SRC")) + } + if (act.getString("type").equals("SET_TP_SRC")) { Assert.assertTrue(act.getInt("port") == 4201); - if (act.getString("type").equals("SET_TP_DST")) + } + if (act.getString("type").equals("SET_TP_DST")) { Assert.assertTrue(act.getInt("port") == 8080); + } } @Test public void testFlowProgrammer() throws JSONException { System.out.println("Starting FlowProgrammer JAXB client."); - String baseURL = "http://127.0.0.1:8080/controller/nb/v2/flow/default/"; + String baseURL = "http://127.0.0.1:8080/controller/nb/v2/flowprogrammer/default/"; // Attempt to get a flow that doesn't exit. Should return 404 // status. - String result = getJsonResult(baseURL + "node/STUB/51966/static-flow/test1", "GET"); + String result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test1", "GET"); Assert.assertTrue(result.equals("404")); // test add flow1 String fc = "{\"name\":\"test1\", \"node\":{\"id\":\"51966\",\"type\":\"STUB\"}, \"actions\":[\"DROP\"]}"; - result = getJsonResult(baseURL + "node/STUB/51966/static-flow/test1", "PUT", fc); + result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test1", "PUT", fc); Assert.assertTrue(httpResponseCode == 201); // test get returns flow that was added. - result = getJsonResult(baseURL + "node/STUB/51966/static-flow/test1", "GET"); + result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test1", "GET"); // check that result came out fine. Assert.assertTrue(httpResponseCode == 200); JSONTokener jt = new JSONTokener(result); @@ -860,17 +861,17 @@ public class NorthboundIT { Assert.assertEquals(node.getString("id"), "51966"); // test adding same flow again fails due to repeat name..return 409 // code - result = getJsonResult(baseURL + "node/STUB/51966/static-flow/test1", "PUT", fc); + result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test1", "PUT", fc); Assert.assertTrue(result.equals("409")); fc = "{\"name\":\"test2\", \"node\":{\"id\":\"51966\",\"type\":\"STUB\"}, \"actions\":[\"DROP\"]}"; - result = getJsonResult(baseURL + "node/STUB/51966/static-flow/test2", "PUT", fc); + result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test2", "PUT", fc); // test should return 409 for error due to same flow being added. Assert.assertTrue(result.equals("409")); // add second flow that's different fc = "{\"name\":\"test2\", \"nwSrc\":\"1.1.1.1\", \"node\":{\"id\":\"51966\",\"type\":\"STUB\"}, \"actions\":[\"DROP\"]}"; - result = getJsonResult(baseURL + "node/STUB/51966/static-flow/test2", "PUT", fc); + result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test2", "PUT", fc); Assert.assertTrue(httpResponseCode == 201); // check that request returns both flows given node. @@ -892,10 +893,10 @@ public class NorthboundIT { Assert.assertTrue(count == 2); // delete a flow, check that it's no longer in list. - result = getJsonResult(baseURL + "node/STUB/51966/static-flow/test2", "DELETE"); - Assert.assertTrue(httpResponseCode == 200); + result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test2", "DELETE"); + Assert.assertTrue(httpResponseCode == 204); - result = getJsonResult(baseURL + "node/STUB/51966/static-flow/test2", "GET"); + result = getJsonResult(baseURL + "node/STUB/51966/staticFlow/test2", "GET"); Assert.assertTrue(result.equals("404")); } @@ -911,14 +912,16 @@ public class NorthboundIT { for (int i = 0; i < json_array.length(); i++) { result = json_array.getJSONObject(i); Integer nid = result.getJSONObject("node").getInt("id"); - if (nid.equals(nodeId)) + if (nid.equals(nodeId)) { break; + } } } else { result = json.getJSONObject(array_name); Integer nid = result.getJSONObject("node").getInt("id"); - if (!nid.equals(nodeId)) + if (!nid.equals(nodeId)) { result = null; + } } return result; } @@ -970,7 +973,7 @@ public class NorthboundIT { Integer nodeConnectorId_2 = 34; String vlan_2 = "123"; - String baseURL = "http://127.0.0.1:8080/controller/nb/v2/host/default"; + String baseURL = "http://127.0.0.1:8080/controller/nb/v2/hosttracker/default"; // test PUT method: addHost() JSONObject fc_json = new JSONObject(); @@ -983,7 +986,7 @@ public class NorthboundIT { fc_json.put("staticHost", "true"); fc_json.put("networkAddress", networkAddress_1); - String result = getJsonResult(baseURL + "/" + networkAddress_1, "PUT", fc_json.toString()); + String result = getJsonResult(baseURL + "/address/" + networkAddress_1, "PUT", fc_json.toString()); Assert.assertTrue(httpResponseCode == 201); fc_json = new JSONObject(); @@ -996,16 +999,16 @@ public class NorthboundIT { fc_json.put("staticHost", "true"); fc_json.put("networkAddress", networkAddress_2); - result = getJsonResult(baseURL + "/" + networkAddress_2 , "PUT", fc_json.toString()); + result = getJsonResult(baseURL + "/address/" + networkAddress_2 , "PUT", fc_json.toString()); Assert.assertTrue(httpResponseCode == 201); // define variables for decoding returned strings String networkAddress; - JSONObject host_jo, dl_jo, nc_jo, node_jo; + JSONObject host_jo; // the two hosts should be in inactive host DB // test GET method: getInactiveHosts() - result = getJsonResult(baseURL + "/inactive", "GET"); + result = getJsonResult(baseURL + "/hosts/inactive", "GET"); Assert.assertTrue(httpResponseCode == 200); JSONTokener jt = new JSONTokener(result); @@ -1041,7 +1044,7 @@ public class NorthboundIT { } // test GET method: getActiveHosts() - no host expected - result = getJsonResult(baseURL, "GET"); + result = getJsonResult(baseURL + "/hosts/active", "GET"); Assert.assertTrue(httpResponseCode == 200); jt = new JSONTokener(result); @@ -1063,7 +1066,7 @@ public class NorthboundIT { // verify the host shows up in active host DB - result = getJsonResult(baseURL, "GET"); + result = getJsonResult(baseURL + "/hosts/active", "GET"); Assert.assertTrue(httpResponseCode == 200); jt = new JSONTokener(result); @@ -1073,7 +1076,7 @@ public class NorthboundIT { // test GET method for getHostDetails() - result = getJsonResult(baseURL + "/" + networkAddress_1, "GET"); + result = getJsonResult(baseURL + "/address/" + networkAddress_1, "GET"); Assert.assertTrue(httpResponseCode == 200); jt = new JSONTokener(result); @@ -1091,13 +1094,13 @@ public class NorthboundIT { // test DELETE method for deleteFlow() - result = getJsonResult(baseURL + "/" + networkAddress_1, "DELETE"); + result = getJsonResult(baseURL + "/address/" + networkAddress_1, "DELETE"); Assert.assertTrue(httpResponseCode == 204); // verify host_1 removed from active host DB // test GET method: getActiveHosts() - no host expected - result = getJsonResult(baseURL, "GET"); + result = getJsonResult(baseURL + "/hosts/active", "GET"); Assert.assertTrue(httpResponseCode == 200); jt = new JSONTokener(result); @@ -1116,8 +1119,9 @@ public class NorthboundIT { JSONArray ja = json.getJSONArray("hostConfig"); for (int i = 0; i < ja.length(); i++) { String na = ja.getJSONObject(i).getString("networkAddress"); - if (na.equalsIgnoreCase(hostIp)) + if (na.equalsIgnoreCase(hostIp)) { return true; + } } return false; } else { @@ -1188,20 +1192,10 @@ public class NorthboundIT { JSONObject headNC = edge.getJSONObject("headNodeConnector"); JSONObject headNode = headNC.getJSONObject("node"); - - JSONArray propsArray = edgeProp.getJSONArray("properties"); - - JSONObject bandw = null; - JSONObject stt = null; - JSONObject ltc = null; - - for (int j = 0; j < propsArray.length(); j++) { - JSONObject props = propsArray.getJSONObject(j); - String propName = props.getString("name"); - if (propName.equals("bandwidth")) bandw = props; - if (propName.equals("state")) stt = props; - if (propName.equals("latency")) ltc = props; - } + JSONObject Props = edgeProp.getJSONObject("properties"); + JSONObject bandw = Props.getJSONObject("bandwidth"); + JSONObject stt = Props.getJSONObject("state"); + JSONObject ltc = Props.getJSONObject("latency"); if (headNC.getInt("id") == headNC1_nodeConnId) { Assert.assertEquals(headNode.getString("type"), nodeType); @@ -1233,7 +1227,6 @@ public class NorthboundIT { Integer nodeId_1 = 3366; String nodeConnectorType_1 = "STUB"; Integer nodeConnectorId_1 = 12; - String nodeType_2 = "STUB"; Integer nodeId_2 = 4477; String nodeConnectorType_2 = "STUB"; @@ -1246,11 +1239,11 @@ public class NorthboundIT { .put("dstNodeConnector", nodeConnectorType_2 + "|" + nodeConnectorId_2 + "@" + nodeType_2 + "|" + nodeId_2); // execute HTTP request and verify response code - result = getJsonResult(baseURL + "/user-link", "PUT", jo.toString()); + result = getJsonResult(baseURL + "/userLink/userLink_1", "PUT", jo.toString()); Assert.assertTrue(httpResponseCode == 201); // === test GET method for getUserLinks() - result = getJsonResult(baseURL + "/user-link", "GET"); + result = getJsonResult(baseURL + "/userLinks", "GET"); Assert.assertTrue(httpResponseCode == 200); if (debugMsg) { System.out.println("result:" + result); @@ -1268,8 +1261,9 @@ public class NorthboundIT { int i; for (i = 0; i < ja.length(); i++) { userlink = ja.getJSONObject(i); - if (userlink.getString("name").equalsIgnoreCase("userLink_1")) + if (userlink.getString("name").equalsIgnoreCase("userLink_1")) { break; + } } Assert.assertFalse(i == ja.length()); } else { @@ -1295,12 +1289,12 @@ public class NorthboundIT { // === test DELETE method for deleteUserLink() String userName = "userLink_1"; - result = getJsonResult(baseURL + "/user-link/" + userName, "DELETE"); - Assert.assertTrue(httpResponseCode == 200); + result = getJsonResult(baseURL + "/userLink/" + userName, "DELETE"); + Assert.assertTrue(httpResponseCode == 204); // execute another getUserLinks() request to verify that userLink_1 is // removed - result = getJsonResult(baseURL + "/user-link", "GET"); + result = getJsonResult(baseURL + "/userLinks", "GET"); Assert.assertTrue(httpResponseCode == 200); if (debugMsg) { System.out.println("result:" + result); @@ -1321,7 +1315,6 @@ public class NorthboundIT { } } } - // Configure the OSGi container @Configuration public Option[] config() { @@ -1355,7 +1348,7 @@ public class NorthboundIT { mavenBundle("org.opendaylight.controller", "configuration").versionAsInProject(), mavenBundle("org.opendaylight.controller", "configuration.implementation").versionAsInProject(), mavenBundle("org.opendaylight.controller", "containermanager").versionAsInProject(), - mavenBundle("org.opendaylight.controller", "containermanager.implementation").versionAsInProject(), + mavenBundle("org.opendaylight.controller", "containermanager.it.implementation").versionAsInProject(), mavenBundle("org.opendaylight.controller", "clustering.services").versionAsInProject(), mavenBundle("org.opendaylight.controller", "clustering.services-implementation").versionAsInProject(), mavenBundle("org.opendaylight.controller", "security").versionAsInProject().noStart(), @@ -1383,6 +1376,9 @@ public class NorthboundIT { mavenBundle("org.opendaylight.controller", "logging.bridge").versionAsInProject(), // mavenBundle("org.opendaylight.controller", "clustering.test").versionAsInProject(), mavenBundle("org.opendaylight.controller", "forwarding.staticrouting").versionAsInProject(), + mavenBundle("org.opendaylight.controller", "bundlescanner").versionAsInProject(), + mavenBundle("org.opendaylight.controller", "bundlescanner.implementation").versionAsInProject(), + mavenBundle("org.opendaylight.controller", "commons.httpclient").versionAsInProject(), // Northbound bundles mavenBundle("org.opendaylight.controller", "commons.northbound").versionAsInProject(), @@ -1465,6 +1461,8 @@ public class NorthboundIT { mavenBundle("org.ops4j.pax.exam", "pax-exam-link-mvn").versionAsInProject(), mavenBundle("org.ops4j.pax.url", "pax-url-aether").versionAsInProject(), + mavenBundle("org.ow2.asm", "asm-all").versionAsInProject(), + mavenBundle("org.springframework", "org.springframework.asm").versionAsInProject(), mavenBundle("org.springframework", "org.springframework.aop").versionAsInProject(), mavenBundle("org.springframework", "org.springframework.context").versionAsInProject(),