wiremock-testcontainers-java icon indicating copy to clipboard operation
wiremock-testcontainers-java copied to clipboard

Add a Demo for WireMock as a proxy in front of another service

Open oleg-nenashev opened this issue 2 years ago • 6 comments

Proposal

One can use Testcontainers for Java to deploy multiple instances in Docker Compose, and we have a concept for that but not existing demo. It would be nice to have an API service provisioned in Testcontainers, and a WireMock mocking a particular request (e,g, injecting a fault) just for one request. The service suggestions are welcome!

image

References

No response

oleg-nenashev avatar Oct 17 '23 08:10 oleg-nenashev

I have started working on the same.

kapishmalik avatar Oct 21 '23 14:10 kapishmalik

Hello, @oleg-nenashev, @kapishmalik - is this still needed? I wouldn't mind working on a little demo/tutorial

etrandafir93 avatar Jul 03 '24 06:07 etrandafir93

Yes, this item is still relevant

oleg-nenashev avatar Jul 04 '24 11:07 oleg-nenashev

Hello @oleg-nenashev, I started looking into this :)

If I understood well, we want to test the interaction between a simple "client" app and the service it depends on. This "server" will expose a REST API and it will be provisioned for testing via Testconatienrs and docker compose.

Then, we'll use a WireMock to proxy the "server" app running in the testcontainer. We can showcase tests for the happy flow, as well as inject errors or delays to test the corner cases.

I have prepared a small demo trying to keep things very simple, here is a link: etrandafir93/wiremock-testcontainers-practice.

As you'll see in the example, I have tried to keep things simple by:

  • Using only one class per service/app
  • Avoid starting S.B. and the web layer for the tested service, I have just instantiated the tested class instead
  • Using wiremock-standalone instead of the wiremock testcontainer

Finally, I wanted to mention that everything here is very raw. But if you think the direction is good, I can write a Baeldung-style article describing how to set up everything.

Let me know what you think, Cheers, Emanuel

etrandafir93 avatar Jul 19 '24 15:07 etrandafir93

Hi @etrandafir93 . Any documentation is always welcome. If you do not use the testcontainers module for this use case, maybe it is better to target the WireMock blog or another resource. @leeturner can probably support you, please reach out to him on slack

oleg-nenashev avatar Jul 20 '24 14:07 oleg-nenashev

Hey @oleg-nenashev - I have joined slack and got in contact with Lee.

I have created this PR for the wiremock-exampels repo, thanks!

etrandafir93 avatar Jul 29 '24 11:07 etrandafir93