Skip to content

Instantly share code, notes, and snippets.

@jaimedantas
Created April 1, 2021 00:16
Show Gist options
  • Save jaimedantas/8fdc806120f083625a9da64bc3999ec4 to your computer and use it in GitHub Desktop.
Save jaimedantas/8fdc806120f083625a9da64bc3999ec4 to your computer and use it in GitHub Desktop.
@MicronautTest(propertySources = ["application.yml"])
class RestControllerTest{
@Inject
@field:Client("/")
lateinit var client : RxHttpClient
@Test
@Property(name = "microservice.returnMessage", value = "My message")
fun shoudReturnMyMessage() {
val id: String = UUID.randomUUID().toString()
val uri = "/resource/$id"
val request: HttpRequest<HelloWorld> = HttpRequest.GET(uri)
val body = client.toBlocking().retrieve(request)
assertNotNull(body)
assertEquals("{\"message\":\"My message\"}", body)
}
@Test
fun shoudReturnBadRequest() {
val id: String = "invalidId"
val uri = "/resource/$id"
val request: HttpRequest<HelloWorld> = HttpRequest.GET(uri)
try {
client.toBlocking().retrieve(request)
fail("Should be bad request")
} catch(e: HttpClientResponseException){
assertEquals(HttpStatus.BAD_REQUEST, e.status)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment