/** * Closes the current array */ @Override public DslPart closeArray() { if (parent instanceof PactDslJsonArray) { closeObject(); return parent.closeArray(); } else { throw new UnsupportedOperationException("can't call closeArray on an Object"); } }
/** * 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; }
@Override public DslPart close() { DslPart parentToReturn = this; if (!closed) { DslPart parent = closeArray(); while (parent != null) { parentToReturn = parent; if (parent instanceof PactDslJsonArray) { parent = parent.closeArray(); } else { parent = parent.closeObject(); } } } return parentToReturn; }
/** * 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; }
protected void putArray(DslPart object) { for(String matcherName: object.matchers.getMatchingRules().keySet()) { matchers.setRules(matcherName, object.matchers.getMatchingRules().get(matcherName)); } generators.addGenerators(object.generators); if (StringUtils.isNotEmpty(object.rootName)) { body.put(object.rootName, object.getBody()); } else { body.put(StringUtils.difference(this.rootPath, object.rootPath), object.getBody()); } }
/** * Closes the current array */ public DslPart closeArray() { if (parent != null) { parent.putArray(this); } else { getMatchers().applyMatcherRootPrefix("$"); getGenerators().applyRootPrefix("$"); } closed = true; return parent; }
/** * Closes the current JSON object */ public DslPart closeObject() { if (parent != null) { parent.putObject(this); } else { getMatchers().applyMatcherRootPrefix("$"); getGenerators().applyRootPrefix("$"); } closed = true; return parent; }
/** * The body of the request * * @param body Built using the Pact body DSL */ public PactDslRequestWithoutPath body(DslPart body) { DslPart parent = body.close(); requestMatchers.addCategory(parent.matchers); requestGenerators.addGenerators(parent.generators); requestBody = OptionalBody.body(parent.toString()); if (!requestHeaders.containsKey(CONTENT_TYPE)) { requestHeaders.put(CONTENT_TYPE, 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; }
protected void putArray(DslPart object) { for(String matcherName: object.matchers.getMatchingRules().keySet()) { matchers.setRules(matcherName, object.matchers.getMatchingRules().get(matcherName)); } generators.addGenerators(object.generators); if (StringUtils.isNotEmpty(object.rootName)) { body.put(object.rootName, object.getBody()); } else { body.put(StringUtils.difference(this.rootPath, object.rootPath), object.getBody()); } }
/** * Closes the current array */ public DslPart closeArray() { if (parent != null) { parent.putArray(this); } else { getMatchers().applyMatcherRootPrefix("$"); getGenerators().applyRootPrefix("$"); } closed = true; return parent; }
/** * Closes the current JSON object */ public DslPart closeObject() { if (parent != null) { parent.putObject(this); } else { getMatchers().applyMatcherRootPrefix("$"); getGenerators().applyRootPrefix("$"); } closed = true; return parent; }
/** * The body of the request * * @param body Built using the Pact body DSL */ public PactDslRequestWithoutPath body(DslPart body) { DslPart parent = body.close(); requestMatchers.addCategory(parent.matchers); requestGenerators.addGenerators(parent.generators); requestBody = OptionalBody.body(parent.toString()); if (!requestHeaders.containsKey(CONTENT_TYPE)) { requestHeaders.put(CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()); } return this; }
/** * Closes the current array */ @Override public DslPart closeArray() { if (parent instanceof PactDslJsonArray) { closeObject(); return parent.closeArray(); } else { throw new UnsupportedOperationException("can't call closeArray on an Object"); } }
@Override public DslPart close() { DslPart parentToReturn = this; if (!closed) { DslPart parent = closeArray(); while (parent != null) { parentToReturn = parent; if (parent instanceof PactDslJsonArray) { parent = parent.closeArray(); } else { parent = parent.closeObject(); } } } return parentToReturn; }
/** * 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; }
protected void putObject(DslPart object) { for (String matcherName: object.matchers.getMatchingRules().keySet()) { matchers.setRules(matcherName, object.matchers.getMatchingRules().get(matcherName)); } generators.addGenerators(object.generators); String elementBase = StringUtils.difference(this.rootPath, object.rootPath); if (StringUtils.isNotEmpty(object.rootName)) { body.put(object.rootName, object.getBody()); } else { String name = StringUtils.strip(elementBase, "."); Pattern p = Pattern.compile("\\['(.+)'\\]"); Matcher matcher = p.matcher(name); if (matcher.matches()) { body.put(matcher.group(1), object.getBody()); } else { body.put(name, object.getBody()); } } }
public LambdaDslObject eachArrayLike(String name, Consumer<LambdaDslJsonArray> nestedArray) { final PactDslJsonArray arrayLike = object.eachArrayLike(name); final LambdaDslJsonArray dslArray = new LambdaDslJsonArray(arrayLike); nestedArray.accept(dslArray); arrayLike.closeArray().closeArray(); return this; }
@Override public DslPart close() { DslPart parentToReturn = this; if (!closed) { DslPart parent = closeObject(); while (parent != null) { parentToReturn = parent; if (parent instanceof PactDslJsonArray) { parent = parent.closeArray(); } else { parent = parent.closeObject(); } } } return parentToReturn; }
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; }