Skip to content

Commit

Permalink
feat: set content type matcher with withBinaryData DSL method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Holshausen committed Jun 18, 2020
1 parent 8203452 commit 512f683
Showing 1 changed file with 3 additions and 1 deletion.
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 512f683

Please sign in to comment.