-
Hi, I wanna use wiremockserver with dynamic port to simulate different responses and validate the incomig requests . Therefore I need to change the port where the injected Cxf Client sends the request. Is it possible? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
Hi @arolfes You can modify the URL dynamically at runtime using something like: @CXFClient
CalculatorSoap calculatorSoap;
@BeforeEach
void setup() {
((BindingProvider)calculatorSoap).getRequestContext()
.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:9999/calculator.asmx");
} |
Beta Was this translation helpful? Give feedback.
-
How do you start the wiremock server? |
Beta Was this translation helpful? Give feedback.
-
Hello @shumonsharif , thank you for the solution. its working fine. I didn't know that it is still possible to use the old fashion way to change the URL for an endpoint. but when I saw your solution I remembered it from previous cxf projects :-) thx a lot. Hello @famod , Late Night Update: Following the tutorial correctly I don't need to change the URL with extra code. Thank you for making it clear. so my code looks like this: Consumer with injected client@ApplicationScoped
class MyConsumer(
@CXFClient("soapService")
val soapClient: SoapServicePortType
) {
// some functions...
} ConsumerTestclass MyConsumerTest {
@InjectWireMock
lateinit var wireMockServer: WireMockServer
@Inject
lateinit var consumer: MyConsumer
@BeforeEach
fun beforeEach() {
wireMockServer.resetAll()
}
// some test functions Wiremock Resourceclass WireMockResource : QuarkusTestResourceLifecycleManager {
val wireMockServer =
WireMockServer(WireMockConfiguration.wireMockConfig().dynamicPort().httpsPort(0))
override fun start(): MutableMap<String, String> {
wireMockServer.start()
return mutableMapOf("quarkus.cxf.client.soapService.client-endpoint-url" to "http://localhost:${wireMockServer.port()}/${MyConsumer.SERVICE_ENDPOINT}")
}
override fun stop() {
wireMockServer.stop()
}
override fun inject(testInjector: TestInjector) {
testInjector.injectIntoFields(
wireMockServer,
AnnotatedAndMatchesType(InjectWireMock::class.java, WireMockServer::class.java)
)
}
}
@Target(AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER)
@Retention
annotation class InjectWireMock |
Beta Was this translation helpful? Give feedback.
-
And by the way your extension is easy to use. Good Job. |
Beta Was this translation helpful? Give feedback.
-
Hi @shumonsharif , @famod I marked @famod reply as answer because for my test purpose it's the better solution. |
Beta Was this translation helpful? Give feedback.
How do you start the wiremock server?
@QuarkusTestResource
should just work here, see https://quarkus.io/guides/getting-started-testing#quarkus-test-resource