Hi <#C9UN99H24|> , i am trying to write provider t...
# pact-jvm
a
Hi #C9UN99H24 , i am trying to write provider test for a spring rest controller. However the pact test are failing on http status code 404. It is expected to return 200. if i run with MockitoJunitRunner it works fine. Any idea how to troubleshoot this further or resolve it. Thanks in advance.
u
It probably means the paths from the Pact file are not being correctly mapped to your controller methods. There is an example project you can have a look at https://github.com/pactflow/example-provider-springboot/blob/master/src/test/java/com/example/springboot/ProductsPactTest.java
a
@uglyog , i did verify the paths. they seem to match. i should mention that its not a springboot project as in the example. Here is my controller- @Controller @Path(“/healthCheck”) public class HealthCheckController{ @Autowired private HealthCheckservice healthCheckService; @GET @Path(“/“) public Response checkHealth( …….. return Response.ok(); } Here is the pact Json { ….. “interactions”: [ { request: { method: GET path: “/healthCheck” …… } Please ignore the formatting and syntax.
m
Would the path then be
/healthCheck/
(with the trailing slash)?
in your pact test, you’re missing the trailing slash
the logs of your API should hopefully tell you want path it actually hit and you could check against registered ones
a
@Matt (pactflow.io / pact-js / pact-go)@Matt (pactflow.io / pact-js / pact-go)@Matt (pactflow.io / pact-js / pact-go), will pact mock the call to the controller or the service has to be running? the same test works fine with mockitorunner. i added the trailing slash but it didnt help.
m
the provider has to be running locally
mocking it out isn’t very helpful here as it wouldn’t prove anything
the point of a provider test is to confirm it can respond to the requests the consumer needs
a
ohh we dont have a dedicated dev environment for the provider i am working on. Moreover we were thinking to integrate the pact test in to our maven int pipeline. i did try using wire mock and it worked. but i wanted to avoid using that. Isnt the purpose of pact to just make sure the contract is correct. how does it matter if we mock it or not. we are still validating the response against pact
Isnt it supposed to work like an integration Test since we are using MockMvc.
u
The purpose of Pact is to verify that the provider service behaves according to the interactions in the Pact file. If you use a mock server, you are not testing anything.
a
@uglyog , @Matt (pactflow.io / pact-js / pact-go)@Matt (pactflow.io / pact-js / pact-go)@Matt (pactflow.io / pact-js / pact-go)@Matt (pactflow.io / pact-js / pact-go)@Matt (pactflow.io / pact-js / pact-go) , i resolved the 404 issue The problem was our app is based on both jersey and spring mvc. The path annotations on resources were of jersey which were not getting picked up by the runner i believe. After replacing it with spring annotations like @RequestMapping and @GetMapping, it worked fine. I am using MockMvcTarget. Is this not the right way to test?