-
Notifications
You must be signed in to change notification settings - Fork 437
Spring Cloud Contract 4.0 Migration Guide
In this doc you will be able to find the migration guide on how to migrate to Spring Cloud Contract 4.0.
-
Remove Gradle's src/test/resources/contracts checking
- Rationale: We've got a separate source set for contract tests:
contractTest
. We've deprecated searching for thesrc/test/resources/contracts
a long time ago and now it's time to remove this check. - Migration path: Either move your contracts from
src/test/resources/contracts
tosrc/contractTest/resources/contracts
or setcontracts { contractsDslDir = file("src/test/resources/contracts") }
in your DSL
- Rationale: We've got a separate source set for contract tests:
-
Remove Spring Cloud Contract Pact integration
- Rationale: Pact has been breaking binary and functional compatibility in patch and minor releases. This is not something we can continue supporting in its current form.
- Migration path: Temporarily the Spring Cloud Contract Pact integration moved here but we're looking for a new home for it.
-
Maven 3.6 as prerequisite for Maven plugin
- Migration path: Upgrade your Maven build to use at least Maven 3.6
Related issues: Leave only code input triggers and output message type and #1837
Until now we had 3 messaging contract types. Output triggered by code execution
, Output triggered by an input message
and Input message that doesn't produce an output
. Effectively we can compare it to Supplier
, Function
and Consumer
interfaces. Truth be told that only the 1st model (Supplier
) makes sense. Function
is effectively a Supplier
+ Consumer
. A Consumer
however is a Stub Runner trigger
execution for Supplier
contract. So we've decided it's high time to remove 2 other types and leave only one, which simplifies things.
Functiontype messaging contract: Convert the contract into a
Supplier` version. The input part that you tested previously by sending a message to an actual queue should be converted to triggering of a label from a supplier messaging contract from a producer of that message.
Before:
- Producer (let's call it
A
) Application has a message listener on a topicfoo
and sends a message to a topicbar
. - Producer contract would contain
input
section with amessageFrom
element and anoutputMessage
section. - The generated test would send a message to the
input.messageFrom
section and poll for a message on theoutputMessage.sentTo
destination
After:
If Producer A
has a message listener on a topic foo
that means that
- Producer
A
is in fact both a consumer and a producer - Since it's a consumer, then there must be a Producer
B
that sends a message tofoo
Producer A
contract would contain triggeredBy
section that would execute some code that would in effect trigger message sending as described in the outputMessage
section of the contract.
The generated test would trigger the code that would send the message and then poll for a message on the outputMessage.sentTo
destination
To test the Producer A
consumer section you should trigger Producer B
s contract which would send a message to the foo
topic
Related issue: Removing support for mocked AMQP, OOB AMQP and OOB Kafka
For RabbitMQ integration, we've been mocking out using mocks and spies internals of Spring MessageListenerContainer
and RabbitTemplate
to mimic the broker behaviour. Of course, with time, it turned out that we're not supporting all possible combinations.
For Kafka integration we were using the embedded Kafka that could work in a different way than the actual Kafka broker.
Mocking these brokers couldn't be continued in this way - it's unsupportable and doesn't really test the actual communication. This is why we've decided to go with the middleware based approach which means that you should use tools like Testcontainers to start a broker and assert your tests against that broker.
Before:
You were using the stubbed AMQP or Kafka Stub Runner features.
After:
- You need to set up your broker for the tests (e.g. via Testcontainers)
- You need to setup the
MesssageVerifierSender
(consumer) orMessageVerifierReceiver
(producer) beans where you will define how you are actually sending and receiving messages
Examples: