Jian Li

Replace deprecated JsonObject.readFrom() with Json.parse().asObject

Change-Id: I9e6e5a83edfd2c6abc694c1cc1e939b0b826e980
......@@ -24,6 +24,7 @@ import static org.junit.Assert.assertThat;
import static org.onosproject.net.NetTestTools.device;
import static org.onosproject.net.NetTestTools.did;
import com.eclipsesource.json.Json;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -93,7 +94,7 @@ public class ClassifierResourceTest extends VtnResourceTest {
final WebResource rs = resource();
final String response = rs.path("classifiers").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
}
}
......
......@@ -33,6 +33,7 @@ import java.util.Set;
import javax.ws.rs.core.MediaType;
import com.eclipsesource.json.Json;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -238,7 +239,7 @@ public class FlowClassifierResourceTest extends VtnResourceTest {
final WebResource rs = resource();
final String response = rs.path("flow_classifiers/4a334cd4-fe9c-4fae-af4b-321c5e2eb051").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
}
......
......@@ -34,6 +34,7 @@ import java.util.Set;
import javax.ws.rs.core.MediaType;
import com.eclipsesource.json.Json;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -184,7 +185,7 @@ public class PortChainResourceTest extends VtnResourceTest {
final WebResource rs = resource();
final String response = rs.path("port_chains/1278dcd4-459f-62ed-754b-87fc5e4a6751").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
}
......
......@@ -34,6 +34,7 @@ import java.util.Set;
import javax.ws.rs.core.MediaType;
import com.eclipsesource.json.Json;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -171,7 +172,7 @@ public class PortPairGroupResourceTest extends VtnResourceTest {
final WebResource rs = resource();
final String response = rs.path("port_pair_groups/4512d643-24fc-4fae-af4b-321c5e2eb3d1").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
}
......
......@@ -33,6 +33,7 @@ import java.util.Set;
import javax.ws.rs.core.MediaType;
import com.eclipsesource.json.Json;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -174,7 +175,7 @@ public class PortPairResourceTest extends VtnResourceTest {
final WebResource rs = resource();
final String response = rs.path("port_pairs/78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
}
......
......@@ -15,6 +15,7 @@
*/
package org.onosproject.rest;
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonObject;
import com.google.common.collect.ImmutableList;
......@@ -227,7 +228,7 @@ public class ApplicationsResourceTest extends ResourceTest {
String response = rs.path("applications").get(String.class);
assertThat(response, containsString("{\"applications\":["));
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......@@ -253,7 +254,7 @@ public class ApplicationsResourceTest extends ResourceTest {
WebResource rs = resource();
String response = rs.path("applications/three").get(String.class);
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result, matchesApp(app3));
......@@ -324,7 +325,7 @@ public class ApplicationsResourceTest extends ResourceTest {
WebResource rs = resource();
String response = rs.path("applications").post(String.class, app4Json);
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result, matchesApp(app4));
......
......@@ -17,6 +17,7 @@ package org.onosproject.rest;
import java.util.List;
import com.eclipsesource.json.Json;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
import org.junit.After;
......@@ -271,7 +272,7 @@ public class DevicesResourceTest extends ResourceTest {
String response = rs.path("devices").get(String.class);
assertThat(response, containsString("{\"devices\":["));
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......@@ -303,7 +304,7 @@ public class DevicesResourceTest extends ResourceTest {
WebResource rs = resource();
String response = rs.path("devices/" + deviceId).get(String.class);
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, matchesDevice(device));
}
......@@ -335,7 +336,7 @@ public class DevicesResourceTest extends ResourceTest {
String response =
rs.path("devices/" + deviceId + "/ports")
.get(String.class);
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, matchesDevice(device));
JsonArray jsonPorts = result.get("ports").asArray();
......
......@@ -15,6 +15,7 @@
*/
package org.onosproject.rest;
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonObject;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
......@@ -134,7 +135,7 @@ public class FlowObjectiveResourceTest extends ResourceTest {
WebResource rs = resource();
final String response = rs.path("flowobjectives/next").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......
......@@ -15,6 +15,7 @@
*/
package org.onosproject.rest;
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonObject;
import com.google.common.collect.ImmutableSet;
......@@ -490,7 +491,7 @@ public class FlowsResourceTest extends ResourceTest {
replay(mockDeviceService);
final WebResource rs = resource();
final String response = rs.path("flows").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......@@ -518,7 +519,7 @@ public class FlowsResourceTest extends ResourceTest {
replay(mockDeviceService);
final WebResource rs = resource();
final String response = rs.path("flows/" + deviceId3).get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......@@ -545,7 +546,7 @@ public class FlowsResourceTest extends ResourceTest {
final WebResource rs = resource();
final String response = rs.path("flows/" + deviceId3 + "/"
+ Long.toString(flow5.id().value())).get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......
......@@ -16,6 +16,7 @@
package org.onosproject.rest;
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonObject;
import com.google.common.collect.ImmutableSet;
......@@ -410,7 +411,7 @@ public class GroupsResourceTest extends ResourceTest {
replay(mockDeviceService);
final WebResource rs = resource();
final String response = rs.path("groups").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......@@ -438,7 +439,7 @@ public class GroupsResourceTest extends ResourceTest {
replay(mockDeviceService);
final WebResource rs = resource();
final String response = rs.path("groups/" + deviceId3).get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......@@ -460,7 +461,7 @@ public class GroupsResourceTest extends ResourceTest {
replay(mockGroupService);
final WebResource rs = resource();
final String response = rs.path("groups/" + deviceId3 + "/" + "111").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......
......@@ -21,6 +21,7 @@ import java.net.HttpURLConnection;
import java.util.HashSet;
import java.util.Set;
import com.eclipsesource.json.Json;
import com.sun.jersey.api.client.ClientResponse;
import org.hamcrest.Description;
import org.hamcrest.Matchers;
......@@ -273,7 +274,7 @@ public class HostResourceTest extends ResourceTest {
String response = rs.path("hosts").get(String.class);
assertThat(response, containsString("{\"hosts\":["));
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......@@ -308,7 +309,7 @@ public class HostResourceTest extends ResourceTest {
WebResource rs = resource();
String response = rs.path("hosts/00:00:11:00:00:01%2F1").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, matchesHost(host1));
}
......@@ -334,7 +335,7 @@ public class HostResourceTest extends ResourceTest {
WebResource rs = resource();
String response = rs.path("hosts/00:00:11:00:00:01/1").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, matchesHost(host1));
}
......
......@@ -15,6 +15,7 @@
*/
package org.onosproject.rest;
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonObject;
import com.eclipsesource.json.JsonValue;
......@@ -294,7 +295,7 @@ public class IntentsResourceTest extends ResourceTest {
final String response = rs.path("intents").get(String.class);
assertThat(response, containsString("{\"intents\":["));
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......@@ -341,13 +342,13 @@ public class IntentsResourceTest extends ResourceTest {
// Test get using key string
final String response = rs.path("intents/" + APP_ID.name()
+ "/0").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, matchesIntent(intent));
// Test get using numeric value
final String responseNumeric = rs.path("intents/" + APP_ID.name()
+ "/0x0").get(String.class);
final JsonObject resultNumeric = JsonObject.readFrom(responseNumeric);
final JsonObject resultNumeric = Json.parse(responseNumeric).asObject();
assertThat(resultNumeric, matchesIntent(intent));
}
......
......@@ -15,6 +15,7 @@
*/
package org.onosproject.rest;
import com.eclipsesource.json.Json;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
import org.junit.After;
......@@ -200,7 +201,7 @@ public class LinksResourceTest extends ResourceTest {
String response = rs.path("links").get(String.class);
assertThat(response, containsString("{\"links\":["));
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......@@ -233,7 +234,7 @@ public class LinksResourceTest extends ResourceTest {
.get(String.class);
assertThat(response, containsString("{\"links\":["));
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......@@ -267,7 +268,7 @@ public class LinksResourceTest extends ResourceTest {
.get(String.class);
assertThat(response, containsString("{\"links\":["));
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......@@ -302,7 +303,7 @@ public class LinksResourceTest extends ResourceTest {
.get(String.class);
assertThat(response, containsString("{\"links\":["));
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......@@ -336,7 +337,7 @@ public class LinksResourceTest extends ResourceTest {
.get(String.class);
assertThat(response, containsString("{\"links\":["));
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......
......@@ -16,6 +16,7 @@
package org.onosproject.rest;
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonObject;
import com.google.common.collect.ImmutableSet;
......@@ -385,7 +386,7 @@ public class MetersResourceTest extends ResourceTest {
replay(mockDeviceService);
final WebResource rs = resource();
final String response = rs.path("meters").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......@@ -415,7 +416,7 @@ public class MetersResourceTest extends ResourceTest {
final WebResource rs = resource();
final String response = rs.path("meters/" + deviceId1.toString()).get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......@@ -441,7 +442,7 @@ public class MetersResourceTest extends ResourceTest {
final WebResource rs = resource();
final String response = rs.path("meters/" + deviceId3.toString()
+ "/" + meter5.id().id()).get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......
......@@ -19,6 +19,7 @@ import com.codahale.metrics.Counter;
import com.codahale.metrics.Meter;
import com.codahale.metrics.Metric;
import com.codahale.metrics.Timer;
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonObject;
import com.google.common.collect.ImmutableMap;
......@@ -109,7 +110,7 @@ public class MetricsResourceTest extends ResourceTest {
String response = rs.path("metrics").get(String.class);
assertThat(response, containsString("{\"metrics\":["));
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
JsonArray jsonMetrics = result.get("metrics").asArray();
......
......@@ -20,6 +20,7 @@ import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Set;
import com.eclipsesource.json.Json;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeDiagnosingMatcher;
import org.junit.After;
......@@ -179,7 +180,7 @@ public class PathsResourceTest extends ResourceTest {
String response = rs.path(url).get(String.class);
assertThat(response, containsString("{\"paths\":["));
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......
......@@ -18,6 +18,7 @@ package org.onosproject.rest;
import java.util.HashMap;
import java.util.stream.IntStream;
import com.eclipsesource.json.Json;
import org.junit.Before;
import org.junit.Test;
import org.onlab.osgi.ServiceDirectory;
......@@ -126,7 +127,7 @@ public class StatisticsResourceTest extends ResourceTest {
.queryParam("port", "2")
.get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......@@ -148,7 +149,7 @@ public class StatisticsResourceTest extends ResourceTest {
final WebResource rs = resource();
final String response = rs.path("statistics/flows/link/").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......
......@@ -17,6 +17,7 @@ package org.onosproject.rest;
import java.util.Set;
import com.eclipsesource.json.Json;
import org.junit.Before;
import org.junit.Test;
import org.onlab.osgi.ServiceDirectory;
......@@ -167,7 +168,7 @@ public class TopologyResourceTest extends ResourceTest {
public void getTopology() {
WebResource rs = resource();
String response = rs.path("topology").get(String.class);
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(4));
......@@ -185,7 +186,7 @@ public class TopologyResourceTest extends ResourceTest {
public void getTopologyClusters() {
WebResource rs = resource();
String response = rs.path("topology/clusters").get(String.class);
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
......@@ -201,7 +202,7 @@ public class TopologyResourceTest extends ResourceTest {
public void getCluster() {
WebResource rs = resource();
String response = rs.path("topology/clusters/0").get(String.class);
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.get("id").asLong(), is(0L));
......@@ -219,7 +220,7 @@ public class TopologyResourceTest extends ResourceTest {
public void getClusterDevices() {
WebResource rs = resource();
String response = rs.path("topology/clusters/0/devices").get(String.class);
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
JsonArray devices = result.get("devices").asArray();
......@@ -236,7 +237,7 @@ public class TopologyResourceTest extends ResourceTest {
public void getClusterLinks() {
WebResource rs = resource();
String response = rs.path("topology/clusters/1/links").get(String.class);
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
JsonArray links = result.get("links").asArray();
......@@ -260,7 +261,7 @@ public class TopologyResourceTest extends ResourceTest {
public void getBroadcast() {
WebResource rs = resource();
String response = rs.path("topology/broadcast/dev1:1").get(String.class);
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.get("broadcast").asBoolean(), is(true));
......@@ -273,7 +274,7 @@ public class TopologyResourceTest extends ResourceTest {
public void getInfrastructure() {
WebResource rs = resource();
String response = rs.path("topology/infrastructure/dev2:1").get(String.class);
JsonObject result = JsonObject.readFrom(response);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.get("infrastructure").asBoolean(), is(true));
......
......@@ -19,6 +19,7 @@ import java.net.HttpURLConnection;
import java.util.HashSet;
import java.util.Set;
import com.eclipsesource.json.Json;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
......@@ -269,7 +270,7 @@ public class NetworkConfigWebResourceTest extends ResourceTest {
final WebResource rs = resource();
final String response = rs.path("network/configuration").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
Assert.assertThat(result, notNullValue());
Assert.assertThat(result.names(), hasSize(2));
......@@ -296,7 +297,7 @@ public class NetworkConfigWebResourceTest extends ResourceTest {
final WebResource rs = resource();
final String response = rs.path("network/configuration/devices").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
Assert.assertThat(result, notNullValue());
Assert.assertThat(result.names(), hasSize(1));
......@@ -322,7 +323,7 @@ public class NetworkConfigWebResourceTest extends ResourceTest {
rs.path("network/configuration/devices/device1")
.get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
Assert.assertThat(result, notNullValue());
Assert.assertThat(result.names(), hasSize(1));
......@@ -345,7 +346,7 @@ public class NetworkConfigWebResourceTest extends ResourceTest {
rs.path("network/configuration/devices/device1/basic")
.get(String.class);
final JsonObject result = JsonObject.readFrom(response);
final JsonObject result = Json.parse(response).asObject();
Assert.assertThat(result, notNullValue());
Assert.assertThat(result.names(), hasSize(2));
......