From 0f64d4c091da2f0003c03b4940d713778fa8057e Mon Sep 17 00:00:00 2001 From: Yuriy Savchenko Date: Thu, 21 Jul 2022 20:29:00 +0300 Subject: [PATCH] Add Kotlin example for WebTestClient setup docs Closes gh-9998 --- .../ROOT/pages/reactive/test/web/setup.adoc | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/docs/modules/ROOT/pages/reactive/test/web/setup.adoc b/docs/modules/ROOT/pages/reactive/test/web/setup.adoc index ca63529ea4..51adc6936d 100644 --- a/docs/modules/ROOT/pages/reactive/test/web/setup.adoc +++ b/docs/modules/ROOT/pages/reactive/test/web/setup.adoc @@ -2,7 +2,9 @@ The basic setup looks like this: -[source,java] +==== +.Java +[source,java,role="primary"] ---- @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = HelloWebfluxMethodApplication.class) @@ -19,9 +21,35 @@ public class HelloWebfluxMethodApplicationTests { // add Spring Security test Support .apply(springSecurity()) .configureClient() - .filter(basicAuthentication()) + .filter(basicAuthentication("user", "password")) .build(); } // ... } ---- + +.Kotlin +[source,kotlin,role="secondary"] +---- +@ExtendWith(SpringExtension::class) +@ContextConfiguration(classes = [HelloWebfluxMethodApplication::class]) +class HelloWebfluxMethodApplicationTests { + @Autowired + lateinit var context: ApplicationContext + + lateinit var rest: WebTestClient + + @BeforeEach + fun setup() { + this.rest = WebTestClient + .bindToApplicationContext(this.context) + // add Spring Security test Support + .apply(springSecurity()) + .configureClient() + .filter(basicAuthentication("user", "password")) + .build() + } + // ... +} +---- +====