Hey. I'm trying to register an extension using jun...
# help
m
Hey. I'm trying to register an extension using junit 5. I'm using the
@RegisterExtension
annotation, and I know that my extension's
getName()
method is called, but the
transform
method is never actually called. I have tried using both a
ResponseTransformer
and a
ResponseDefinitionTransformer
, just in case there was a difference, and neither works. I'm using
stubFor()
to register the transformer for the stub. I know the stub matches the call, because I can make changes to the stub, and they show up in the test. I also tried using json stubs, with the same transformer name, and that also didn't work. I'm using WireMock 2.35 in a spring-boot 3 application. I followed this guide, but with the caveat that that guide uses interfaces that don't exist in my version of WireMock. Presumably because the guide is for a newer version of WireMock. I'm getting WireMock via
org.springframework.cloud:spring-cloud-contract-wiremock
, so I'm not really in a position to upgrade to 3.2.0. Any idea what I might be missing?
My debugger breakpoint in transform() is never hit. This is my configuration.
image.png
I'm auto-configuring WireMock in my test with this annotation:
Copy code
@AutoConfigureWireMock(port = 0, stubs = "classpath:/stubs")
t
@RegisterExtension
is for JUnit extensions rather than WireMock's. You need to add your transformer via the
.extensio s(...)
method on the config object passed to WireMock at startup.
m
I see. Do you know if there are any spring-level hooks for that? I ask because we use an annotation to auto-configure wiremock, so we don't have access to that object directly
t
I think you can put an instance of
WireMockConfiguration
into the test context and add it to this, per this comment: https://github.com/spring-cloud/spring-cloud-contract/blob/main/spring-cloud-contr[…]ingframework/cloud/contract/wiremock/WireMockConfiguration.java
m
I tried providing a
WireMockConfiguration
as a bean, but I ran into issues that it didn't pick up whatever other spring magic the auto-configuration does. However, what did solve it was adding a
WireMockConfigurationCustomizer
bean:
πŸ‘ 1
Thanks for all the help πŸ˜ƒ
I realize this is a spring-cloud-contract-wiremock issue, rather than a wiremock issue, but still πŸ˜ƒ
t
I probably ought to refresh my understanding of it a bit, since it’s such a big portion of our users
m
Thanks for a great piece of software πŸ˜ƒ
t
Thanks for the kind feedback!