diff --git a/framework-docs/modules/ROOT/pages/testing/mockmvc/hamcrest/expectations.adoc b/framework-docs/modules/ROOT/pages/testing/mockmvc/hamcrest/expectations.adoc index 5206b34d97fc..e8a81fe2c618 100644 --- a/framework-docs/modules/ROOT/pages/testing/mockmvc/hamcrest/expectations.adoc +++ b/framework-docs/modules/ROOT/pages/testing/mockmvc/hamcrest/expectations.adoc @@ -184,7 +184,10 @@ Kotlin:: + [source,kotlin,indent=0,subs="verbatim,quotes"] ---- - // Not possible in Kotlin until {kotlin-issues}/KT-22208 is fixed + standaloneSetup(SimpleController()) + .alwaysExpect(MockMvcResultMatchers.status().isOk()) + .alwaysExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) + .build() ---- ====== diff --git a/framework-docs/modules/ROOT/pages/testing/mockmvc/hamcrest/filters.adoc b/framework-docs/modules/ROOT/pages/testing/mockmvc/hamcrest/filters.adoc index d61a9f1b174b..ea625acabc56 100644 --- a/framework-docs/modules/ROOT/pages/testing/mockmvc/hamcrest/filters.adoc +++ b/framework-docs/modules/ROOT/pages/testing/mockmvc/hamcrest/filters.adoc @@ -18,7 +18,7 @@ Kotlin:: + [source,kotlin,indent=0,subs="verbatim,quotes"] ---- - // Not possible in Kotlin until {kotlin-issues}/KT-22208 is fixed + mockMvc = standaloneSetup(PersonController()).addFilters(CharacterEncodingFilter()).build() ---- ====== diff --git a/framework-docs/modules/ROOT/pages/testing/mockmvc/hamcrest/requests.adoc b/framework-docs/modules/ROOT/pages/testing/mockmvc/hamcrest/requests.adoc index cc85e2846ad7..5bc0f331d350 100644 --- a/framework-docs/modules/ROOT/pages/testing/mockmvc/hamcrest/requests.adoc +++ b/framework-docs/modules/ROOT/pages/testing/mockmvc/hamcrest/requests.adoc @@ -159,7 +159,18 @@ Kotlin:: + [source,kotlin,indent=0,subs="verbatim,quotes"] ---- - // Not possible in Kotlin until {kotlin-issues}/KT-22208 is fixed + class MyWebTests { + + lateinit var mockMvc: MockMvc + + @BeforeEach + fun setup() { + mockMvc = MockMvcBuilders.standaloneSetup(AccountController()) + .defaultRequest(get("/") + .contextPath("/app").servletPath("/main") + .accept(MediaType.APPLICATION_JSON)).build() + } + } ---- ====== diff --git a/framework-docs/modules/ROOT/pages/testing/mockmvc/hamcrest/setup-steps.adoc b/framework-docs/modules/ROOT/pages/testing/mockmvc/hamcrest/setup-steps.adoc index 8cda0b66b036..9d895e9de9b1 100644 --- a/framework-docs/modules/ROOT/pages/testing/mockmvc/hamcrest/setup-steps.adoc +++ b/framework-docs/modules/ROOT/pages/testing/mockmvc/hamcrest/setup-steps.adoc @@ -25,7 +25,13 @@ Kotlin:: + [source,kotlin,indent=0,subs="verbatim,quotes"] ---- - // Not possible in Kotlin until {kotlin-issues}/KT-22208 is fixed + // static import of MockMvcBuilders.standaloneSetup + + val mockMvc = standaloneSetup(MusicController()) + .defaultRequest(get("/").accept(MediaType.APPLICATION_JSON)) + .alwaysExpect(status().isOk()) + .alwaysExpect(content().contentType("application/json;charset=UTF-8")) + .build() ---- ====== @@ -53,7 +59,13 @@ Kotlin:: + [source,kotlin,indent=0,subs="verbatim,quotes"] ---- - // Not possible in Kotlin until {kotlin-issues}/KT-22208 is fixed + // static import of SharedHttpSessionConfigurer.sharedHttpSession + + val mockMvc = MockMvcBuilders.standaloneSetup(TestController()) + .apply(sharedHttpSession()) + .build() + + // Use mockMvc to perform requests... ---- ====== diff --git a/framework-docs/modules/ROOT/pages/testing/mockmvc/htmlunit/mah.adoc b/framework-docs/modules/ROOT/pages/testing/mockmvc/htmlunit/mah.adoc index 97dd4171b956..e78e83787c89 100644 --- a/framework-docs/modules/ROOT/pages/testing/mockmvc/htmlunit/mah.adoc +++ b/framework-docs/modules/ROOT/pages/testing/mockmvc/htmlunit/mah.adoc @@ -267,7 +267,19 @@ Kotlin:: + [source,kotlin,indent=0,subs="verbatim,quotes"] ---- - // Not possible in Kotlin until {kotlin-issues}/KT-22208 is fixed + val mockMvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .build() + + webClient = MockMvcWebClientBuilder + .mockMvcSetup(mockMvc) + // for illustration only - defaults to "" + .contextPath("") + // By default MockMvc is used for localhost only; + // the following will use MockMvc for example.com and example.org as well + .useMockMvcForHosts("example.com", "example.org") + .build() ---- ====== diff --git a/framework-docs/modules/ROOT/pages/testing/mockmvc/htmlunit/webdriver.adoc b/framework-docs/modules/ROOT/pages/testing/mockmvc/htmlunit/webdriver.adoc index a9e3533cac50..ea1575a9353d 100644 --- a/framework-docs/modules/ROOT/pages/testing/mockmvc/htmlunit/webdriver.adoc +++ b/framework-docs/modules/ROOT/pages/testing/mockmvc/htmlunit/webdriver.adoc @@ -562,7 +562,19 @@ Kotlin:: + [source,kotlin,indent=0,subs="verbatim,quotes"] ---- - // Not possible in Kotlin until {kotlin-issues}/KT-22208 is fixed + val mockMvc: MockMvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .build() + + driver = MockMvcHtmlUnitDriverBuilder + .mockMvcSetup(mockMvc) + // for illustration only - defaults to "" + .contextPath("") + // By default MockMvc is used for localhost only; + // the following will use MockMvc for example.com and example.org as well + .useMockMvcForHosts("example.com", "example.org") + .build() ---- ======