Committed by
Gerrit Code Review
JSON for flows should return the app name, not the app ID
Change-Id: I12d217b07bffb59615dfeefd40242f01669989c2
Showing
2 changed files
with
12 additions
and
7 deletions
... | @@ -17,6 +17,7 @@ package org.onosproject.codec.impl; | ... | @@ -17,6 +17,7 @@ package org.onosproject.codec.impl; |
17 | 17 | ||
18 | import org.onosproject.codec.CodecContext; | 18 | import org.onosproject.codec.CodecContext; |
19 | import org.onosproject.codec.JsonCodec; | 19 | import org.onosproject.codec.JsonCodec; |
20 | +import org.onosproject.core.CoreService; | ||
20 | import org.onosproject.net.flow.FlowEntry; | 21 | import org.onosproject.net.flow.FlowEntry; |
21 | import org.onosproject.net.flow.TrafficSelector; | 22 | import org.onosproject.net.flow.TrafficSelector; |
22 | import org.onosproject.net.flow.TrafficTreatment; | 23 | import org.onosproject.net.flow.TrafficTreatment; |
... | @@ -34,9 +35,11 @@ public final class FlowEntryCodec extends JsonCodec<FlowEntry> { | ... | @@ -34,9 +35,11 @@ public final class FlowEntryCodec extends JsonCodec<FlowEntry> { |
34 | public ObjectNode encode(FlowEntry flowEntry, CodecContext context) { | 35 | public ObjectNode encode(FlowEntry flowEntry, CodecContext context) { |
35 | checkNotNull(flowEntry, "Flow entry cannot be null"); | 36 | checkNotNull(flowEntry, "Flow entry cannot be null"); |
36 | 37 | ||
38 | + CoreService service = context.getService(CoreService.class); | ||
39 | + | ||
37 | final ObjectNode result = context.mapper().createObjectNode() | 40 | final ObjectNode result = context.mapper().createObjectNode() |
38 | .put("id", Long.toString(flowEntry.id().value())) | 41 | .put("id", Long.toString(flowEntry.id().value())) |
39 | - .put("appId", flowEntry.appId()) | 42 | + .put("appId", service.getAppId(flowEntry.appId()).name()) |
40 | .put("groupId", flowEntry.groupId().id()) | 43 | .put("groupId", flowEntry.groupId().id()) |
41 | .put("priority", flowEntry.priority()) | 44 | .put("priority", flowEntry.priority()) |
42 | .put("timeout", flowEntry.timeout()) | 45 | .put("timeout", flowEntry.timeout()) | ... | ... |
... | @@ -299,10 +299,12 @@ public class FlowsResourceTest extends ResourceTest { | ... | @@ -299,10 +299,12 @@ public class FlowsResourceTest extends ResourceTest { |
299 | */ | 299 | */ |
300 | public static class FlowJsonMatcher extends TypeSafeMatcher<JsonObject> { | 300 | public static class FlowJsonMatcher extends TypeSafeMatcher<JsonObject> { |
301 | private final FlowEntry flow; | 301 | private final FlowEntry flow; |
302 | + private final String expectedAppId; | ||
302 | private String reason = ""; | 303 | private String reason = ""; |
303 | 304 | ||
304 | - public FlowJsonMatcher(FlowEntry flowValue) { | 305 | + public FlowJsonMatcher(FlowEntry flowValue, String expectedAppIdValue) { |
305 | flow = flowValue; | 306 | flow = flowValue; |
307 | + expectedAppId = expectedAppIdValue; | ||
306 | } | 308 | } |
307 | 309 | ||
308 | @Override | 310 | @Override |
... | @@ -316,8 +318,8 @@ public class FlowsResourceTest extends ResourceTest { | ... | @@ -316,8 +318,8 @@ public class FlowsResourceTest extends ResourceTest { |
316 | } | 318 | } |
317 | 319 | ||
318 | // check application id | 320 | // check application id |
319 | - final int jsonAppId = jsonFlow.get("appId").asInt(); | 321 | + final String jsonAppId = jsonFlow.get("appId").asString(); |
320 | - if (jsonAppId != flow.appId()) { | 322 | + if (!jsonAppId.equals(expectedAppId)) { |
321 | reason = "appId " + Short.toString(flow.appId()); | 323 | reason = "appId " + Short.toString(flow.appId()); |
322 | return false; | 324 | return false; |
323 | } | 325 | } |
... | @@ -399,8 +401,8 @@ public class FlowsResourceTest extends ResourceTest { | ... | @@ -399,8 +401,8 @@ public class FlowsResourceTest extends ResourceTest { |
399 | * @param flow flow object we are looking for | 401 | * @param flow flow object we are looking for |
400 | * @return matcher | 402 | * @return matcher |
401 | */ | 403 | */ |
402 | - private static FlowJsonMatcher matchesFlow(FlowEntry flow) { | 404 | + private static FlowJsonMatcher matchesFlow(FlowEntry flow, String expectedAppName) { |
403 | - return new FlowJsonMatcher(flow); | 405 | + return new FlowJsonMatcher(flow, expectedAppName); |
404 | } | 406 | } |
405 | 407 | ||
406 | /** | 408 | /** |
... | @@ -430,7 +432,7 @@ public class FlowsResourceTest extends ResourceTest { | ... | @@ -430,7 +432,7 @@ public class FlowsResourceTest extends ResourceTest { |
430 | flowFound = true; | 432 | flowFound = true; |
431 | 433 | ||
432 | // We found the correct flow, check attribute values | 434 | // We found the correct flow, check attribute values |
433 | - assertThat(jsonFlow, matchesFlow(flow)); | 435 | + assertThat(jsonFlow, matchesFlow(flow, APP_ID.name())); |
434 | } | 436 | } |
435 | } | 437 | } |
436 | if (!flowFound) { | 438 | if (!flowFound) { | ... | ... |
-
Please register or login to post a comment