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

[V3] PactDslJsonRootValue as response body fails #1855

Open
huehnerlady opened this issue Feb 14, 2025 · 2 comments
Open

[V3] PactDslJsonRootValue as response body fails #1855

huehnerlady opened this issue Feb 14, 2025 · 2 comments

Comments

@huehnerlady
Copy link
Contributor

Hi,

I am currently try to implement a pact:

my code looks as follows

  @Pact(consumer = "CONSUMER")
  fun consumer(builder: PactDslWithProvider) =
      builder
          .uponReceiving("download document")
          .method("GET")
          .path("/download")
          .willRespondWith()
          .status(200)
          .headers(mapOf("Content-Type" to "application/pdf"))
          .body(PactDslJsonRootValue.stringType("someFile"))
          .toPact()

  @Test
  @PactTestFor(pactMethod = "consumer", pactVersion = V3)
  fun testConsumer(mockServer: MockServer) {
    val response = RestTemplate().getForEntity(mockServer.getUrl() + "/download", ByteArray::class.java)
    response.statusCode shouldBe HttpStatus.OK
    response.headers["Content-Type"]?.shouldContain("application/pdf")
    response.body?.toString(Charsets.UTF_8) shouldBe "someFile"
  }

I now have the problem:

Expected :"someFile"
Actual   :""someFile""

So for me it looks like there is an extra set of " added to the response?

relates to #1841 (same error, but in V4 and request, therefore I opened a new issue)

@rholshausen
Copy link
Contributor

PactDslJsonRootValue and the other JSON DSLs can only be used with JSON payloads (that's why they have Json in the class name). Your content type is application/pdf, which is a binary format. You can't use any matching rules with that except for the content type one.

@huehnerlady
Copy link
Contributor Author

PactDslJsonRootValue and the other JSON DSLs can only be used with JSON payloads (that's why they have Json in the class name). Your content type is application/pdf, which is a binary format. You can't use any matching rules with that except for the content type one.

@rholshausen thanks for your answer. but what does stringType as a root value otherwise mean? to me it sounds like there is a body and instead of an object I have just a string. so I am very confused in which other circumstance I would use this then?

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

2 participants