I am trying to test the following spring webflux Kotlin application with the WebTestClient and Junit 5:
@SpringBootApplication
class ReactiveKataApplication
fun main(args: Array<String>) {
SpringApplicationBuilder(ReactiveKataApplication::class.java)
.initializers(
beans {
bean {
router {
GET("/frp/hello") {
ServerResponse.ok().body(Mono.just("Hello"), String::class.java)
}
}
}
})
.build()
.run(*args)
}
I have the following test which is failing with a 404, can anyone help me identify the issue?
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@SpringBootTest
class ReactiveKataApplicationContextTest {
private lateinit var webTestClient : WebTestClient
@Autowired
lateinit var context: ApplicationContext
@BeforeAll
fun initClient() {
webTestClient = WebTestClient
.bindToApplicationContext(context)
.configureClient()
.build()
}
@Test
fun `calling hello world endpoint returns 200`() {
webTestClient.get().uri("/frp/hello")
.exchange()
.expectStatus().isOk
}
}
In the test log I see that the context is the ReactiveKataApplicationContextTest rather than the actual application, can anyone assist in resolving this using the WebTestClient binding to the Application Context?
2020-01-29 12:01:27.538 INFO 16269 --- [ main] c.o.r.ReactiveKataApplicationContextTest : Started ReactiveKataApplicationContextTest in 1.666 seconds (JVM running for 3.157)
I have tried @SpringBootTest(classes = [ ReactiveKataApplication::class ])
to no avail.
Git repo here: https://github.com/stefan-cross/reactive-spring-kata