use of au.com.dius.pact.model.InvalidPactException in project pact-jvm by DiUS.
the class MessagePactBuilder method withContent.
public MessagePactBuilder withContent(DslPart body) {
if (messages == null || messages.isEmpty()) {
throw new InvalidPactException("expectsToReceive is required before withMetaData");
}
Message message = messages.get(messages.size() - 1);
@SuppressWarnings("unchecked") Map<String, String> metadata = message.getMetaData();
if (metadata == null) {
metadata = new HashMap<String, String>(1);
metadata.put(CONTENT_TYPE, ContentType.APPLICATION_JSON.toString());
} else if (!metadata.containsKey(CONTENT_TYPE)) {
metadata.put(CONTENT_TYPE, ContentType.APPLICATION_JSON.toString());
}
message.setContents(OptionalBody.body(body.toString()));
message.setMatchingRules(body.getMatchers());
return this;
}
Aggregations