org.springframework.boot.actuate.endpoint.http.ActuatorMediaType Java Examples
The following examples show how to use
org.springframework.boot.actuate.endpoint.http.ActuatorMediaType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoggersHtmlEndpoint.java From edison-microservice with Apache License 2.0 | 6 votes |
@RequestMapping( value = "${edison.application.management.base-path:/internal}/loggers/{name:.*}", consumes = { ActuatorMediaType.V2_JSON, APPLICATION_JSON_VALUE}, produces = { ActuatorMediaType.V2_JSON, APPLICATION_JSON_VALUE}, method = POST) @ResponseBody public Object post(@PathVariable String name, @RequestBody Map<String, String> configuration) { final String level = configuration.get("configuredLevel"); final LogLevel logLevel = level == null ? null : LogLevel.valueOf(level.toUpperCase()); loggersEndpoint.configureLogLevel(name, logLevel); return HttpEntity.EMPTY; }
Example #2
Source File: QueryIndexEndpointStrategyTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test public void should_retry() { // given Instance instance = Instance.create(InstanceId.of("id")).register(Registration .create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build()); String body = "{\"_links\":{\"metrics-requiredMetricName\":{\"templated\":true,\"href\":\"/mgmt/metrics/{requiredMetricName}\"},\"self\":{\"templated\":false,\"href\":\"/mgmt\"},\"metrics\":{\"templated\":false,\"href\":\"/mgmt/stats\"},\"info\":{\"templated\":false,\"href\":\"/mgmt/info\"}}}"; this.wireMock.stubFor(get("/mgmt").inScenario("retry").whenScenarioStateIs(STARTED) .willReturn(aResponse().withFault(Fault.CONNECTION_RESET_BY_PEER)).willSetStateTo("recovered")); this.wireMock.stubFor(get("/mgmt").inScenario("retry").whenScenarioStateIs("recovered") .willReturn(ok(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON))); QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient); // when StepVerifier.create(strategy.detectEndpoints(instance)) // then .expectNext(Endpoints.single("metrics", "/mgmt/stats").withEndpoint("info", "/mgmt/info"))// .verifyComplete(); }
Example #3
Source File: QueryIndexEndpointStrategyTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test public void should_return_empty_on_empty_endpoints() { // given Instance instance = Instance.create(InstanceId.of("id")).register(Registration .create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build()); String body = "{\"_links\":{}}"; this.wireMock .stubFor(get("/mgmt").willReturn(okJson(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON))); QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient); // when StepVerifier.create(strategy.detectEndpoints(instance)) // then .verifyComplete(); }
Example #4
Source File: QueryIndexEndpointStrategyTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test public void should_return_endpoints_with_aligned_scheme() { // given Instance instance = Instance.create(InstanceId.of("id")).register(Registration .create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build()); String host = "http://localhost:" + this.wireMock.httpsPort(); String body = "{\"_links\":{\"metrics-requiredMetricName\":{\"templated\":true,\"href\":\"" + host + "/mgmt/metrics/{requiredMetricName}\"},\"self\":{\"templated\":false,\"href\":\"" + host + "/mgmt\"},\"metrics\":{\"templated\":false,\"href\":\"" + host + "/mgmt/stats\"},\"info\":{\"templated\":false,\"href\":\"" + host + "/mgmt/info\"}}}"; this.wireMock.stubFor(get("/mgmt").willReturn(ok(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON))); QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient); // when String secureHost = "https://localhost:" + this.wireMock.httpsPort(); StepVerifier.create(strategy.detectEndpoints(instance)) // then .expectNext(Endpoints.single("metrics", secureHost + "/mgmt/stats").withEndpoint("info", secureHost + "/mgmt/info"))// .verifyComplete(); }
Example #5
Source File: QueryIndexEndpointStrategyTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test public void should_return_endpoints() { // given Instance instance = Instance.create(InstanceId.of("id")).register(Registration .create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build()); String host = "https://localhost:" + this.wireMock.httpsPort(); String body = "{\"_links\":{\"metrics-requiredMetricName\":{\"templated\":true,\"href\":\"" + host + "/mgmt/metrics/{requiredMetricName}\"},\"self\":{\"templated\":false,\"href\":\"" + host + "/mgmt\"},\"metrics\":{\"templated\":false,\"href\":\"" + host + "/mgmt/stats\"},\"info\":{\"templated\":false,\"href\":\"" + host + "/mgmt/info\"}}}"; this.wireMock.stubFor(get("/mgmt").willReturn(ok(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON))); QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient); // when StepVerifier.create(strategy.detectEndpoints(instance)) // then .expectNext(Endpoints.single("metrics", host + "/mgmt/stats").withEndpoint("info", host + "/mgmt/info"))// .verifyComplete(); }
Example #6
Source File: InstanceExchangeFilterFunctionsTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test void should_not_convert_v2_actuator() { InstanceExchangeFilterFunction filter = InstanceExchangeFilterFunctions.convertLegacyEndpoints( singletonList(new LegacyEndpointConverter("test", (from) -> Flux.just(this.converted)) { })); ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("/test")) .attribute(ATTRIBUTE_ENDPOINT, "test").build(); ClientResponse response = ClientResponse.create(HttpStatus.OK) .header(CONTENT_TYPE, ActuatorMediaType.V2_JSON) .header(CONTENT_LENGTH, Integer.toString(this.original.readableByteCount())) .body(Flux.just(this.original)).build(); Mono<ClientResponse> convertedResponse = filter.filter(INSTANCE, request, (r) -> Mono.just(response)); StepVerifier.create(convertedResponse).assertNext((r) -> { assertThat(r.headers().contentType()).hasValue(MediaType.valueOf(ActuatorMediaType.V2_JSON)); assertThat(r.headers().contentLength()).hasValue(this.original.readableByteCount()); StepVerifier.create(r.body(BodyExtractors.toDataBuffers())).expectNext(this.original).verifyComplete(); }).verifyComplete(); }
Example #7
Source File: InstanceExchangeFilterFunctionsTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test void should_convert_json() { ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("/test")) .attribute(ATTRIBUTE_ENDPOINT, "test").build(); ClientResponse legacyResponse = ClientResponse.create(HttpStatus.OK) .header(CONTENT_TYPE, APPLICATION_JSON_VALUE) .header(CONTENT_LENGTH, Integer.toString(this.original.readableByteCount())) .body(Flux.just(this.original)).build(); Mono<ClientResponse> response = this.filter.filter(INSTANCE, request, (r) -> Mono.just(legacyResponse)); StepVerifier.create(response).assertNext((r) -> { assertThat(r.headers().contentType()).hasValue(MediaType.valueOf(ActuatorMediaType.V2_JSON)); assertThat(r.headers().contentLength()).isEmpty(); StepVerifier.create(r.body(BodyExtractors.toDataBuffers())).expectNext(this.converted).verifyComplete(); }).verifyComplete(); }
Example #8
Source File: InstanceExchangeFilterFunctionsTest.java From spring-boot-admin with Apache License 2.0 | 6 votes |
@Test void should_convert_v1_actuator() { ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("/test")) .attribute(ATTRIBUTE_ENDPOINT, "test").build(); @SuppressWarnings("deprecation") ClientResponse legacyResponse = ClientResponse.create(HttpStatus.OK) .header(CONTENT_TYPE, ACTUATOR_V1_MEDIATYPE.toString()) .header(CONTENT_LENGTH, Integer.toString(this.original.readableByteCount())) .body(Flux.just(this.original)).build(); Mono<ClientResponse> response = this.filter.filter(INSTANCE, request, (r) -> Mono.just(legacyResponse)); StepVerifier.create(response).assertNext((r) -> { assertThat(r.headers().contentType()).hasValue(MediaType.valueOf(ActuatorMediaType.V2_JSON)); assertThat(r.headers().contentLength()).isEmpty(); StepVerifier.create(r.body(BodyExtractors.toDataBuffers())).expectNext(this.converted).verifyComplete(); }).verifyComplete(); }
Example #9
Source File: InstanceExchangeFilterFunctionsTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void should_convert_v1_actuator() { ExchangeFilterFunction filter = InstanceExchangeFilterFunctions.convertLegacyEndpoint(new TestLegacyEndpointConverter()); ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("/test")) .attribute(ATTRIBUTE_ENDPOINT, "test") .build(); ClientResponse response = ClientResponse.create(HttpStatus.OK) .header(CONTENT_TYPE, ActuatorMediaType.V1_JSON) .body(Flux.just(ORIGINAL)) .build(); Mono<ClientResponse> convertedResponse = filter.filter(request, r -> Mono.just(response)); StepVerifier.create(convertedResponse) .assertNext(r -> StepVerifier.create(r.body(BodyExtractors.toDataBuffers())) .expectNext(CONVERTED) .verifyComplete()) .verifyComplete(); }
Example #10
Source File: QueryIndexEndpointStrategyTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void should_return_empty_on_empty_endpoints() { //given Instance instance = Instance.create(InstanceId.of("id")) .register(Registration.create("test", wireMock.url("/mgmt/health")) .managementUrl(wireMock.url("/mgmt")) .build()); String body = "{\"_links\":{}}"; wireMock.stubFor(get("/mgmt").willReturn(okJson(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON) .withHeader("Content-Length", Integer.toString(body.length()) ))); QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(instanceWebClient); //when StepVerifier.create(strategy.detectEndpoints(instance)) //then .verifyComplete(); }
Example #11
Source File: QueryIndexEndpointStrategyTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void should_return_endpoints() { //given Instance instance = Instance.create(InstanceId.of("id")) .register(Registration.create("test", wireMock.url("/mgmt/health")) .managementUrl(wireMock.url("/mgmt")) .build()); String body = "{\"_links\":{\"metrics-requiredMetricName\":{\"templated\":true,\"href\":\"\\/mgmt\\/metrics\\/{requiredMetricName}\"},\"self\":{\"templated\":false,\"href\":\"\\/mgmt\"},\"metrics\":{\"templated\":false,\"href\":\"\\/mgmt\\/stats\"},\"info\":{\"templated\":false,\"href\":\"\\/mgmt\\/info\"}}}"; wireMock.stubFor(get("/mgmt").willReturn(ok(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON) .withHeader("Content-Length", Integer.toString(body.length()) ))); QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(instanceWebClient); //when StepVerifier.create(strategy.detectEndpoints(instance)) //then .expectNext(Endpoints.single("metrics", "/mgmt/stats").withEndpoint("info", "/mgmt/info"))// .verifyComplete(); }
Example #12
Source File: InstanceExchangeFilterFunctionsTest.java From Moss with Apache License 2.0 | 6 votes |
@Test public void should_not_convert_v2_actuator() { ExchangeFilterFunction filter = InstanceExchangeFilterFunctions.convertLegacyEndpoint(new TestLegacyEndpointConverter()); ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("/test")) .attribute(ATTRIBUTE_ENDPOINT, "test") .build(); ClientResponse response = ClientResponse.create(HttpStatus.OK) .header(CONTENT_TYPE, ActuatorMediaType.V2_JSON) .body(Flux.just(ORIGINAL)) .build(); Mono<ClientResponse> convertedResponse = filter.filter(request, r -> Mono.just(response)); StepVerifier.create(convertedResponse) .assertNext(r -> StepVerifier.create(r.body(BodyExtractors.toDataBuffers())) .expectNext(ORIGINAL) .verifyComplete()) .verifyComplete(); }
Example #13
Source File: LoggersHtmlEndpoint.java From edison-microservice with Apache License 2.0 | 5 votes |
@RequestMapping( value = "${edison.application.management.base-path:/internal}/loggers", produces = { ActuatorMediaType.V2_JSON, APPLICATION_JSON_VALUE}, method = GET) @ResponseBody public Object get() { final Map<String, Object> levels = loggersEndpoint.loggers(); return (levels == null ? notFound().build() : levels); }
Example #14
Source File: LoggersHtmlEndpoint.java From edison-microservice with Apache License 2.0 | 5 votes |
@RequestMapping( value = "${edison.application.management.base-path:/internal}/loggers/{name:.*}", produces = { ActuatorMediaType.V2_JSON, APPLICATION_JSON_VALUE}, method = GET) @ResponseBody public Object get(@PathVariable String name) { final LoggerLevels levels = loggersEndpoint.loggerLevels(name); return (levels == null ? notFound().build() : levels); }
Example #15
Source File: QueryIndexEndpointStrategyTest.java From Moss with Apache License 2.0 | 5 votes |
@Test public void should_retry() { //given Instance instance = Instance.create(InstanceId.of("id")) .register(Registration.create("test", wireMock.url("/mgmt/health")) .managementUrl(wireMock.url("/mgmt")) .build()); String body = "{\"_links\":{\"metrics-requiredMetricName\":{\"templated\":true,\"href\":\"\\/mgmt\\/metrics\\/{requiredMetricName}\"},\"self\":{\"templated\":false,\"href\":\"\\/mgmt\"},\"metrics\":{\"templated\":false,\"href\":\"\\/mgmt\\/stats\"},\"info\":{\"templated\":false,\"href\":\"\\/mgmt\\/info\"}}}"; wireMock.stubFor(get("/mgmt").inScenario("retry") .whenScenarioStateIs(STARTED) .willReturn(aResponse().withFixedDelay(5000)) .willSetStateTo("recovered")); wireMock.stubFor(get("/mgmt").inScenario("retry") .whenScenarioStateIs("recovered") .willReturn(ok(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON) .withHeader("Content-Length", Integer.toString(body.length()) ))); QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(instanceWebClient); //when StepVerifier.create(strategy.detectEndpoints(instance)) //then .expectNext(Endpoints.single("metrics", "/mgmt/stats").withEndpoint("info", "/mgmt/info"))// .verifyComplete(); }
Example #16
Source File: ActuatorTest.java From syncope with Apache License 2.0 | 5 votes |
@Test public void health() throws SSLException { webClient.get().uri("/actuator/health"). exchange().expectStatus().isUnauthorized(); webClient.get().uri("/actuator/health"). header(HttpHeaders.AUTHORIZATION, basicAuthHeader()). exchange(). expectStatus().isOk(). expectHeader().valueEquals(HttpHeaders.CONTENT_TYPE, ActuatorMediaType.V3_JSON); }
Example #17
Source File: StatusUpdaterTest.java From Moss with Apache License 2.0 | 5 votes |
@Test public void should_change_status_to_down() { String body = "{ \"status\" : \"UP\", \"details\" : { \"foo\" : \"bar\" } }"; wireMock.stubFor(get("/health").willReturn(okForContentType(ActuatorMediaType.V2_JSON, body).withHeader("Content-Length", Integer.toString(body.length()) ))); StepVerifier.create(eventStore) .expectSubscription() .then(() -> StepVerifier.create(updater.updateStatus(instance.getId())).verifyComplete()) .assertNext(event -> { assertThat(event).isInstanceOf(InstanceStatusChangedEvent.class); assertThat(event.getInstance()).isEqualTo(instance.getId()); InstanceStatusChangedEvent statusChangedEvent = (InstanceStatusChangedEvent) event; assertThat(statusChangedEvent.getStatusInfo().getStatus()).isEqualTo("UP"); assertThat(statusChangedEvent.getStatusInfo().getDetails()).isEqualTo(singletonMap("foo", "bar" )); }) .thenCancel() .verify(); StepVerifier.create(repository.find(instance.getId())) .assertNext(app -> assertThat(app.getStatusInfo().getStatus()).isEqualTo("UP")) .verifyComplete(); StepVerifier.create(repository.computeIfPresent(instance.getId(), (key, instance) -> Mono.just(instance.deregister()) )) .then(() -> StepVerifier.create(updater.updateStatus(instance.getId())).verifyComplete()) .thenCancel() .verify(); StepVerifier.create(repository.find(instance.getId())) .assertNext(app -> assertThat(app.getStatusInfo().getStatus()).isEqualTo("UNKNOWN")) .verifyComplete(); }
Example #18
Source File: AbstractInstancesProxyControllerIntegrationTest.java From spring-boot-admin with Apache License 2.0 | 5 votes |
private void stubForInstance(String managementPath) { String managementUrl = this.wireMock.url(managementPath); //@formatter:off String actuatorIndex = "{ \"_links\": { " + "\"env\": { \"href\": \"" + managementUrl + "/env\", \"templated\": false }," + "\"test\": { \"href\": \"" + managementUrl + "/test\", \"templated\": false }," + "\"post\": { \"href\": \"" + managementUrl + "/post\", \"templated\": false }," + "\"delete\": { \"href\": \"" + managementUrl + "/delete\", \"templated\": false }," + "\"invalid\": { \"href\": \"" + managementUrl + "/invalid\", \"templated\": false }," + "\"timeout\": { \"href\": \"" + managementUrl + "/timeout\", \"templated\": false }" + " } }"; //@formatter:on this.wireMock.stubFor(get(urlEqualTo(managementPath + "/health")) .willReturn(ok("{ \"status\" : \"UP\" }").withHeader(CONTENT_TYPE, ActuatorMediaType.V2_JSON))); this.wireMock.stubFor(get(urlEqualTo(managementPath + "/info")) .willReturn(ok("{ }").withHeader(CONTENT_TYPE, ACTUATOR_CONTENT_TYPE))); this.wireMock.stubFor(options(urlEqualTo(managementPath + "/env")).willReturn( ok().withHeader(ALLOW, HttpMethod.HEAD.name(), HttpMethod.GET.name(), HttpMethod.OPTIONS.name()))); this.wireMock.stubFor(get(urlEqualTo(managementPath + "")) .willReturn(ok(actuatorIndex).withHeader(CONTENT_TYPE, ACTUATOR_CONTENT_TYPE))); this.wireMock.stubFor( get(urlEqualTo(managementPath + "/invalid")).willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE))); this.wireMock.stubFor(get(urlEqualTo(managementPath + "/timeout")).willReturn(ok().withFixedDelay(10000))); this.wireMock.stubFor(get(urlEqualTo(managementPath + "/test")) .willReturn(ok("{ \"foo\" : \"bar\" }").withHeader(CONTENT_TYPE, ACTUATOR_CONTENT_TYPE))); this.wireMock.stubFor(get(urlEqualTo(managementPath + "/test/has%20spaces")) .willReturn(ok("{ \"foo\" : \"bar-with-spaces\" }").withHeader(CONTENT_TYPE, ACTUATOR_CONTENT_TYPE))); this.wireMock.stubFor(post(urlEqualTo(managementPath + "/post")).willReturn(ok())); this.wireMock.stubFor(delete(urlEqualTo(managementPath + "/delete")).willReturn(serverError() .withBody("{\"error\": \"You're doing it wrong!\"}").withHeader(CONTENT_TYPE, ACTUATOR_CONTENT_TYPE))); }
Example #19
Source File: StatusUpdaterTest.java From spring-boot-admin with Apache License 2.0 | 5 votes |
@Test public void should_change_status_to_down() { String body = "{ \"status\" : \"UP\", \"details\" : { \"foo\" : \"bar\" } }"; this.wireMock.stubFor(get("/health").willReturn(okForContentType(ActuatorMediaType.V2_JSON, body) .withHeader("Content-Length", Integer.toString(body.length())))); StepVerifier.create(this.eventStore).expectSubscription() .then(() -> StepVerifier.create(this.updater.updateStatus(this.instance.getId())).verifyComplete()) .assertNext((event) -> { assertThat(event).isInstanceOf(InstanceStatusChangedEvent.class); assertThat(event.getInstance()).isEqualTo(this.instance.getId()); InstanceStatusChangedEvent statusChangedEvent = (InstanceStatusChangedEvent) event; assertThat(statusChangedEvent.getStatusInfo().getStatus()).isEqualTo("UP"); assertThat(statusChangedEvent.getStatusInfo().getDetails()).isEqualTo(singletonMap("foo", "bar")); }).thenCancel().verify(); StepVerifier.create(this.repository.find(this.instance.getId())) .assertNext((app) -> assertThat(app.getStatusInfo().getStatus()).isEqualTo("UP")).verifyComplete(); StepVerifier .create(this.repository.computeIfPresent(this.instance.getId(), (key, instance) -> Mono.just(instance.deregister()))) .then(() -> StepVerifier.create(this.updater.updateStatus(this.instance.getId())).verifyComplete()) .thenCancel().verify(); StepVerifier.create(this.repository.find(this.instance.getId())) .assertNext((app) -> assertThat(app.getStatusInfo().getStatus()).isEqualTo("UNKNOWN")).verifyComplete(); }
Example #20
Source File: InstanceWebClientTest.java From Moss with Apache License 2.0 | 5 votes |
@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(); 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"))); }
Example #21
Source File: InstanceWebClientTest.java From Moss with Apache License 2.0 | 5 votes |
@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, getRequestedFor(urlEqualTo("/status")).withHeader(ACCEPT, containing(MediaType.APPLICATION_JSON_VALUE)) .withHeader(ACCEPT, containing(ActuatorMediaType.V1_JSON)) .withHeader(ACCEPT, containing(ActuatorMediaType.V2_JSON)) ); }
Example #22
Source File: InstanceExchangeFilterFunctions.java From spring-boot-admin with Apache License 2.0 | 4 votes |
private static ClientResponse convertLegacyResponse(LegacyEndpointConverter converter, ClientResponse response) { return ClientResponse.from(response).headers((headers) -> { headers.replace(HttpHeaders.CONTENT_TYPE, singletonList(ActuatorMediaType.V2_JSON)); headers.remove(HttpHeaders.CONTENT_LENGTH); }).body(response.bodyToFlux(DataBuffer.class).transform(converter::convert)).build(); }
Example #23
Source File: AbstractInstancesProxyControllerIntegrationTest.java From Moss with Apache License 2.0 | 4 votes |
public void setUpClient(ConfigurableApplicationContext context) { int localPort = context.getEnvironment().getProperty("local.server.port", Integer.class, 0); client = WebTestClient.bindToServer() .baseUrl("http://localhost:" + localPort) .responseTimeout(Duration.ofSeconds(10)) .build(); String managementUrl = "http://localhost:" + wireMock.port() + "/mgmt"; //@formatter:off String actuatorIndex = "{ \"_links\": { " + "\"env\": { \"href\": \"" + managementUrl + "/env\", \"templated\": false }," + "\"test\": { \"href\": \"" + managementUrl + "/test\", \"templated\": false }," + "\"invalid\": { \"href\": \"" + managementUrl + "/invalid\", \"templated\": false }," + "\"timeout\": { \"href\": \"" + managementUrl + "/timeout\", \"templated\": false }" + " } }"; //@formatter:on wireMock.stubFor(get(urlEqualTo("/mgmt/health")).willReturn(ok("{ \"status\" : \"UP\" }").withHeader(CONTENT_TYPE, ActuatorMediaType.V2_JSON ))); wireMock.stubFor(get(urlEqualTo("/mgmt/info")).willReturn(ok("{ }").withHeader(CONTENT_TYPE, ACTUATOR_CONTENT_TYPE ))); wireMock.stubFor(options(urlEqualTo("/mgmt/env")).willReturn(ok().withHeader(ALLOW, HttpMethod.HEAD.name(), HttpMethod.GET.name(), HttpMethod.OPTIONS.name() ))); wireMock.stubFor(get(urlEqualTo("/mgmt")).willReturn(ok(actuatorIndex).withHeader(CONTENT_TYPE, ACTUATOR_CONTENT_TYPE ))); wireMock.stubFor(get(urlEqualTo("/mgmt/invalid")).willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE))); wireMock.stubFor(get(urlEqualTo("/mgmt/timeout")).willReturn(ok().withFixedDelay(10000))); wireMock.stubFor(get(urlEqualTo("/mgmt/test")).willReturn(ok("{ \"foo\" : \"bar\" }").withHeader(CONTENT_TYPE, ACTUATOR_CONTENT_TYPE ))); wireMock.stubFor(get(urlEqualTo("/mgmt/test/has%20spaces")).willReturn(ok("{ \"foo\" : \"bar-with-spaces\" }").withHeader(CONTENT_TYPE, ACTUATOR_CONTENT_TYPE ))); wireMock.stubFor(post(urlEqualTo("/mgmt/test")).willReturn(ok())); wireMock.stubFor(delete(urlEqualTo("/mgmt/test")).willReturn(serverError().withBody( "{\"error\": \"You're doing it wrong!\"}").withHeader(CONTENT_TYPE, ACTUATOR_CONTENT_TYPE))); instanceId = registerInstance(managementUrl); }