From 512f683c9dd3d6659ac61f45e2a97baca18a82f7 Mon Sep 17 00:00:00 2001 From: Ronald Holshausen Date: Thu, 18 Jun 2020 15:55:40 +1000 Subject: [PATCH] feat: set content type matcher with withBinaryData DSL method --- .../java/au/com/dius/pact/consumer/dsl/PactDslResponse.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/consumer/src/main/java/au/com/dius/pact/consumer/dsl/PactDslResponse.java b/consumer/src/main/java/au/com/dius/pact/consumer/dsl/PactDslResponse.java index 2bfbcd121e..790be13a78 100644 --- a/consumer/src/main/java/au/com/dius/pact/consumer/dsl/PactDslResponse.java +++ b/consumer/src/main/java/au/com/dius/pact/consumer/dsl/PactDslResponse.java @@ -11,6 +11,7 @@ import au.com.dius.pact.core.model.generators.Category; import au.com.dius.pact.core.model.generators.Generators; import au.com.dius.pact.core.model.generators.ProviderStateGenerator; +import au.com.dius.pact.core.model.matchingrules.ContentTypeMatcher; import au.com.dius.pact.core.model.matchingrules.MatchingRules; import au.com.dius.pact.core.model.matchingrules.MatchingRulesImpl; import au.com.dius.pact.core.model.matchingrules.RegexMatcher; @@ -276,13 +277,14 @@ public PactDslResponse body(Document body) throws TransformerException { } /** - * Response body as a binary data. + * Response body as a binary data. It will match any expected bodies against the content type. * @param example Example contents to use in the consumer test * @param contentType Content type of the data */ public PactDslResponse withBinaryData(byte[] example, String contentType) { responseBody = OptionalBody.body(example, au.com.dius.pact.core.model.ContentType.fromString(contentType)); responseHeaders.put(CONTENT_TYPE, Collections.singletonList(contentType)); + responseMatchers.addCategory("body").addRule("$", new ContentTypeMatcher(contentType)); return this; }