Skip to content

Instantly share code, notes, and snippets.

@ptrthomas
Last active January 7, 2018 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptrthomas/f4ec70480e0389119f49c679dfe408a3 to your computer and use it in GitHub Desktop.
Save ptrthomas/f4ec70480e0389119f49c679dfe408a3 to your computer and use it in GitHub Desktop.
Consumer-Provider Example
Ref Source Code Description
C Consumer.java The 'consumer' or client application that consumes the demo 'Payment Service' and also listens to a queue
P PaymentService.java The provider 'Payment Service' implemented in Spring Boot and using an in-memory data-store
1 ConsumerIntegrationTest.java An end-to-end integration test of the consumer that needs the real provider to be up and running
KC payment-service.feature A 'normal' Karate functional-test that tests the 'contract' of the Payment Service from the perspective of the consumer
2 PaymentServiceContractTest.java JUnit runner for the above Karate 'contract' test, that depends on the real provider being up and running
KP payment-service-mock.feature A 'state-ful' mock (or stub) that fully implements the 'contract' ! Yes, really.
3 PaymentServiceContractUsingMockTest.java Uses the above 'stub' to run the Payment Service 'contract' test
4 ConsumerUsingMockTest.java Uses the 'fake' Payment Service 'stub' to run an integration test for the real consumer
KX payment-service-proxy.feature Karate can act as a proxy with 'gateway like' capabilities, you can choose to either stub a response or delegate to a remote provider, depending on the incoming request. Think of the 'X' as being able to transform the HTTP request and response payloads as they pass through (and before returning)
5a ConsumerUsingProxyHttpTest.java Here Karate is set up to act as an HTTP proxy, the advantage is that the consumer can use the 'real' provider URL, which simplifies configuration, provided that you can configure the consumer to use an HTTP proxy (ideally in a non-invasive fashion)
5b ConsumerUsingProxyRewriteTest.java Karate acts as a URL 're-writing' proxy. Here the consumer 'knows' only about the proxy. In this mode (as well as the above 'HTTP proxy' mode which uses the same script file), you can choose to either stub a response - or even forward the incoming HTTP request onto any remote URL you choose.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment