Open Ashwinikumar2002 opened 1 year ago
@uglyog pls help
The Pact verification test made the request to your provider, expecting a 200 response with a JSON body, but got 401 response instead with no body.
401 is an unauthorized response status. You provider rejected the request because it is unauthenticated.
Please refer to https://github.com/pact-foundation/pact-jvm/tree/master/provider/junit5#modifying-the-requests-before-they-are-sent on how you can add authentication headers to the request.
How do I resolve the response body. Also the Authorization is basic auth key. how will I pass it???
"Content-Type": "application/json;charset=UTF-8"
"Authorization": "Basic auth_key",
This is the content type and authorization the consumer is sending to my service...
I am trying to write the provider driven contract test not consumer driven contract test @rholshausen
No sure what that means, but if you are getting a 401 response, then this must be wrong: "Authorization": "Basic auth_key"
.
Have you tried accessing the API with something like curl or Postman?
Yes
I put user id and pass
Even adding the Httprequest is throwing this error- org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter [au.com.dius.pact.consumer.MockServer mockServer]
and get a token I guess it is standard springboot auth which we are using.
Then that is using Basic Auth. You need the correct header value for that. You can find the correct header in Postman.
I.e. with
you can find the header value that was used
Even adding the Httprequest is throwing this error- org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter [au.com.dius.pact.consumer.MockServer mockServer]
What about this??
@rholshausen
<dependency>
<groupId>au.com.dius.pact.provider</groupId>
<artifactId>junit5spring</artifactId>
<version>4.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5</artifactId>
<version>5.1.2</version>
</dependency>
This is my dependency
That error is possibly due to @ExtendWith(PactVerificationInvocationContextProvider.class)
missing on your test template method. Have you setup the test correctly according to the JUnit5 docs?
Can you share that doc??
That error is possibly due to
@ExtendWith(PactVerificationInvocationContextProvider.class)
missing on your test template method. Have you setup the test correctly according to the JUnit5 docs?
I have this annotation
Facing the below error at this point in the Provider contract testing please help.
@TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { if (context != null) { context.verifyInteraction(); } }
The error message is below - [INFO] [none] [client: none][trx: none] [http-nio-9090-exec-1] [o.a.c.c.C.[Tomcat].[localhost].[/]] : Initializing Spring DispatcherServlet 'dispatcherServlet'
[INFO] [none] [client: none][trx: none] [http-nio-9090-exec-1] [o.s.web.servlet.DispatcherServlet] : Initializing Servlet 'dispatcherServlet'
[INFO] [none] [client: none][trx: none] [http-nio-9090-exec-1] [o.s.web.servlet.DispatcherServlet] : Completed initialization in 2 ms
returns a response which has status code 200 (FAILED) has a matching body (FAILED)
Failures:
1) Verifying a pact between OrderProcessing and Namor - Pact Verification for Payment initiation: has status code 200