@Test public void pointToPointIntent() { ConnectPoint ingress = NetTestTools.connectPoint("ingress", 1); ConnectPoint egress = NetTestTools.connectPoint("egress", 2); final PointToPointIntent intent = PointToPointIntent.builder() .appId(appId) .selector(emptySelector) .treatment(emptyTreatment) .ingressPoint(ingress) .egressPoint(egress).build(); final JsonCodec<PointToPointIntent> intentCodec = context.codec(PointToPointIntent.class); assertThat(intentCodec, notNullValue()); final ObjectNode intentJson = intentCodec.encode(intent, context); assertThat(intentJson, matchesIntent(intent)); }
@Override public ObjectNode encode(Intent intent, CodecContext context) { checkNotNull(intent, "Intent cannot be null"); final ObjectNode result = context.mapper().createObjectNode() .put(TYPE, intent.getClass().getSimpleName()) .put(ID, intent.id().toString()) .put(APP_ID, UrlEscapers.urlPathSegmentEscaper() .escape(intent.appId().name())); final ArrayNode jsonResources = result.putArray(RESOURCES); for (final NetworkResource resource : intent.resources()) { jsonResources.add(resource.toString()); } IntentService service = context.getService(IntentService.class); IntentState state = service.getIntentState(intent.key()); if (state != null) { result.put(STATE, state.toString()); } return result; }
IntentCodec extends JsonCodec<Intent> { @Override public ObjectNode encode(Intent intent, CodecContext context) { checkNotNull(intent, "Intent cannot be null"); final ObjectNode result = context.mapper().createObjectNode() .put(TYPE, intent.getClass().getSimpleName()) .put(ID, intent.id().toString()) .put(APP_ID, UrlEscapers.urlPathSegmentEscaper() .escape(intent.appId().name())); final ArrayNode jsonResources = result.putArray(RESOURCES); for (final NetworkResource resource : intent.resources()) { jsonResources.add(resource.toString()); } IntentService service = context.getService(IntentService.class); IntentState state = service.getIntentState(intent.key()); if (state != null) { result.put(STATE, state.toString()); } return result; } }
IntentCodec extends JsonCodec<Intent> { @Override public ObjectNode encode(Intent intent, CodecContext context) { checkNotNull(intent, "Intent cannot be null"); final ObjectNode result = context.mapper().createObjectNode() .put(TYPE, intent.getClass().getSimpleName()) .put(ID, intent.id().toString()) .put(APP_ID, UrlEscapers.urlPathSegmentEscaper() .escape(intent.appId().name())); final ArrayNode jsonResources = result.putArray(RESOURCES); for (final NetworkResource resource : intent.resources()) { jsonResources.add(resource.toString()); } IntentService service = context.getService(IntentService.class); IntentState state = service.getIntentState(intent.key()); if (state != null) { result.put(STATE, state.toString()); } return result; }  }
IntentCodec extends JsonCodec<Intent> { @Override public ObjectNode encode(Intent intent, CodecContext context) { checkNotNull(intent, "Intent cannot be null"); final ObjectNode result = context.mapper().createObjectNode() .put(TYPE, intent.getClass().getSimpleName()) .put(ID, intent.id().toString()) .put(APP_ID, UrlEscapers.urlPathSegmentEscaper() .escape(intent.appId().name())); final ArrayNode jsonResources = result.putArray(RESOURCES); for (final NetworkResource resource : intent.resources()) { jsonResources.add(resource.toString()); } IntentService service = context.getService(IntentService.class); IntentState state = service.getIntentState(intent.key()); if (state != null) { result.put(STATE, state.toString()); } return result; }  @Override ObjectNode encode(Intent intent, CodecContext context); @Override Intent decode(ObjectNode json, CodecContext context); static void intentAttributes(ObjectNode json, CodecContext context,
                                    Intent.Builder builder); }
IntentCodec extends JsonCodec<Intent> { @Override public ObjectNode encode(Intent intent, CodecContext context) { checkNotNull(intent, "Intent cannot be null"); final ObjectNode result = context.mapper().createObjectNode() .put(TYPE, intent.getClass().getSimpleName()) .put(ID, intent.id().toString()) .put(APP_ID, UrlEscapers.urlPathSegmentEscaper() .escape(intent.appId().name())); final ArrayNode jsonResources = result.putArray(RESOURCES); for (final NetworkResource resource : intent.resources()) { jsonResources.add(resource.toString()); } IntentService service = context.getService(IntentService.class); IntentState state = service.getIntentState(intent.key()); if (state != null) { result.put(STATE, state.toString()); } return result; }  @Override ObjectNode encode(Intent intent, CodecContext context); @Override Intent decode(ObjectNode json, CodecContext context); static void intentAttributes(ObjectNode json, CodecContext context,
                                    Intent.Builder builder);  }