Search in sources :

Example 1 with InvalidPactException

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;
}
Also used : Message(au.com.dius.pact.model.v3.messaging.Message) InvalidPactException(au.com.dius.pact.model.InvalidPactException)

Aggregations

InvalidPactException (au.com.dius.pact.model.InvalidPactException)1 Message (au.com.dius.pact.model.v3.messaging.Message)1