Subnets Northbound integration tests. 85/485/5
authorpatrichu <patrichu@cisco.com>
Fri, 14 Jun 2013 05:52:31 +0000 (22:52 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 14 Jun 2013 15:09:05 +0000 (15:09 +0000)
Change-Id: I8dc1017565b8e0f7aef72e01c915fa479458f1d8
Signed-off-by: patrichu <patrichu@cisco.com>
opendaylight/northbound/integrationtest/src/test/java/org/opendaylight/controller/northbound/integrationtest/NorthboundIT.java

index 0acedce..103a515 100644 (file)
@@ -41,11 +41,9 @@ import org.opendaylight.controller.sal.core.UpdateType;
 import org.opendaylight.controller.switchmanager.IInventoryListener;
 import org.opendaylight.controller.usermanager.IUserManager;
 
-
 @RunWith(PaxExam.class)
 public class NorthboundIT {
-    private Logger log = LoggerFactory
-            .getLogger(NorthboundIT.class);
+    private Logger log = LoggerFactory.getLogger(NorthboundIT.class);
     // get the OSGI bundle context
     @Inject
     private BundleContext bc;
@@ -256,6 +254,76 @@ public class NorthboundIT {
 
     }
 
+    @Test
+    public void testSubnetsNorthbound() throws JSONException {
+        String baseURL = "http://127.0.0.1:8080/controller/nb/v2/subnet/";
+
+        String name1 = "testSubnet1";
+        String subnet1 = "1.1.1.1/24";
+        String name2 = "testSubnet2";
+        String subnet2 = "2.2.2.2/24";
+
+        // Test GET subnets in default container
+        String result = getJsonResult(baseURL + "default");
+        JSONTokener jt = new JSONTokener(result);
+        JSONObject json = new JSONObject(jt);
+        Assert.assertEquals("{}", result);
+
+        // Test GET subnet1 expecting 404
+        result = getJsonResult(baseURL + "default/" + name1);
+        Assert.assertEquals(404, httpResponseCode.intValue());
+
+        // Test POST subnet1
+        String queryParameter = new QueryParameter("subnetName", name1).add(
+                "subnet", subnet1).getString();
+        result = getJsonResult(baseURL + "default/" + name1 + queryParameter,
+                "POST");
+        Assert.assertEquals(201, httpResponseCode.intValue());
+
+        // Test GET subnet1
+        result = getJsonResult(baseURL + "default/" + name1);
+        jt = new JSONTokener(result);
+        json = new JSONObject(jt);
+        Assert.assertEquals(200, httpResponseCode.intValue());
+        Assert.assertEquals(name1, json.getString("@name"));
+        Assert.assertEquals(subnet1, json.getString("@subnet"));
+
+        // Test POST subnet2
+        queryParameter = new QueryParameter("subnetName", name2).add("subnet",
+                subnet2).getString();
+        result = getJsonResult(baseURL + "default/" + name2 + queryParameter,
+                "POST");
+        Assert.assertEquals(201, httpResponseCode.intValue());
+
+        // Test GET all subnets in default container
+        result = getJsonResult(baseURL + "default");
+        jt = new JSONTokener(result);
+        json = new JSONObject(jt);
+        JSONArray subnetConfigArray = json.getJSONArray("subnetConfig");
+        JSONObject subnetConfig;
+        Assert.assertEquals(2, subnetConfigArray.length());
+        for (int i = 0; i < subnetConfigArray.length(); i++) {
+            subnetConfig = subnetConfigArray.getJSONObject(i);
+            if (subnetConfig.getString("@name").equals(name1)) {
+                Assert.assertEquals(subnet1, subnetConfig.getString("@subnet"));
+            } else if (subnetConfig.getString("@name").equals(name2)) {
+                Assert.assertEquals(subnet2, subnetConfig.getString("@subnet"));
+            } else {
+                // Unexpected config name
+                Assert.assertTrue(false);
+            }
+        }
+
+        // Test DELETE subnet1
+        result = getJsonResult(baseURL + "default/" + name1, "DELETE");
+        Assert.assertEquals(200, httpResponseCode.intValue());
+
+        // Test GET deleted subnet1
+        result = getJsonResult(baseURL + "default/" + name1);
+        Assert.assertEquals(404, httpResponseCode.intValue());
+
+    }
+
     @Test
     public void testStaticRoutingNorthbound() throws JSONException {
         String baseURL = "http://127.0.0.1:8080/controller/nb/v2/staticroute/";