/** * Element that must be a boolean * @param example example boolean to use for generated bodies */ public PactDslJsonArray booleanType(Boolean example) { body.put(example); matchers.addRule(rootPath + appendArrayIndex(0), TypeMatcher.INSTANCE); return this; }
/** * Element that must be an integer * @param number example integer value to use for generated bodies */ public PactDslJsonArray integerType(Long number) { body.put(number); matchers.addRule(rootPath + appendArrayIndex(0), new NumberTypeMatcher(NumberTypeMatcher.NumberType.INTEGER)); return this; }
/** * Element that must be a decimalType value * @param number example decimalType value */ public PactDslJsonArray decimalType(BigDecimal number) { body.put(number); matchers.addRule(rootPath + appendArrayIndex(0), new NumberTypeMatcher(NumberTypeMatcher.NumberType.DECIMAL)); return this; }
/** * List item that must include the provided string * @param value Value that must be included */ public PactDslJsonArray includesStr(String value) { body.put(value); matchers.addRule(rootPath + appendArrayIndex(0), includesMatcher(value)); return this; }
/** * Adds an element that will have it's value injected from the provider state * @param expression Expression to be evaluated from the provider state * @param example Example value to be used in the consumer test */ public PactDslJsonArray valueFromProviderState(String expression, Object example) { generators.addGenerator(Category.BODY, rootPath + appendArrayIndex(0), new ProviderStateGenerator(expression)); body.put(example); return this; } }
/** * Element that must be an integer * @param number example integer value to use for generated bodies */ public PactDslJsonArray integerType(Long number) { body.put(number); matchers.addRule(rootPath + appendArrayIndex(0), new NumberTypeMatcher(NumberTypeMatcher.NumberType.INTEGER)); return this; }
protected void putObject(DslPart object) { for(String matcherName: object.matchers.getMatchingRules().keySet()) { matchers.setRules(rootPath + appendArrayIndex(1) + matcherName, object.matchers.getMatchingRules().get(matcherName)); } generators.addGenerators(object.generators, rootPath + appendArrayIndex(1)); for (int i = 0; i < getNumberExamples(); i++) { body.put(object.getBody()); } }
protected void putObject(DslPart object) { for(String matcherName: object.matchers.getMatchingRules().keySet()) { matchers.setRules(rootPath + appendArrayIndex(1) + matcherName, object.matchers.getMatchingRules().get(matcherName)); } generators.addGenerators(object.generators, rootPath + appendArrayIndex(1)); for (int i = 0; i < getNumberExamples(); i++) { body.put(object.getBody()); } }
/** * Element that must be an ISO formatted timestamp */ public PactDslJsonArray timestamp() { String pattern = DateFormatUtils.ISO_DATETIME_FORMAT.getPattern(); body.put(DateFormatUtils.ISO_DATETIME_FORMAT.format(new Date(DATE_2000))); generators.addGenerator(Category.BODY, rootPath + appendArrayIndex(0), new DateTimeGenerator(pattern)); matchers.addRule(rootPath + appendArrayIndex(0), matchTimestamp(pattern)); return this; }
/** * Element that must match the given timestamp format * @param format timestamp format */ public PactDslJsonArray timestamp(String format) { FastDateFormat instance = FastDateFormat.getInstance(format); body.put(instance.format(new Date(DATE_2000))); generators.addGenerator(Category.BODY, rootPath + appendArrayIndex(0), new DateTimeGenerator(format)); matchers.addRule(rootPath + appendArrayIndex(0), matchTimestamp(format)); return this; }
/** * Element that must be formatted as an ISO date */ public PactDslJsonArray date() { String pattern = DateFormatUtils.ISO_DATE_FORMAT.getPattern(); body.put(DateFormatUtils.ISO_DATE_FORMAT.format(new Date(DATE_2000))); generators.addGenerator(Category.BODY, rootPath + appendArrayIndex(0), new DateGenerator(pattern)); matchers.addRule(rootPath + appendArrayIndex(0), matchDate(pattern)); return this; }
/** * Element that must be formatted as an ISO date */ public PactDslJsonArray date() { String pattern = DateFormatUtils.ISO_DATE_FORMAT.getPattern(); body.put(DateFormatUtils.ISO_DATE_FORMAT.format(new Date(DATE_2000))); generators.addGenerator(Category.BODY, rootPath + appendArrayIndex(0), new DateGenerator(pattern)); matchers.addRule(rootPath + appendArrayIndex(0), matchDate(pattern)); return this; }
/** * Element that must be an ISO formatted time */ public PactDslJsonArray time() { String pattern = DateFormatUtils.ISO_TIME_FORMAT.getPattern(); body.put(DateFormatUtils.ISO_TIME_FORMAT.format(new Date(DATE_2000))); generators.addGenerator(Category.BODY, rootPath + appendArrayIndex(0), new TimeGenerator(pattern)); matchers.addRule(rootPath + appendArrayIndex(0), matchTime(pattern)); return this; }
/** * Element that must match the given time format * @param format time format to match */ public PactDslJsonArray time(String format) { FastDateFormat instance = FastDateFormat.getInstance(format); body.put(instance.format(new Date(DATE_2000))); generators.addGenerator(Category.BODY, rootPath + appendArrayIndex(0), new TimeGenerator(format)); matchers.addRule(rootPath + appendArrayIndex(0), matchTime(format)); return this; }
/** * Element that must match the given timestamp format * @param format timestamp format * @param example example date and time to use for generated bodies */ public PactDslJsonArray timestamp(String format, Date example) { FastDateFormat instance = FastDateFormat.getInstance(format); body.put(instance.format(example)); matchers.addRule(rootPath + appendArrayIndex(0), matchTimestamp(format)); return this; }
@Override public PactDslJsonArray eachArrayWithMaxLike(int numberExamples, Integer size) { if (numberExamples > size) { throw new IllegalArgumentException(String.format("Number of example %d is more than the maximum size of %d", numberExamples, size)); } matchers.addRule(rootPath + appendArrayIndex(1), matchMax(size)); PactDslJsonArray parent = new PactDslJsonArray(rootPath, "", this, true); parent.setNumberExamples(numberExamples); return new PactDslJsonArray("", "", parent); }
/** * Element that can be any number */ public PactDslJsonArray numberType() { generators.addGenerator(Category.BODY, rootPath + appendArrayIndex(1), new RandomIntGenerator(0, Integer.MAX_VALUE)); return numberType(100); }
/** * Element that must match the given timestamp format * @param format timestamp format * @param example example date and time to use for generated bodies */ public PactDslJsonArray timestamp(String format, Date example) { FastDateFormat instance = FastDateFormat.getInstance(format); body.put(instance.format(example)); matchers.addRule(rootPath + appendArrayIndex(0), matchTimestamp(format)); return this; }
@Override public PactDslJsonArray eachArrayWithMinLike(int numberExamples, Integer size) { if (numberExamples < size) { throw new IllegalArgumentException(String.format("Number of example %d is less than the minimum size of %d", numberExamples, size)); } matchers.addRule(rootPath + appendArrayIndex(1), matchMin(size)); PactDslJsonArray parent = new PactDslJsonArray(rootPath, "", this, true); parent.setNumberExamples(numberExamples); return new PactDslJsonArray("", "", parent); }
/** * Element that must be an integer */ public PactDslJsonArray integerType() { generators.addGenerator(Category.BODY, rootPath + appendArrayIndex(1), new RandomIntGenerator(0, Integer.MAX_VALUE)); return integerType(100L); }