-
Notifications
You must be signed in to change notification settings - Fork 436
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/contractsa long time ago and now it's time to remove this check. - Migration path: Either move your contracts from
src/test/resources/contractstosrc/contractTest/resources/contractsor 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 aSupplier` 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 topicfooand sends a message to a topicbar. - Producer contract would contain
inputsection with amessageFromelement and anoutputMessagesection. - The generated test would send a message to the
input.messageFromsection and poll for a message on theoutputMessage.sentTodestination
After:
If Producer A has a message listener on a topic foo that means that
- Producer
Ais in fact both a consumer and a producer - Since it's a consumer, then there must be a Producer
Bthat 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 Bs 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: