no.skatteetaten.aurora.mockmvc.extensions.wiremock.ConnectionHeaderExtension.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockmvc-extensions-kotlin Show documentation
Show all versions of mockmvc-extensions-kotlin Show documentation
Simplifies setup of MockMvc tests combined with generation of restdocs and Spring Cloud Contract stubs
package no.skatteetaten.aurora.mockmvc.extensions.wiremock
import com.github.tomakehurst.wiremock.common.FileSource
import com.github.tomakehurst.wiremock.extension.Parameters
import com.github.tomakehurst.wiremock.extension.ResponseTransformer
import com.github.tomakehurst.wiremock.http.HttpHeader
import com.github.tomakehurst.wiremock.http.HttpHeaders
import com.github.tomakehurst.wiremock.http.Request
import com.github.tomakehurst.wiremock.http.Response
import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockExtensions
import org.springframework.http.HttpHeaders.CONNECTION
class MockMvcWireMockExtensions : WireMockExtensions {
override fun extensions() = mutableListOf(ConnectionHeaderTransformer())
}
class ConnectionHeaderTransformer : ResponseTransformer() {
override fun transform(
request: Request?,
response: Response?,
files: FileSource?,
parameters: Parameters?
): Response =
Response.Builder.like(response)
.headers(HttpHeaders.copyOf(response?.headers).plus(HttpHeader(CONNECTION, "Close")))
.build()
override fun getName() = this::class.simpleName
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy