From 67676880f7ab4a07e4cc0b4e9ec603c3d761a950 Mon Sep 17 00:00:00 2001 From: Piotr Kubowicz Date: Mon, 29 Dec 2025 23:30:42 +0100 Subject: [PATCH] [kotlin] Add integration test for query params This is a test for a regression from #22512 where param values were written as a list. --- .../build.gradle | 1 + .../openapitools/integration/PetApiTest.kt | 35 +++++++++++++++++++ .../openapitools/integration/UserApiTest.kt | 35 +++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 samples/client/petstore/kotlin-jvm-spring-3-restclient/src/test/kotlin/org/openapitools/integration/PetApiTest.kt create mode 100644 samples/client/petstore/kotlin-jvm-spring-3-restclient/src/test/kotlin/org/openapitools/integration/UserApiTest.kt diff --git a/samples/client/petstore/kotlin-jvm-spring-3-restclient/build.gradle b/samples/client/petstore/kotlin-jvm-spring-3-restclient/build.gradle index 87885e16cbe2..f46b04c5bda3 100644 --- a/samples/client/petstore/kotlin-jvm-spring-3-restclient/build.gradle +++ b/samples/client/petstore/kotlin-jvm-spring-3-restclient/build.gradle @@ -66,6 +66,7 @@ dependencies { implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.20.0" implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.20.0" implementation "org.springframework.boot:spring-boot-starter-web:$spring_boot_version" + testImplementation "org.springframework.boot:spring-boot-test:$spring_boot_version" testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2" } diff --git a/samples/client/petstore/kotlin-jvm-spring-3-restclient/src/test/kotlin/org/openapitools/integration/PetApiTest.kt b/samples/client/petstore/kotlin-jvm-spring-3-restclient/src/test/kotlin/org/openapitools/integration/PetApiTest.kt new file mode 100644 index 000000000000..29cf3c9d223b --- /dev/null +++ b/samples/client/petstore/kotlin-jvm-spring-3-restclient/src/test/kotlin/org/openapitools/integration/PetApiTest.kt @@ -0,0 +1,35 @@ +package org.openapitools.integration + +import io.kotlintest.matchers.collections.shouldHaveSize +import io.kotlintest.specs.ShouldSpec +import org.openapitools.client.apis.PetApi +import org.springframework.boot.test.web.client.MockServerRestClientCustomizer +import org.springframework.http.HttpMethod +import org.springframework.http.MediaType.APPLICATION_JSON +import org.springframework.test.web.client.match.MockRestRequestMatchers.method +import org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo +import org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess +import org.springframework.web.client.RestClient + +class PetApiTest : ShouldSpec() { + init { + should("find by status passing a query parameter with a list of values") { + val restClientBuilder: RestClient.Builder = RestClient.builder() + val mockServer = MockServerRestClientCustomizer().let { + it.customize(restClientBuilder) + it.getServer(restClientBuilder) + } + val petApi = PetApi(restClientBuilder.build()) + + mockServer.expect(requestTo("/pet/findByStatus?status=pending,available")) + .andExpect(method(HttpMethod.GET)) + .andRespond(withSuccess("[]", APPLICATION_JSON)) + + val response = petApi.findPetsByStatus(listOf(PetApi.StatusFindPetsByStatus.pending, PetApi.StatusFindPetsByStatus.available)) + + mockServer.verify() + + response shouldHaveSize 0 + } + } +} diff --git a/samples/client/petstore/kotlin-jvm-spring-3-restclient/src/test/kotlin/org/openapitools/integration/UserApiTest.kt b/samples/client/petstore/kotlin-jvm-spring-3-restclient/src/test/kotlin/org/openapitools/integration/UserApiTest.kt new file mode 100644 index 000000000000..34d15ceed200 --- /dev/null +++ b/samples/client/petstore/kotlin-jvm-spring-3-restclient/src/test/kotlin/org/openapitools/integration/UserApiTest.kt @@ -0,0 +1,35 @@ +package org.openapitools.integration + +import io.kotlintest.shouldBe +import io.kotlintest.specs.ShouldSpec +import org.openapitools.client.apis.UserApi +import org.springframework.boot.test.web.client.MockServerRestClientCustomizer +import org.springframework.http.HttpMethod +import org.springframework.http.MediaType.TEXT_PLAIN +import org.springframework.test.web.client.match.MockRestRequestMatchers.method +import org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo +import org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess +import org.springframework.web.client.RestClient + +class UserApiTest : ShouldSpec() { + init { + should("call login user passing a query parameter with a single value") { + val restClientBuilder: RestClient.Builder = RestClient.builder() + val mockServer = MockServerRestClientCustomizer().let { + it.customize(restClientBuilder) + it.getServer(restClientBuilder) + } + val userApi = UserApi(restClientBuilder.build()) + + mockServer.expect(requestTo("/user/login?username=myUsername&password=myPassword")) + .andExpect(method(HttpMethod.GET)) + .andRespond(withSuccess("login response", TEXT_PLAIN)) + + val response = userApi.loginUser("myUsername", "myPassword") + + mockServer.verify() + + response shouldBe "login response" + } + } +}