Example usage for org.springframework.boot.actuate.endpoint.http ActuatorMediaType V2_JSON

List of usage examples for org.springframework.boot.actuate.endpoint.http ActuatorMediaType V2_JSON

Introduction

In this page you can find the example usage for org.springframework.boot.actuate.endpoint.http ActuatorMediaType V2_JSON.

Prototype

String V2_JSON

To view the source code for org.springframework.boot.actuate.endpoint.http ActuatorMediaType V2_JSON.

Click Source Link

Document

Constant for the Actuator V2 media type.

Usage

From source file:de.codecentric.boot.admin.server.web.client.InstanceWebClientTest.java

@Test
public void should_add_default_accept_headers() {
    Instance instance = Instance.create(InstanceId.of("id"))
            .register(Registration.create("test", wireMock.url("/status")).build());
    wireMock.stubFor(get("/status").willReturn(ok()));

    Mono<ClientResponse> exchange = instanceWebClient.instance(instance).get().uri("health").exchange();

    StepVerifier.create(exchange).expectNextCount(1).verifyComplete();
    wireMock.verify(1,/*  w  ww  .  j ava2 s .  c o m*/
            getRequestedFor(urlEqualTo("/status"))
                    .withHeader(ACCEPT, containing(MediaType.APPLICATION_JSON_VALUE))
                    .withHeader(ACCEPT, containing(ActuatorMediaType.V1_JSON))
                    .withHeader(ACCEPT, containing(ActuatorMediaType.V2_JSON)));
}

From source file:de.codecentric.boot.admin.server.web.client.InstanceWebClientTest.java

@Test
public void should_convert_legacy_endpont() {
    Instance instance = Instance.create(InstanceId.of("id"))
            .register(Registration.create("test", wireMock.url("/status")).build());

    String responseBody = "{ \"status\" : \"UP\", \"foo\" : \"bar\" }";
    wireMock.stubFor(get("/status").willReturn(okForContentType(ActuatorMediaType.V1_JSON, responseBody)
            .withHeader(CONTENT_LENGTH, Integer.toString(responseBody.length()))
            .withHeader("X-Custom", "1234")));

    Mono<ClientResponse> exchange = instanceWebClient.instance(instance).get().uri("health").exchange();

    StepVerifier.create(exchange).assertNext(response -> {
        assertThat(response.headers().contentLength()).isEmpty();
        assertThat(response.headers().contentType())
                .contains(MediaType.parseMediaType(ActuatorMediaType.V2_JSON));
        assertThat(response.headers().header("X-Custom")).containsExactly("1234");
        assertThat(response.headers().header(CONTENT_TYPE)).containsExactly(ActuatorMediaType.V2_JSON);
        assertThat(response.headers().header(CONTENT_LENGTH)).isEmpty();
        assertThat(response.headers().asHttpHeaders().get("X-Custom")).containsExactly("1234");
        assertThat(response.headers().asHttpHeaders().get(CONTENT_TYPE))
                .containsExactly(ActuatorMediaType.V2_JSON);
        assertThat(response.headers().asHttpHeaders().get(CONTENT_LENGTH)).isNull();
        assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
    }).verifyComplete();/*ww  w . jav a 2s .  co m*/

    String expectedBody = "{\"status\":\"UP\",\"details\":{\"foo\":\"bar\"}}";
    StepVerifier.create(exchange.flatMap(r -> r.bodyToMono(String.class)))
            .assertNext(actualBody -> assertThat(actualBody).isEqualTo(expectedBody)).verifyComplete();

    wireMock.verify(2, getRequestedFor(urlEqualTo("/status")));
}