Test Micronaut Health endpoint

Micronaut management dependency adds support for monitoring of your application via endpoints. For example, the health endpoint exposes the state of your application.

I test it with Spock:

package example.micronaut

import io.micronaut.http.HttpRequest
import io.micronaut.http.client.HttpClient
import io.micronaut.http.client.annotation.Client
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import javax.inject.Inject
import spock.lang.Specification
import io.micronaut.http.HttpResponse
import io.micronaut.http.HttpStatus
import io.micronaut.http.client.BlockingHttpClient

class HealthSpec extends Specification {

    HttpClient httpClient
    void "/health responds OK"() {
        BlockingHttpClient client = httpClient.toBlocking()
        HttpRequest<?> request = HttpRequest.GET('/health')
        HttpResponse<Map> response = client.exchange(request, Map)

        response.status() == HttpStatus.OK
        response.body() == [status: 'UP']

My next events:
๐Ÿ—“ May 27 09:00 AWS Dublin - Micronaut and AWS Lambda
๐Ÿ—“ Jul 20 09:00 Workshop Security in the Micronaut Framework
๐Ÿ—“ Sep 20 09:00 JCON Online 2022 - Getting Started with the Micronaut Framework
๐Ÿ—“ Sep 23 09:00 JCON Online 2022 - Micronautยฎ Framework and Microstream Java-native persistence engine

Tags: #micronaut #test #spock
May 2021, 06.