ZipkinHealthController { static String writeJson(String overallStatus, List<ComponentHealth> healths) throws IOException { StringWriter writer = new StringWriter(); try (JsonGenerator generator = JsonUtil.createGenerator(writer)) { generator.writeStartObject(); generator.writeStringField("status", overallStatus); generator.writeObjectFieldStart("zipkin"); generator.writeStringField("status", overallStatus); generator.writeObjectFieldStart("details"); for (ComponentHealth health : healths) { generator.writeObjectFieldStart(health.name); generator.writeStringField("status", health.status); if (health.status.equals(STATUS_DOWN)) { generator.writeObjectFieldStart("details"); generator.writeStringField("error", health.error); generator.writeEndObject(); } generator.writeEndObject(); } generator.writeEndObject(); generator.writeEndObject(); generator.writeEndObject(); } return writer.toString(); } ZipkinHealthController(List<Component> components); @Get("/actuator/health") CompletableFuture<HttpResponse> getActuatorHealth(ServiceRequestContext ctx); @Get("/health") CompletableFuture<HttpResponse> getHealth(ServiceRequestContext ctx);  }
@Test public void writeJson_mappedByName() throws Exception { List<ComponentHealth> healths = asList( new ComponentHealth("foo", STATUS_UP, null), new ComponentHealth("bar", STATUS_DOWN, "java.io.IOException: socket disconnect") ); assertThat(ZipkinHealthController.writeJson(STATUS_DOWN, healths)).isEqualTo("" + "{\n" + " \"status\" : \"DOWN\",\n" + " \"zipkin\" : {\n" + " \"status\" : \"DOWN\",\n" + " \"details\" : {\n" + " \"foo\" : {\n" + " \"status\" : \"UP\"\n" + " },\n" + " \"bar\" : {\n" + " \"status\" : \"DOWN\",\n" + " \"details\" : {\n" + " \"error\" : \"java.io.IOException: socket disconnect\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}" ); }