Hi all. I have a question on the mix between HTTP ...
# general
g
Hi all. I have a question on the mix between HTTP and message event testing. Assuming app A consumes both HTTP REST APIs and events of app B, should app A produce a single contract with both HTTP and message event in it? If the answer is yes, do pact library allow to produce a provider test that both verify HTTP request and message event contracts and produces a single result? I am using java. I have produced a test that tests all HTTP interactions with a single call to
verifyInteraction()
. How do you add event testing to that?
m
If the pact files are serialised as version 4 of the Pact specification, then all interactions can be written to one contract (one logical consumer/provider). For versions earlier than that, you need to name the applications differently, unfortunately. Note Pact Spec Version != SDK version (e.g. Pact JVM 4.x.x)
For the second part of the question, I believe you would just add the additional message mappings to your verification tests: e.g. https://github.com/pactflow/example-provider-java-kafka/blob/master/src/test/java/io/pactflow/example/kafka/ProductsKafkaProducerTest.java I’m not fully across the Java API. what have you tried?
g
Thanks @Matt (pactflow.io / pact-js / pact-go). I have to study a bit your answer and the code you sent but I still have a fundamental doubt. For HTTP provider test you set up the controller in the context and the you call a single method
context.verifyInteraction();
. The pact library will replay the interactions and produce a single for the contract verification to inform the pact broker. I have no control on what happens after calling the verify function. If I add code to the same test to verify the event side of the contract I will then have two results: the HTTP verification and the event side verification but the pact broker must be informed with a single result. The contract is either verified or not.
m
Pact JVM will manage the results of both tests and send back to the broker (whether or not it’s a single contract from one consumer or multiple)