Fix ONOS-2090 - Improvements to Intent JSON
- Intents are now identified by the name portion of the appId rather than
the number
- removed the now useless "details" field which had a toString()
dump of the intent for when we didn't support all intent types
- Single Intent GET operations now accept a decimal or hexadecimal
value for the Intent key.
Change-Id: I39d635e68cccf2e59d0d11307b93329a2dc0bc96
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java
index 9c3e76a..8ef6fbd 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/IntentsWebResource.java
@@ -91,14 +91,14 @@
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{appId}/{key}")
- public Response getIntentById(@PathParam("appId") Short appId,
+ public Response getIntentById(@PathParam("appId") String appId,
@PathParam("key") String key) {
final ApplicationId app = get(CoreService.class).getAppId(appId);
Intent intent = get(IntentService.class).getIntent(Key.of(key, app));
if (intent == null) {
- intent = get(IntentService.class)
- .getIntent(Key.of(Long.parseLong(key), app));
+ long numericalKey = Long.decode(key);
+ intent = get(IntentService.class).getIntent(Key.of(numericalKey, app));
}
nullIsNotFound(intent, INTENT_NOT_FOUND);
@@ -140,7 +140,7 @@
*/
@DELETE
@Path("{appId}/{key}")
- public void deleteIntentById(@PathParam("appId") Short appId,
+ public void deleteIntentById(@PathParam("appId") String appId,
@PathParam("key") String keyString) {
final ApplicationId app = get(CoreService.class).getAppId(appId);
diff --git a/web/api/src/test/java/org/onosproject/rest/IntentsResourceTest.java b/web/api/src/test/java/org/onosproject/rest/IntentsResourceTest.java
index 6572b68..ee39094 100644
--- a/web/api/src/test/java/org/onosproject/rest/IntentsResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/IntentsResourceTest.java
@@ -110,9 +110,11 @@
}
// check application id
+
final String jsonAppId = jsonIntent.get("appId").asString();
- if (!jsonAppId.equals(intent.appId().toString())) {
- reason = "appId " + intent.appId().toString();
+ final String appId = intent.appId().name();
+ if (!jsonAppId.equals(appId)) {
+ reason = "appId was " + jsonAppId;
return false;
}
@@ -123,13 +125,6 @@
return false;
}
- // check details field
- final String jsonDetails = jsonIntent.get("details").asString();
- if (!jsonDetails.equals(intent.toString())) {
- reason = "details " + intent.toString();
- return false;
- }
-
// check state field
final String jsonState = jsonIntent.get("state").asString();
if (!jsonState.equals("INSTALLED")) {
@@ -196,7 +191,7 @@
@Override
public boolean matchesSafely(JsonArray json) {
boolean intentFound = false;
- final int expectedAttributes = 6;
+ final int expectedAttributes = 5;
for (int jsonIntentIndex = 0; jsonIntentIndex < json.size();
jsonIntentIndex++) {
@@ -336,11 +331,12 @@
.andReturn(intent)
.anyTimes();
replay(mockIntentService);
- expect(mockCoreService.getAppId(APP_ID.id()))
+ expect(mockCoreService.getAppId(APP_ID.name()))
.andReturn(APP_ID).anyTimes();
replay(mockCoreService);
final WebResource rs = resource();
- final String response = rs.path("intents/1/0").get(String.class);
+ final String response = rs.path("intents/" + APP_ID.name()
+ + "/0").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
assertThat(result, matchesIntent(intent));
}
@@ -371,8 +367,9 @@
*/
@Test
public void testPost() {
- expect(mockCoreService.getAppId((short) 2))
- .andReturn(new DefaultApplicationId(2, "app"));
+ ApplicationId testId = new DefaultApplicationId(2, "myApp");
+ expect(mockCoreService.getAppId("myApp"))
+ .andReturn(testId);
replay(mockCoreService);
mockIntentService.submit(anyObject());
diff --git a/web/api/src/test/resources/org/onosproject/rest/post-intent.json b/web/api/src/test/resources/org/onosproject/rest/post-intent.json
index 4c6c4b8..b01ef87 100644
--- a/web/api/src/test/resources/org/onosproject/rest/post-intent.json
+++ b/web/api/src/test/resources/org/onosproject/rest/post-intent.json
@@ -1,6 +1,6 @@
{
"type": "PointToPointIntent",
- "appId": 2,
+ "appId": "myApp",
"selector": {
"criteria": [
{