+ public void testStaticRoutingNorthbound() throws JSONException {
+ String baseURL = "http://127.0.0.1:8080/controller/nb/v2/staticroute/";
+
+ String name1 = "testRoute1";
+ String prefix1 = "192.168.1.1/24";
+ String nextHop1 = "0.0.0.0";
+ String name2 = "testRoute2";
+ String prefix2 = "192.168.1.1/16";
+ String nextHop2 = "1.1.1.1";
+
+ // Test GET static routes in default container, expecting no results
+ String result = getJsonResult(baseURL + "default");
+ JSONTokener jt = new JSONTokener(result);
+ JSONObject json = new JSONObject(jt);
+ Assert.assertEquals("{}", result);
+
+ // Test insert static route
+ String requestBody = "{\"name\":\"" + name1 + "\", \"prefix\":\""
+ + prefix1 + "\", \"nextHop\":\"" + nextHop1 + "\"}";
+ result = getJsonResult(baseURL + "default/" + name1, "POST",
+ requestBody);
+ Assert.assertEquals(201, httpResponseCode.intValue());
+
+ requestBody = "{\"name\":\"" + name2 + "\", \"prefix\":\"" + prefix2
+ + "\", \"nextHop\":\"" + nextHop2 + "\"}";
+ result = getJsonResult(baseURL + "default/" + name2, "POST",
+ requestBody);
+ Assert.assertEquals(201, httpResponseCode.intValue());
+
+ // Test Get all static routes
+ result = getJsonResult(baseURL + "default");
+ jt = new JSONTokener(result);
+ json = new JSONObject(jt);
+ JSONArray staticRoutes = json.getJSONArray("staticRoute");
+ Assert.assertEquals(2, staticRoutes.length());
+ JSONObject route;
+ for (int i = 0; i < staticRoutes.length(); i++) {
+ route = staticRoutes.getJSONObject(i);
+ if (route.getString("name").equals(name1)) {
+ Assert.assertEquals(prefix1, route.getString("prefix"));
+ Assert.assertEquals(nextHop1, route.getString("nextHop"));
+ } else if (route.getString("name").equals(name2)) {
+ Assert.assertEquals(prefix2, route.getString("prefix"));
+ Assert.assertEquals(nextHop2, route.getString("nextHop"));
+ } else {
+ // static route has unknown name
+ Assert.assertTrue(false);
+ }
+ }
+
+ // Test get specific static route
+ result = getJsonResult(baseURL + "default/" + name1);
+ jt = new JSONTokener(result);
+ json = new JSONObject(jt);
+
+ Assert.assertEquals(name1, json.getString("name"));
+ Assert.assertEquals(prefix1, json.getString("prefix"));
+ Assert.assertEquals(nextHop1, json.getString("nextHop"));
+
+ result = getJsonResult(baseURL + "default/" + name2);
+ jt = new JSONTokener(result);
+ json = new JSONObject(jt);
+
+ Assert.assertEquals(name2, json.getString("name"));
+ Assert.assertEquals(prefix2, json.getString("prefix"));
+ Assert.assertEquals(nextHop2, json.getString("nextHop"));
+
+ // Test delete static route
+ result = getJsonResult(baseURL + "default/" + name1, "DELETE");
+ Assert.assertEquals(200, httpResponseCode.intValue());
+
+ result = getJsonResult(baseURL + "default");
+ jt = new JSONTokener(result);
+ json = new JSONObject(jt);
+ JSONObject singleStaticRoute = json.getJSONObject("staticRoute");
+ Assert.assertEquals(name2, singleStaticRoute.getString("name"));
+
+ }
+
+ @Test
+ public void testSwitchManager() throws JSONException {