Jan Eivind Rognås
04/12/2024, 10:12 AMwireMockServer.stubFor(
WireMock.get(WireMock.urlPathTemplate("/organisations/v1/register/organisations/{id}"))
.willReturn(
WireMock.aResponse()
.withTransformers("filter-single-organisation")
// .withTransformerParameter("id", "{{ request.path.id }}")
))
class SingleOrganisationTransformer : ResponseDefinitionTransformerV2 {
override fun transform(serveEvent: ServeEvent): ResponseDefinition {
println(serveEvent.request.url)
println(serveEvent.stubMapping.request.urlPathTemplate)
val orgId = serveEvent.transformerParameters.getString("id") ?: 0
val organisation = jacksonObjectMapper().writeValueAsString(WireMockAdminStubs.ORGANISATIONS_LIST.find { it.id == orgId })
return ResponseDefinitionBuilder()
.withHeader("Content-Type", "application/json")
.withBody(organisation)
.build()
}
override fun getName(): String {
return "filter-single-organisation"
}
}
Tom
04/15/2024, 8:40 AMPathTemplate pathTemplate =
serveEvent.getStubMapping().getRequest().getUrlMatcher().getPathTemplate();
PathParams requestPathParams = pathTemplate.parse(Urls.getPath(request.getUrl()));
The PathParams
object contains the variable values.Jan Eivind Rognås
04/15/2024, 8:48 AM