Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.json.JSONObject not found #1566

Open
Wiesbond opened this issue May 30, 2022 · 2 comments
Open

org.json.JSONObject not found #1566

Wiesbond opened this issue May 30, 2022 · 2 comments

Comments

@Wiesbond
Copy link

Wiesbond commented May 30, 2022

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
Copy link
Contributor

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants