ServiceDiscoveryRestEndpoint { private void update(RoutingContext routingContext) { String uuid = routingContext.request().getParam("uuid"); JsonObject json = routingContext.getBodyAsJson(); Record record = new Record(json); if (!uuid.equals(record.getRegistration())) { routingContext.fail(400); return; } discovery.update(record, ar -> { if (ar.failed()) { routingContext.fail(ar.cause()); } else { routingContext.response().setStatusCode(200) .putHeader("Content-Type", "application/json") .end(ar.result().toJson().toString()); } }); } private  ServiceDiscoveryRestEndpoint(Router router, ServiceDiscovery discovery, String root); static ServiceDiscoveryRestEndpoint create(Router router, ServiceDiscovery discovery); static ServiceDiscoveryRestEndpoint create(Router router, ServiceDiscovery discovery, String root); static final String DEFAULT_ROOT; }
@Test public void testUpdate() throws UnsupportedEncodingException { HelloService svc = new HelloServiceImpl("stuff"); ProxyHelper.registerService(HelloService.class, vertx, svc, "address"); Record record = new Record() .setName("Hello") .setLocation(new JsonObject().put(Record.ENDPOINT, "address")); discovery.publish(record, (r) -> { }); await().until(() -> record.getRegistration() != null); Record retrieved = retrieve(record.getRegistration()); assertThat(retrieved.getStatus()).isEqualTo(Status.UP); retrieved.setStatus(Status.OUT_OF_SERVICE).getMetadata().put("foo", "bar"); Restafari.Response response = given().body(retrieved.toJson().toString()) .put("/discovery/" + record.getRegistration()); assertThat(response.getStatusCode()).isEqualTo(200); retrieved = new Record(new JsonObject(response.asString())); assertThat(retrieved.getStatus()).isEqualTo(Status.OUT_OF_SERVICE); assertThat(retrieved.getMetadata().getString("foo")).isEqualTo("bar"); response = get("/discovery/"); JsonArray services = new JsonArray(response.asString()); assertThat(services.size()).isEqualTo(0); services = given() .param("query", "{\"status\":\"*\"}") .get("/discovery") .asJsonArray(); assertThat(services.size()).isEqualTo(1); }