no.skatteetaten.aurora.mockmvc.extensions.mock.mockContractResponse.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.mock
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import org.mockito.BDDMockito
inline fun BDDMockito.BDDMyOngoingStubbing.withContractResponse(
name: String,
folder: String = "contracts",
extension: String = "json",
objectMapper: ObjectMapper = jacksonObjectMapper(),
fn: ExtendedBDDMyOngoingStubbing.() -> BDDMockito.BDDMyOngoingStubbing
): ExtendedBDDMyOngoingStubbing {
val fileName = "/$folder/$name.$extension"
val content = objectMapper.readValue(this::class.java.getResource(fileName))
val onGoingStubbing = fn(ExtendedBDDMyOngoingStubbing(this, content))
return ExtendedBDDMyOngoingStubbing(onGoingStubbing, content)
}
class ExtendedBDDMyOngoingStubbing(ongoingStubbing: BDDMockito.BDDMyOngoingStubbing, val content: T) :
BDDMockito.BDDMyOngoingStubbing by ongoingStubbing {
val mockResponse = content
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy