/** * The body of the request * * @param body Built using the Pact body DSL */ public PactDslRequestWithPath body(DslPart body) { DslPart parent = body.close(); requestMatchers.addCategory(parent.getMatchers()); requestGenerators.addGenerators(parent.generators); requestBody = OptionalBody.body(parent.toString()); if (!requestHeaders.containsKey(CONTENT_TYPE)) { requestHeaders.put(CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()); } return this; }
/** * The body of the request * * @param body Built using the Pact body DSL */ public PactDslRequestWithPath body(DslPart body) { DslPart parent = body.close(); requestMatchers.addCategory(parent.getMatchers()); requestGenerators.addGenerators(parent.generators); requestBody = OptionalBody.body(parent.toString()); if (!requestHeaders.containsKey(CONTENT_TYPE)) { requestHeaders.put(CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()); } return this; }
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<>(1); metadata.put(CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()); } else if (!metadata.containsKey(CONTENT_TYPE)) { metadata.put(CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()); } DslPart parent = body.close(); message.setContents(OptionalBody.body(parent.toString())); message.getMatchingRules().addCategory(parent.getMatchers()); return this; }
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<>(1); metadata.put(CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()); } else if (!metadata.containsKey(CONTENT_TYPE)) { metadata.put(CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()); } DslPart parent = body.close(); message.setContents(OptionalBody.body(parent.toString())); message.getMatchingRules().addCategory(parent.getMatchers()); return this; }
/** * Response body to return * * @param body Response body built using the Pact body DSL */ public PactDslResponse body(DslPart body) { DslPart parent = body.close(); if (parent instanceof PactDslJsonRootValue) { ((PactDslJsonRootValue)parent).setEncodeJson(true); } responseMatchers.addCategory(parent.getMatchers()); responseGenerators.addGenerators(parent.generators); if (parent.getBody() != null) { responseBody = OptionalBody.body(parent.getBody().toString()); } else { responseBody = OptionalBody.nullBody(); } if (!responseHeaders.containsKey(CONTENT_TYPE)) { matchHeader(CONTENT_TYPE, DEFAULT_JSON_CONTENT_TYPE_REGEX, ContentType.APPLICATION_JSON.toString()); } return this; }
/** * Response body to return * * @param body Response body built using the Pact body DSL */ public PactDslResponse body(DslPart body) { DslPart parent = body.close(); if (parent instanceof PactDslJsonRootValue) { ((PactDslJsonRootValue)parent).setEncodeJson(true); } responseMatchers.addCategory(parent.getMatchers()); responseGenerators.addGenerators(parent.generators); if (parent.getBody() != null) { responseBody = OptionalBody.body(parent.getBody().toString()); } else { responseBody = OptionalBody.nullBody(); } if (!responseHeaders.containsKey(CONTENT_TYPE)) { matchHeader(CONTENT_TYPE, DEFAULT_JSON_CONTENT_TYPE_REGEX, ContentType.APPLICATION_JSON.toString()); } return this; }