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.08k stars 479 forks source link

org.json.JSONObject not found #1566

Open Wiesbond opened 2 years ago

Wiesbond commented 2 years ago

I have following pact and test in version 4.3.8

@Pact(consumer = "MyConsumer", provider = "MyProvider")
    public RequestResponsePact createPactForWiesaTest(PactDslWithProvider pactDslWithProvider) {

        PactDslResponse builder = pactDslWithProvider
            .given("Check buildId")
            .uponReceiving("Request to get wiesa buildId")
            .path("/wiesabuild")
            .headers(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN)
            .body("ala")
            .method("POST")
            .willRespondWith()
            .status(HttpStatus.OK.getCode())
            .body("is OK", MediaType.TEXT_PLAIN);
        return builder.toPact();
    }

    @Test
    @PactTestFor(providerName = "MyProvider", pactMethod = "createPactForWiesaTest", pactVersion = PactSpecVersion.V3)
    void testWiesaMultipartService(MockServer mockServer) throws MalformedURLException {
        String url = mockServer.getUrl();
        String response;

        try (RxHttpClient rxHttpClient = RxHttpClient.create(new URL(url))) {
            response = rxHttpClient.toBlocking().retrieve(
                HttpRequest.POST("/wiesabuild", "ala")
                    .contentType(MediaType.TEXT_PLAIN)
                    .accept(MediaType.TEXT_PLAIN),
                String.class
            );
            assertThat(response).as("body should be with simple is OK statement").isEqualToIgnoringWhitespace("is OK");
        }
    }

and I have got error: class file for org.json.JSONObject not found for .body("ala") in creating pact.

Looks like dependency org.json:json is missing in au.com.dius.pact.consumer:junit5:4.3.8

rholshausen commented 2 years ago

It's a transitive runtime dependency:

au.com.dius.pact.consumer:junit5:4.3.8
    -> au.com.dius.pact.consumer:4.3.8
        -> org.json:json:20210307 

Are you using Maven? You might need to add that to your project if your dependency resolution is not working.

marcosflobo commented 10 months ago

Same issue for me. I had to include in my dependencies testImplementation("org.json:json:20210307")