Skip to content

Commit 6767688

Browse files
committed
[kotlin] Add integration test for query params
This is a test for a regression from OpenAPITools#22512 where param values were written as a list.
1 parent 19945d9 commit 6767688

3 files changed

Lines changed: 71 additions & 0 deletions

File tree

samples/client/petstore/kotlin-jvm-spring-3-restclient/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ dependencies {
6666
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.20.0"
6767
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.20.0"
6868
implementation "org.springframework.boot:spring-boot-starter-web:$spring_boot_version"
69+
testImplementation "org.springframework.boot:spring-boot-test:$spring_boot_version"
6970
testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2"
7071
}
7172

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.openapitools.integration
2+
3+
import io.kotlintest.matchers.collections.shouldHaveSize
4+
import io.kotlintest.specs.ShouldSpec
5+
import org.openapitools.client.apis.PetApi
6+
import org.springframework.boot.test.web.client.MockServerRestClientCustomizer
7+
import org.springframework.http.HttpMethod
8+
import org.springframework.http.MediaType.APPLICATION_JSON
9+
import org.springframework.test.web.client.match.MockRestRequestMatchers.method
10+
import org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo
11+
import org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess
12+
import org.springframework.web.client.RestClient
13+
14+
class PetApiTest : ShouldSpec() {
15+
init {
16+
should("find by status passing a query parameter with a list of values") {
17+
val restClientBuilder: RestClient.Builder = RestClient.builder()
18+
val mockServer = MockServerRestClientCustomizer().let {
19+
it.customize(restClientBuilder)
20+
it.getServer(restClientBuilder)
21+
}
22+
val petApi = PetApi(restClientBuilder.build())
23+
24+
mockServer.expect(requestTo("/pet/findByStatus?status=pending,available"))
25+
.andExpect(method(HttpMethod.GET))
26+
.andRespond(withSuccess("[]", APPLICATION_JSON))
27+
28+
val response = petApi.findPetsByStatus(listOf(PetApi.StatusFindPetsByStatus.pending, PetApi.StatusFindPetsByStatus.available))
29+
30+
mockServer.verify()
31+
32+
response shouldHaveSize 0
33+
}
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.openapitools.integration
2+
3+
import io.kotlintest.shouldBe
4+
import io.kotlintest.specs.ShouldSpec
5+
import org.openapitools.client.apis.UserApi
6+
import org.springframework.boot.test.web.client.MockServerRestClientCustomizer
7+
import org.springframework.http.HttpMethod
8+
import org.springframework.http.MediaType.TEXT_PLAIN
9+
import org.springframework.test.web.client.match.MockRestRequestMatchers.method
10+
import org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo
11+
import org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess
12+
import org.springframework.web.client.RestClient
13+
14+
class UserApiTest : ShouldSpec() {
15+
init {
16+
should("call login user passing a query parameter with a single value") {
17+
val restClientBuilder: RestClient.Builder = RestClient.builder()
18+
val mockServer = MockServerRestClientCustomizer().let {
19+
it.customize(restClientBuilder)
20+
it.getServer(restClientBuilder)
21+
}
22+
val userApi = UserApi(restClientBuilder.build())
23+
24+
mockServer.expect(requestTo("/user/login?username=myUsername&password=myPassword"))
25+
.andExpect(method(HttpMethod.GET))
26+
.andRespond(withSuccess("login response", TEXT_PLAIN))
27+
28+
val response = userApi.loginUser("myUsername", "myPassword")
29+
30+
mockServer.verify()
31+
32+
response shouldBe "login response"
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)