-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[kotlin] Add integration test for query params #22588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wing328
merged 1 commit into
OpenAPITools:master
from
pkubowicz:kotlin-params-integ-test
Jan 14, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...kotlin-jvm-spring-3-restclient/src/test/kotlin/org/openapitools/integration/PetApiTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| } | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
...otlin-jvm-spring-3-restclient/src/test/kotlin/org/openapitools/integration/UserApiTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the PR
i think we will need to update the build.gradle mustache template as well to include this testImlementation.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was afraid I was editing in a wrong place, but I could not find a better place for integration tests. I wanted to demonstrate the regression quickly.
I think integration tests (checking what URLs are hit, with what request body string) are very important. With Spring Mock Server, it's easy to write such tests with very little code, and they are also very fast (no port is opened, all happens inside JVM). I would be happy if the integration test suite grows somewhere in the future.
I don't know if integration tests should be part of samples (there are many sample projects, making finding and modifying all integration tests relevant to a feature harder). If you show me a 'cleaner' way to plug in my tests, I am happy to modify my PR.