summaryrefslogtreecommitdiffstats
path: root/framework/src/onos/web/api
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/web/api')
-rw-r--r--framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java4
-rw-r--r--framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ClusterWebResource.java6
-rw-r--r--framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/DevicesWebResource.java6
-rw-r--r--framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java8
-rw-r--r--framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java8
-rw-r--r--framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java6
-rw-r--r--framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/LinksWebResource.java2
-rw-r--r--framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java2
-rw-r--r--framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/PathsWebResource.java4
-rw-r--r--framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java10
-rw-r--r--framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/TopologyWebResource.java14
-rw-r--r--framework/src/onos/web/api/src/main/resources/definitions/Application.json4
-rw-r--r--framework/src/onos/web/api/src/main/resources/definitions/ApplicationPost.json4
-rw-r--r--framework/src/onos/web/api/src/main/resources/definitions/Applications.json4
-rw-r--r--framework/src/onos/web/api/src/test/java/org/onosproject/rest/resources/NetworkConfigWebResourceTest.java352
15 files changed, 392 insertions, 42 deletions
diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java
index b38633bf..f0383346 100644
--- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java
+++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java
@@ -44,7 +44,7 @@ public class ApplicationsWebResource extends AbstractWebResource {
* Get all installed applications.
* Returns array of all installed applications.
*
- * @rsModel Applications
+ * @onos.rsModel Applications
* @return 200 OK
*/
@GET
@@ -57,7 +57,7 @@ public class ApplicationsWebResource extends AbstractWebResource {
/**
* Get application details.
* Returns details of the specified application.
- * @rsModel Application
+ * @onos.rsModel Application
* @param name application name
* @return 200 OK; 404; 401
*/
diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ClusterWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ClusterWebResource.java
index 16a4dc7f..cedbd6b6 100644
--- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ClusterWebResource.java
+++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ClusterWebResource.java
@@ -49,7 +49,7 @@ public class ClusterWebResource extends AbstractWebResource {
* Returns array of all cluster nodes.
*
* @return 200 OK
- * @rsModel Cluster
+ * @onos.rsModel Cluster
*/
@GET
public Response getClusterNodes() {
@@ -63,7 +63,7 @@ public class ClusterWebResource extends AbstractWebResource {
*
* @param id cluster node identifier
* @return 200 OK
- * @rsModel ClusterNode
+ * @onos.rsModel ClusterNode
*/
@GET
@Path("{id}")
@@ -80,7 +80,7 @@ public class ClusterWebResource extends AbstractWebResource {
* @param config cluster definition
* @return 200 OK
* @throws IOException to signify bad request
- * @rsModel ClusterPost
+ * @onos.rsModel ClusterPost
*/
@POST
@Path("configuration")
diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/DevicesWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/DevicesWebResource.java
index 23ca46e7..be1e5b63 100644
--- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/DevicesWebResource.java
+++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/DevicesWebResource.java
@@ -46,7 +46,7 @@ public class DevicesWebResource extends AbstractWebResource {
* Returns array of all discovered infrastructure devices.
*
* @return 200 OK
- * @rsModel DevicesGet
+ * @onos.rsModel DevicesGet
*/
@GET
public Response getDevices() {
@@ -60,7 +60,7 @@ public class DevicesWebResource extends AbstractWebResource {
*
* @param id device identifier
* @return 200 OK
- * @rsModel DeviceGet
+ * @onos.rsModel DeviceGet
*/
@GET
@Path("{id}")
@@ -91,7 +91,7 @@ public class DevicesWebResource extends AbstractWebResource {
* Get ports of infrastructure device.
* Returns details of the specified infrastructure device.
*
- * @rsModel DeviceGetPorts
+ * @onos.rsModel DeviceGetPorts
* @param id device identifier
* @return 200 OK
*/
diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java
index 252a3ba7..e5e1ddab 100644
--- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java
+++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java
@@ -58,7 +58,7 @@ public class FlowsWebResource extends AbstractWebResource {
/**
* Get all flow entries. Returns array of all flow rules in the system.
- * @rsModel Flows
+ * @onos.rsModel Flows
* @return array of all the intents in the system
*/
@GET
@@ -80,7 +80,7 @@ public class FlowsWebResource extends AbstractWebResource {
/**
* Get flow entries of a device. Returns array of all flow rules for the
* specified device.
- * @rsModel Flows
+ * @onos.rsModel Flows
* @param deviceId device identifier
* @return flow data as an array
*/
@@ -103,7 +103,7 @@ public class FlowsWebResource extends AbstractWebResource {
/**
* Get flow rule. Returns the flow entry specified by the device id and
* flow rule id.
- * @rsModel Flows
+ * @onos.rsModel Flows
* @param deviceId device identifier
* @param flowId flow rule identifier
* @return flow data as an array
@@ -130,7 +130,7 @@ public class FlowsWebResource extends AbstractWebResource {
/**
* Create new flow rule. Creates and installs a new flow rule for the
* specified device.
- * @rsModel FlowsPost
+ * @onos.rsModel FlowsPost
* @param deviceId device identifier
* @param stream flow rule JSON
* @return status of the request - CREATED if the JSON is correct,
diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java
index 00cbdf2f..8f69c24d 100644
--- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java
+++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java
@@ -73,7 +73,7 @@ public class HostsWebResource extends AbstractWebResource {
* Returns array of all known end-station hosts.
*
* @return 200 OK
- * @rsModel Hosts
+ * @onos.rsModel Hosts
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@@ -89,7 +89,7 @@ public class HostsWebResource extends AbstractWebResource {
*
* @param id host identifier
* @return 200 OK
- * @rsModel Host
+ * @onos.rsModel Host
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@@ -108,7 +108,7 @@ public class HostsWebResource extends AbstractWebResource {
* @param mac host MAC address
* @param vlan host VLAN identifier
* @return 200 OK
- * @rsModel Host
+ * @onos.rsModel Host
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@@ -128,7 +128,7 @@ public class HostsWebResource extends AbstractWebResource {
* @param stream input JSON
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
- * @rsModel HostPut
+ * @onos.rsModel HostPut
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java
index 2c63db9c..e6955045 100644
--- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java
+++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java
@@ -70,7 +70,7 @@ public class IntentsWebResource extends AbstractWebResource {
/**
* Get all intents.
* Returns array containing all the intents in the system.
- * @rsModel Intents
+ * @onos.rsModel Intents
* @return array of all the intents in the system
*/
@GET
@@ -84,7 +84,7 @@ public class IntentsWebResource extends AbstractWebResource {
/**
* Get intent by application and key.
* Returns details of the specified intent.
- * @rsModel Intents
+ * @onos.rsModel Intents
* @param appId application identifier
* @param key intent key
* @return intent data
@@ -136,7 +136,7 @@ public class IntentsWebResource extends AbstractWebResource {
/**
* Submit a new intent.
* Creates and submits intent from the JSON request.
- * @rsModel IntentHost
+ * @onos.rsModel IntentHost
* @param stream input JSON
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/LinksWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/LinksWebResource.java
index e36ea8af..edf9f028 100644
--- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/LinksWebResource.java
+++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/LinksWebResource.java
@@ -44,7 +44,7 @@ public class LinksWebResource extends AbstractWebResource {
/**
* Get infrastructure links.
* Returns array of all links, or links for the specified device or port.
- * @rsModel LinksGet
+ * @onos.rsModel LinksGet
* @param deviceId (optional) device identifier
* @param port (optional) port number
* @param direction (optional) direction qualifier
diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java
index 69c0b6a3..9e474fd3 100644
--- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java
+++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java
@@ -68,7 +68,6 @@ public class NetworkConfigWebResource extends AbstractWebResource {
/**
* Get entire network configuration base.
*
- * @rsModel NetCfgGet
* @return network configuration JSON
*/
@GET
@@ -185,7 +184,6 @@ public class NetworkConfigWebResource extends AbstractWebResource {
/**
* Upload bulk network configuration.
*
- * @rsModel NetCfgGet
* @param request network configuration JSON rooted at the top node
* @return empty response
* @throws IOException if unable to parse the request
diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/PathsWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/PathsWebResource.java
index c14b4ec2..9968d1e7 100644
--- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/PathsWebResource.java
+++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/PathsWebResource.java
@@ -60,7 +60,7 @@ public class PathsWebResource extends AbstractWebResource {
/**
* Get all shortest paths between any two hosts or devices.
* Returns array of all shortest paths between any two elements.
- * @rsModel Paths
+ * @onos.rsModel Paths
* @param src source identifier
* @param dst destination identifier
* @return path data
@@ -79,7 +79,7 @@ public class PathsWebResource extends AbstractWebResource {
/**
* Get all shortest disjoint paths between any two hosts or devices.
* Returns array of all shortest disjoint paths between any two elements.
- * @rsModel Paths
+ * @onos.rsModel Paths
* @param src source identifier
* @param dst destination identifier
* @return path data
diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java
index 284d3775..7c6dd74e 100644
--- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java
+++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java
@@ -60,7 +60,7 @@ public class StatisticsWebResource extends AbstractWebResource {
/**
* Get load statistics for all links or for a specific link.
- * @rsModel StatisticsFlowsLink
+ * @onos.rsModel StatisticsFlowsLink
* @param deviceId (optional) device ID for a specific link
* @param port (optional) port number for a specified link
* @return JSON encoded array lof Load objects
@@ -102,7 +102,7 @@ public class StatisticsWebResource extends AbstractWebResource {
/**
* Get table statistics for all tables of all devices.
- * @rsModel StatisticsFlowsTables
+ * @onos.rsModel StatisticsFlowsTables
* @return JSON encoded array of table statistics
*/
@GET
@@ -131,7 +131,7 @@ public class StatisticsWebResource extends AbstractWebResource {
/**
* Get table statistics for all tables of a specified device.
- * @rsModel StatisticsFlowsTables
+ * @onos.rsModel StatisticsFlowsTables
* @param deviceId device ID
* @return JSON encoded array of table statistics
*/
@@ -157,7 +157,7 @@ public class StatisticsWebResource extends AbstractWebResource {
/**
* Get port statistics of all devices.
- * @rsModel StatisticsPorts
+ * @onos.rsModel StatisticsPorts
* @return JSON encoded array of port statistics
*/
@GET
@@ -186,7 +186,7 @@ public class StatisticsWebResource extends AbstractWebResource {
/**
* Get port statistics of a specified devices.
- * @rsModel StatisticsPorts
+ * @onos.rsModel StatisticsPorts
* @param deviceId device ID
* @return JSON encoded array of port statistics
*/
diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/TopologyWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/TopologyWebResource.java
index d51bd5a0..683f7afe 100644
--- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/TopologyWebResource.java
+++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/TopologyWebResource.java
@@ -50,7 +50,7 @@ public class TopologyWebResource extends AbstractWebResource {
* Get overview of current topology.
*
* @return topology overview
- * @rsModel Topology
+ * @onos.rsModel Topology
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@@ -64,7 +64,7 @@ public class TopologyWebResource extends AbstractWebResource {
* Get overview of topology SCCs.
*
* @return topology clusters overview
- * @rsModel TopologyClusters
+ * @onos.rsModel TopologyClusters
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@@ -82,7 +82,7 @@ public class TopologyWebResource extends AbstractWebResource {
*
* @param clusterId id of the cluster to query
* @return topology cluster details
- * @rsModel TopologyCluster
+ * @onos.rsModel TopologyCluster
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@@ -106,7 +106,7 @@ public class TopologyWebResource extends AbstractWebResource {
*
* @param clusterId id of the cluster to query
* @return topology cluster devices
- * @rsModel TopologyClustersDevices
+ * @onos.rsModel TopologyClustersDevices
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@@ -130,7 +130,7 @@ public class TopologyWebResource extends AbstractWebResource {
*
* @param clusterId id of the cluster to query
* @return topology cluster links
- * @rsModel LinksGet
+ * @onos.rsModel LinksGet
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@@ -180,7 +180,7 @@ public class TopologyWebResource extends AbstractWebResource {
* @param connectPointString deviceid:portnumber
* @return JSON representation of true if the connect point is broadcast,
* false otherwise
- * @rsModel TopologyBroadcast
+ * @onos.rsModel TopologyBroadcast
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@@ -205,7 +205,7 @@ public class TopologyWebResource extends AbstractWebResource {
* @param connectPointString deviceid:portnumber
* @return JSON representation of true if the connect point is broadcast,
* false otherwise
- * @rsModel TopologyInfrastructure
+ * @onos.rsModel TopologyInfrastructure
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
diff --git a/framework/src/onos/web/api/src/main/resources/definitions/Application.json b/framework/src/onos/web/api/src/main/resources/definitions/Application.json
index ea6c3ea2..fb5bbeb9 100644
--- a/framework/src/onos/web/api/src/main/resources/definitions/Application.json
+++ b/framework/src/onos/web/api/src/main/resources/definitions/Application.json
@@ -25,7 +25,7 @@
},
"version": {
"type": "string",
- "example": "1.4.0.SNAPSHOT"
+ "example": "1.2.3"
},
"description": {
"type": "string",
@@ -48,7 +48,7 @@
},
"featuresRepo": {
"type": "string",
- "example": "mvn:org.onosproject/onos-app-cip/1.4.0-SNAPSHOT/xml/features"
+ "example": "mvn:org.onosproject/onos-app-cip/1.2.3/xml/features"
},
"features": {
"type": "array",
diff --git a/framework/src/onos/web/api/src/main/resources/definitions/ApplicationPost.json b/framework/src/onos/web/api/src/main/resources/definitions/ApplicationPost.json
index ea6c3ea2..fb5bbeb9 100644
--- a/framework/src/onos/web/api/src/main/resources/definitions/ApplicationPost.json
+++ b/framework/src/onos/web/api/src/main/resources/definitions/ApplicationPost.json
@@ -25,7 +25,7 @@
},
"version": {
"type": "string",
- "example": "1.4.0.SNAPSHOT"
+ "example": "1.2.3"
},
"description": {
"type": "string",
@@ -48,7 +48,7 @@
},
"featuresRepo": {
"type": "string",
- "example": "mvn:org.onosproject/onos-app-cip/1.4.0-SNAPSHOT/xml/features"
+ "example": "mvn:org.onosproject/onos-app-cip/1.2.3/xml/features"
},
"features": {
"type": "array",
diff --git a/framework/src/onos/web/api/src/main/resources/definitions/Applications.json b/framework/src/onos/web/api/src/main/resources/definitions/Applications.json
index d7653619..304404a4 100644
--- a/framework/src/onos/web/api/src/main/resources/definitions/Applications.json
+++ b/framework/src/onos/web/api/src/main/resources/definitions/Applications.json
@@ -38,7 +38,7 @@
},
"version": {
"type": "string",
- "example": "1.4.0.SNAPSHOT"
+ "example": "1.2.3"
},
"description": {
"type": "string",
@@ -61,7 +61,7 @@
},
"featuresRepo": {
"type": "string",
- "example": "mvn:org.onosproject/onos-app-cip/1.4.0-SNAPSHOT/xml/features"
+ "example": "mvn:org.onosproject/onos-app-cip/1.2.3/xml/features"
},
"features": {
"type": "array",
diff --git a/framework/src/onos/web/api/src/test/java/org/onosproject/rest/resources/NetworkConfigWebResourceTest.java b/framework/src/onos/web/api/src/test/java/org/onosproject/rest/resources/NetworkConfigWebResourceTest.java
new file mode 100644
index 00000000..2b341af2
--- /dev/null
+++ b/framework/src/onos/web/api/src/test/java/org/onosproject/rest/resources/NetworkConfigWebResourceTest.java
@@ -0,0 +1,352 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.rest.resources;
+
+import java.net.HttpURLConnection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.osgi.ServiceDirectory;
+import org.onlab.osgi.TestServiceDirectory;
+import org.onlab.rest.BaseResource;
+import org.onosproject.net.DefaultDevice;
+import org.onosproject.net.Device;
+import org.onosproject.net.Link;
+import org.onosproject.net.config.Config;
+import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.net.config.NetworkConfigServiceAdapter;
+import org.onosproject.net.config.SubjectFactory;
+import org.onosproject.rest.ResourceTest;
+
+import com.eclipsesource.json.JsonObject;
+import com.eclipsesource.json.JsonValue;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.ImmutableSet;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import com.sun.jersey.api.client.WebResource;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.replay;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.fail;
+
+/**
+ * Unit tests for network config web resource.
+ */
+public class NetworkConfigWebResourceTest extends ResourceTest {
+
+ MockNetworkConfigService mockNetworkConfigService;
+
+ public class MockDeviceConfig extends Config<Device> {
+
+ final String field1Value;
+ final String field2Value;
+
+ MockDeviceConfig(String value1, String value2) {
+ field1Value = value1;
+ field2Value = value2;
+ }
+
+ @Override
+ public String key() {
+ return "basic";
+ }
+
+ @Override
+ public JsonNode node() {
+ return new ObjectMapper()
+ .createObjectNode()
+ .put("field1", field1Value)
+ .put("field2", field2Value);
+ }
+ }
+
+ /**
+ * Mock config factory for devices.
+ */
+ private final SubjectFactory<Device> mockDevicesSubjectFactory =
+ new SubjectFactory<Device>(Device.class, "devices") {
+ @Override
+ public Device createSubject(String subjectKey) {
+ DefaultDevice device = createMock(DefaultDevice.class);
+ replay(device);
+ return device;
+ }
+
+ @Override
+ public Class<Device> subjectClass() {
+ return Device.class;
+ }
+ };
+
+ /**
+ * Mock config factory for links.
+ */
+ private final SubjectFactory<Link> mockLinksSubjectFactory =
+ new SubjectFactory<Link>(Link.class, "links") {
+ @Override
+ public Link createSubject(String subjectKey) {
+ return null;
+ }
+
+ @Override
+ public Class<Link> subjectClass() {
+ return Link.class;
+ }
+ };
+
+ /**
+ * Mocked config service.
+ */
+ class MockNetworkConfigService extends NetworkConfigServiceAdapter {
+
+ Set devicesSubjects = new HashSet<>();
+ Set devicesConfigs = new HashSet<>();
+ Set linksSubjects = new HashSet();
+ Set linksConfigs = new HashSet<>();
+
+ @Override
+ public Set<Class> getSubjectClasses() {
+ return ImmutableSet.of(Device.class, Link.class);
+ }
+
+ @Override
+ public SubjectFactory getSubjectFactory(Class subjectClass) {
+ if (subjectClass == Device.class) {
+ return mockDevicesSubjectFactory;
+ } else if (subjectClass == Link.class) {
+ return mockLinksSubjectFactory;
+ }
+ return null;
+ }
+
+ @Override
+ public SubjectFactory getSubjectFactory(String subjectClassKey) {
+ if (subjectClassKey.equals("devices")) {
+ return mockDevicesSubjectFactory;
+ } else if (subjectClassKey.equals("links")) {
+ return mockLinksSubjectFactory;
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <S> Set<S> getSubjects(Class<S> subjectClass) {
+ if (subjectClass == Device.class) {
+ return devicesSubjects;
+ } else if (subjectClass == Link.class) {
+ return linksSubjects;
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <S> Set<? extends Config<S>> getConfigs(S subject) {
+ if (subject instanceof Device || subject.toString().contains("device")) {
+ return devicesConfigs;
+ } else if (subject.toString().contains("link")) {
+ return linksConfigs;
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
+
+ if (configClass == MockDeviceConfig.class) {
+ return (C) devicesConfigs.toArray()[0];
+ }
+ return null;
+ }
+
+ @Override
+ public Class<? extends Config> getConfigClass(String subjectClassKey, String configKey) {
+ return MockDeviceConfig.class;
+ }
+ }
+
+ /**
+ * Sets up mocked config service.
+ */
+ @Before
+ public void setUp() {
+ mockNetworkConfigService = new MockNetworkConfigService();
+ ServiceDirectory testDirectory =
+ new TestServiceDirectory()
+ .add(NetworkConfigService.class, mockNetworkConfigService);
+ BaseResource.setServiceDirectory(testDirectory);
+ }
+
+ /**
+ * Sets up test config data.
+ */
+ @SuppressWarnings("unchecked")
+ public void setUpConfigData() {
+ mockNetworkConfigService.devicesSubjects.add("device1");
+ mockNetworkConfigService.devicesConfigs.add(new MockDeviceConfig("v1", "v2"));
+ }
+
+ /**
+ * Tests the result of the rest api GET when there are no configs.
+ */
+ @Test
+ public void testEmptyConfigs() {
+ final WebResource rs = resource();
+ final String response = rs.path("network/configuration").get(String.class);
+
+ assertThat(response, containsString("\"devices\":{}"));
+ assertThat(response, containsString("\"links\":{}"));
+ }
+
+ /**
+ * Tests the result of the rest api GET for a single subject with no configs.
+ */
+ @Test
+ public void testEmptyConfig() {
+ final WebResource rs = resource();
+ final String response = rs.path("network/configuration/devices").get(String.class);
+
+ assertThat(response, is("{}"));
+ }
+
+ /**
+ * Tests the result of the rest api GET for a single subject that
+ * is undefined.
+ */
+ @Test
+ public void testNonExistentConfig() {
+ final WebResource rs = resource();
+
+ try {
+ final String response = rs.path("network/configuration/nosuchkey").get(String.class);
+ fail("GET of non-existent key does not produce an exception " + response);
+ } catch (UniformInterfaceException e) {
+ assertThat(e.getResponse().getStatus(), is(HttpURLConnection.HTTP_NOT_FOUND));
+ }
+ }
+
+ private void checkBasicAttributes(JsonValue basic) {
+ Assert.assertThat(basic.asObject().get("field1").asString(), is("v1"));
+ Assert.assertThat(basic.asObject().get("field2").asString(), is("v2"));
+ }
+
+ /**
+ * Tests the result of the rest api GET when there is a config.
+ */
+ @Test
+
+ public void testConfigs() {
+ setUpConfigData();
+ final WebResource rs = resource();
+ final String response = rs.path("network/configuration").get(String.class);
+
+ final JsonObject result = JsonObject.readFrom(response);
+ Assert.assertThat(result, notNullValue());
+
+ Assert.assertThat(result.names(), hasSize(2));
+
+ JsonValue devices = result.get("devices");
+ Assert.assertThat(devices, notNullValue());
+
+ JsonValue device1 = devices.asObject().get("device1");
+ Assert.assertThat(device1, notNullValue());
+
+ JsonValue basic = device1.asObject().get("basic");
+ Assert.assertThat(basic, notNullValue());
+
+ checkBasicAttributes(basic);
+ }
+
+ /**
+ * Tests the result of the rest api single subject key GET when
+ * there is a config.
+ */
+ @Test
+ public void testSingleSubjectKeyConfig() {
+ setUpConfigData();
+ final WebResource rs = resource();
+ final String response = rs.path("network/configuration/devices").get(String.class);
+
+ final JsonObject result = JsonObject.readFrom(response);
+ Assert.assertThat(result, notNullValue());
+
+ Assert.assertThat(result.names(), hasSize(1));
+
+ JsonValue device1 = result.asObject().get("device1");
+ Assert.assertThat(device1, notNullValue());
+
+ JsonValue basic = device1.asObject().get("basic");
+ Assert.assertThat(basic, notNullValue());
+
+ checkBasicAttributes(basic);
+ }
+
+ /**
+ * Tests the result of the rest api single subject GET when
+ * there is a config.
+ */
+ @Test
+ public void testSingleSubjectConfig() {
+ setUpConfigData();
+ final WebResource rs = resource();
+ final String response =
+ rs.path("network/configuration/devices/device1")
+ .get(String.class);
+
+ final JsonObject result = JsonObject.readFrom(response);
+ Assert.assertThat(result, notNullValue());
+
+ Assert.assertThat(result.names(), hasSize(1));
+
+ JsonValue basic = result.asObject().get("basic");
+ Assert.assertThat(basic, notNullValue());
+
+ checkBasicAttributes(basic);
+ }
+
+ /**
+ * Tests the result of the rest api single subject single config GET when
+ * there is a config.
+ */
+ @Test
+ public void testSingleSubjectSingleConfig() {
+ setUpConfigData();
+ final WebResource rs = resource();
+ final String response =
+ rs.path("network/configuration/devices/device1/basic")
+ .get(String.class);
+
+ final JsonObject result = JsonObject.readFrom(response);
+ Assert.assertThat(result, notNullValue());
+
+ Assert.assertThat(result.names(), hasSize(2));
+
+ checkBasicAttributes(result);
+ }
+
+ // TODO: Add test for DELETE and POST
+}