All Downloads are FREE. Search and download functionalities are using the official Maven repository.

no.skatteetaten.aurora.mockmvc.extensions.mock.mockContractResponse.kt Maven / Gradle / Ivy

Go to download

Simplifies setup of MockMvc tests combined with generation of restdocs and Spring Cloud Contract stubs

There is a newer version: 1.1.7
Show newest version
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