pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.07k stars 473 forks source link

Pact JVM with Gradle: Authorization issue, getting response as 400 #1795

Open muhammad-arham643 opened 1 month ago

muhammad-arham643 commented 1 month ago

Hi! I am new to Pact JVM and I am trying to write the test on the provider side. I am getting the error 400 as a return code instead of 200. I am using the gradle tool to test the functionality. Can someone please guide me to this issue?

I am using the correct token and the header and the content-type.

Thanks in advance.

@Provider("ABC") @PactFolder("pacts") public class ProviderTest {

private String token; // Declare the token variable
@BeforeEach
void before(PactVerificationContext context){
    token = "1234567"
    context.setTarget(new HttpsTestTarget("testing.ABC.", 443, "/..));
}

@TestTemplate
@ExtendWith(PactVerificationInvocationContextProvider.class)
void verifyPact(PactVerificationContext context, HttpRequest request) {

    request.addHeader("Authorization", "Bearer " + token);
    context.verifyInteraction();
}

@State("my test does not exists")
void testdoesnotexists() {
    /* Set up the token as needed for this provider state */
}
}
rholshausen commented 1 month ago

400 error code means your provider did not get the request it was expecting. You will need to enable debug logging to work out what the error is.