Created
April 1, 2021 00:16
-
-
Save jaimedantas/8fdc806120f083625a9da64bc3999ec4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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