Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member

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.

Copy link
Contributor Author

@pkubowicz pkubowicz Dec 30, 2025

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.

testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2"
}

Expand Down
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
}
}
}
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"
}
}
}
Loading