spring cloud contract testing - input message validation

334 views Asked by At

Do we have a way to test the input message contract from consumer side if producer changes input message body.

We use only stubTrigger.trigger("label"); to test from consumer side but how does consumer know that if the producer changes input message contract? Consumer test case seems to be passing for me always even producer changes input contract.

1

There are 1 answers

2
Marcin Grzejszczak On

So I understand that you have some synchronous situation where you receive a message and then send another one to some other application? Or is it the other way round, that you send a message and then expect to get back another one.

You have 2 choices. One is to read the documentation and use this approach (http://cloud.spring.io/spring-cloud-static/Dalston.SR3/#_scenario_2_output_triggered_by_input) . Here you can define a contract where a specific input message will allow to trigger an output. SO in your case if your output message is wrong then you will not receive the other one. The other approach is actually to split this into 2 contracts (https://github.com/spring-cloud/spring-cloud-contract/issues/321). Let's say that your app is called A and the other one is called B. First contract will be A sends a message to B (A is the producer) and the second one that B sends a message to A (B is the producer). So in case A wants to change input to send the message to B the contract tests will fail.