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

Pact verification of response body with line breaks fails (JUnit5) #1579

Open
mhnot opened this issue Jul 7, 2022 · 0 comments
Open

Pact verification of response body with line breaks fails (JUnit5) #1579

mhnot opened this issue Jul 7, 2022 · 0 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@mhnot
Copy link

mhnot commented Jul 7, 2022

I tried to cover a file download endpoint via consumer driven contract test.
I don't care about the downloaded content but want to verify that the body is not empty by using PactDslRootValue.stringMatcher("^.+$", "whatever")

Consumer class:

public class DownloadEndpointsCDCTest extends ConsumerPactTest
{
  @Override
  protected RequestResponsePact createPact(final PactDslWithProvider aBuilder)
  {
    return aBuilder//
        .given("A text generation job finished successfully")
        .uponReceiving("A request to download text")
        .pathFromProviderState("/textresult/${jobId}", "/textresult/" + "dummyJobId")
        .method("GET")
        .willRespondWith()
        .status(200)
        .headers(Map.of("Content-Type", "text/plain"))
        .body(PactDslRootValue.stringMatcher("^.+$", "whatever"))
        .toPact();
  }
}

Generated contract:

{
  "consumer": {
    "name": "Core_Chat_Client"
  },
  "interactions": [
    {
      "description": "A request to download text",
      "providerStates": [
        {
          "name": "A text generation job finished successfully"
        }
      ],
      "request": {
        "generators": {
          "path": {
            "dataType": "STRING",
            "expression": "/textresult/${jobId}",
            "type": "ProviderState"
          }
        },
        "method": "GET",
        "path": "/textresult/dummyJobId"
      },
      "response": {
        "body": "whatever",
        "headers": {
          "Content-Type": "text/plain"
        },
        "matchingRules": {
          "body": {
            "$": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "regex",
                  "regex": "^.+$"
                }
              ]
            }
          }
        },
        "status": 200
      }
    }
  ],
  "metadata": {
    "pact-jvm": {
      "version": "4.3.10"
    },
    "pactSpecification": {
      "version": "3.0.0"
    }
  },
  "provider": {
    "name": "Chat_Service"
  }
}

Unfortunately the verification on provider side fails in case body contains line breaks.
The body content "Hello World" can be verified successfully but "Hello \r\n World" fails with following message:

java.lang.AssertionError: Core_Chat_Client - Upon A request to download text
Failures:

  1. Verifying a pact between Core_Chat_Client and Chat_Service - A request to download text has a matching body

    1.1) body: / Expected body 'whatever' to match 'Hello
    World' using regex '^.+$' but did not match
    at au.com.dius.pact.provider.junit5.PactVerificationContext.verifyInteraction(PactVerificationContext.kt:66)
    at foo.ContractVerificationTest.pactVerificationTestTemplate(ContractVerificationTest.java:147)

Used versions:
Consumer: au.com.dius.pact.consumer:junit:4.3.10
Provider: au.com.dius.pact.provider:junit5:4.3.10

@rholshausen rholshausen added the bug Indicates an unexpected problem or unintended behavior label Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants