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;
}
+ @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/";