Ray Milkey
Committed by Gerrit Code Review

JSON for flows should return the app name, not the app ID

Change-Id: I12d217b07bffb59615dfeefd40242f01669989c2
......@@ -17,6 +17,7 @@ package org.onosproject.codec.impl;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.core.CoreService;
import org.onosproject.net.flow.FlowEntry;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
......@@ -34,9 +35,11 @@ public final class FlowEntryCodec extends JsonCodec<FlowEntry> {
public ObjectNode encode(FlowEntry flowEntry, CodecContext context) {
checkNotNull(flowEntry, "Flow entry cannot be null");
CoreService service = context.getService(CoreService.class);
final ObjectNode result = context.mapper().createObjectNode()
.put("id", Long.toString(flowEntry.id().value()))
.put("appId", flowEntry.appId())
.put("appId", service.getAppId(flowEntry.appId()).name())
.put("groupId", flowEntry.groupId().id())
.put("priority", flowEntry.priority())
.put("timeout", flowEntry.timeout())
......
......@@ -299,10 +299,12 @@ public class FlowsResourceTest extends ResourceTest {
*/
public static class FlowJsonMatcher extends TypeSafeMatcher<JsonObject> {
private final FlowEntry flow;
private final String expectedAppId;
private String reason = "";
public FlowJsonMatcher(FlowEntry flowValue) {
public FlowJsonMatcher(FlowEntry flowValue, String expectedAppIdValue) {
flow = flowValue;
expectedAppId = expectedAppIdValue;
}
@Override
......@@ -316,8 +318,8 @@ public class FlowsResourceTest extends ResourceTest {
}
// check application id
final int jsonAppId = jsonFlow.get("appId").asInt();
if (jsonAppId != flow.appId()) {
final String jsonAppId = jsonFlow.get("appId").asString();
if (!jsonAppId.equals(expectedAppId)) {
reason = "appId " + Short.toString(flow.appId());
return false;
}
......@@ -399,8 +401,8 @@ public class FlowsResourceTest extends ResourceTest {
* @param flow flow object we are looking for
* @return matcher
*/
private static FlowJsonMatcher matchesFlow(FlowEntry flow) {
return new FlowJsonMatcher(flow);
private static FlowJsonMatcher matchesFlow(FlowEntry flow, String expectedAppName) {
return new FlowJsonMatcher(flow, expectedAppName);
}
/**
......@@ -430,7 +432,7 @@ public class FlowsResourceTest extends ResourceTest {
flowFound = true;
// We found the correct flow, check attribute values
assertThat(jsonFlow, matchesFlow(flow));
assertThat(jsonFlow, matchesFlow(flow, APP_ID.name()));
}
}
if (!flowFound) {
......