Hi all, we tried to cover a file download endpoin...
# pact-jvm
m
Hi all, we tried to cover a file download endpoint via consumer driven contract test. The endpoint serves XML and we don't care about the downloaded content or tag structure. We just want to verify that the body is not empty. Here are the things that we tried and the results: Consumer class:
Copy code
public class DownloadEndpointsCDCTest extends ConsumerPactTest
{
  @Override
  protected RequestResponsePact createPact(final PactDslWithProvider aBuilder)
  {
      final DslPart expectedBodyResponse1 = PactDslRootValue.stringMatcher("^.+$", "whatever");
      final DslPart expectedBodyResponse2 = PactDslRootValue.stringMatcher("^.+$",
        "<?xml version=\"1.0\" encoding=\"utf-8\"?><example>foo</example>");
  
    return aBuilder//
        .given("A XML generation job finished successfully")
        .uponReceiving("A request to download XML")
        .pathFromProviderState("/xmlresult/${jobId}", "/xmlresult/" + "dummyJobId")
        .method("GET")
        .willRespondWith()
        .status(200)
        .headers(Map.of("Content-Type", "application/xml"))
       // .body(expectedBodyResponse1)
        .body(expectedBodyResponse2)
        .toPact();
  }
}
Generated contract:
Copy code
{
  "consumer": {
    "name": "XXX_Client"
  },
  "interactions": [
    {
      "description": "A request to download a XML",
      "providerStates": [
        {
          "name": "A XML generation finished successfully"
        }
      ],
      "request": {
        "generators": {
          "path": {
            "dataType": "STRING",
            "expression": "/nativeresult/${jobId}",
            "type": "ProviderState"
          }
        },
        "headers": {
          "RM-MDC-TOKEN": "dummyTraceId"
        },
        "method": "GET",
        "path": "/xmlresult/dummyJobId"
      },
      "response": {
        "body": "<?xml version=\"1.0\" encoding=\"utf-8\"?><example>foo</example>",
        "headers": {
          "Content-Type": "application/xml"
        },
        "matchingRules": {
          "body": {
            "$": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "regex",
                  "regex": "^.+$"
                }
              ]
            }
          },
          "header": {}
        },
        "status": 200
      }
    }
  ],
  "metadata": {
    "pact-jvm": {
      "version": "4.3.14"
    },
    "pactSpecification": {
      "version": "3.0.0"
    }
  },
  "provider": {
    "name": "XXX_Service"
  }
}
The verification fails on provider side. In case we use "*expectedBodyResponse1*" from the above example following exception is thrown (which is comprehensible because the content is not XML): Content is not allowed in prolog. at au.com.dius.pact.provider.junit5.PactVerificationContext.verifyInteraction(PactVerificationContext.kt:66) In case we use "*expectedBodyResponse2*" from the above example following exception is thrown: _Verifying a pact between XXX_Client and XXX_Service - A request to download a XML has a matching body_ body: $.example.#text Expected '' to match '^.+$' at au.com.dius.pact.provider.junit5.PactVerificationContext.verifyInteraction(PactVerificationContext.kt:66) How can we verify that a response of content type "application/xml" is not empty? Used versions: Consumer: au.com.dius.pact.consumerjunit4.3.14 Provider: au.com.dius.pact.providerjunit54.3.13
no ideas anyone? Should I enter a bug?
I created #1623