Hi all in the group! I have a a bit of problem wit...
# pact-jvm
a
Hi all in the group! I have a a bit of problem with setting up pact for a project we are trying at our company. I have a project in intellij running spring boot with pact and it holds both client service and also a provider class responding to https call with a reply. Here is the pickle.. Im running the component im due to test, deployed in a docker container running on wsl on my machine (our company doesnt allow docker on windows... I have sorted the ssl problem by now) So the client class in intellij is sending a https call via the component in the container and back to the provider class in intellij and back to a responseEntity in my client. This works fine via the commandLineRunner in main and the regular SpringBootTest assertEquals (expected, actual). HOWEVER. If i set up a similar test in pact test having the pact test method send a https request via the client class and so forth i get the : au.com.dius.pact.consumer.PactMismatchesException: The following requests were not received: method: POST path: /callNextTicket/v1 query: {} headers: {} matchers: MatchingRules(rules={}) generators: Generators(categories={}) body: MISSING Im suspecting that this has to do with pacts mockserver kicking in. But is there any way around this without having to set up mock versions of all my services etc. deploying the pact project in the container causes a whole set of other problems.. Any thoughts?
m
Usually you would isolate the specific scenario you're testing and not send actual requests to services, except for the interaction you're focussed on. You definitely don't send requests to the real provider - they should go to the mock server. This is the error you're seeing - the mock server expected requests but didn't get them
👍 1
a
But is it possible at all to send a request to the real provider? Could i send a request to the real provider via a mock server?. If not, I think we have proven that pact will not be suitable for our purposes.
m
No, it's not how it works. Perhaps there's a misunderstanding of what Pact does. Why can't you run them as isolated unit tests instead of integrated using docker etc?
a
Yea I knew that it wasnt the conventional way of using Pact but I wanted to test if it could be used in this way anyway. So, the company I work for own this component that mappes and forwards GET requests from two services that we dont provide. So it looks like this: [Service A ]->SOAP GET -> [My Component] -> SOAP GET [Service B] After that a reply is sent back from Service B -> via my component that translates the msg format and forwards it to Service A. We dont provide or control either Service A nor B. So we have mocked both those services in our intelliJ project. What we want is to test the integration of our component without mixing with it. To be able to test it in a safe enviroment we have deployed our component in a container. I think If we need to mock also the component itself the Pact framwork will not be suitable for our specific needs. Althout pact seems really great for its intended puropses
So is your verdict that i should not use Pact for this kind of testing? 🙂
m
I'm not quite understanding why you can't do isolated testing. I get the general scenario but pact will give you the integration confidence without running them in an integrated way
👍 1
a
I feel like the alternative would be to mock also our component?. Simular jUnit tests are already on the components unit tests. I think in general it would create too many layers of mocking for our liking and we would like to test the actual integration of the component with mocked services around it. But its possible that i missunderstood the details of how Pact works in the end.
m
You don’t mock your own component in a Pact test, just the other collaborators. The idea is to isolate the communication between the two systems you’d like to contract test. In your case, you would mock
Service B
when writing a consumer Pact test from
My Component
to service B. The mock would be provided by Pact, so it can create a contract for Service B to later check. When
Service B
is verified by Pact, it would stub out any other external dependencies.
Service A
would do similar, except the provider would be your component. When
My Component
verifies its consumer contract with
Service A
, you would stub our your provider(s) - in this case,
Service B
.