/** * Value that must be an IP4 address */ public static PactDslRootValue ipAddress() { PactDslRootValue value = new PactDslRootValue(); value.setValue("127.0.0.1"); value.setMatcher(value.regexp("(\\d{1,3}\\.)+\\d{1,3}")); return value; }
/** * Value that must be a boolean */ public static PactDslRootValue booleanType() { return booleanType(true); }
/** * Value that must be a numeric identifier * @param id example id to use for generated bodies */ public static PactDslRootValue id(Long id) { return numberType(id); }
/** * Value that can be any string * * @param example example value to use for generated bodies */ public static PactDslRootValue stringType(String example) { PactDslRootValue value = new PactDslRootValue(); value.setValue(example); value.setMatcher(TypeMatcher.INSTANCE); return value; }
/** * Value that must match the given timestamp format * @param format timestamp format * @param example example date and time to use for generated bodies */ public static PactDslRootValue timestamp(String format, Date example) { FastDateFormat instance = FastDateFormat.getInstance(format); PactDslRootValue value = new PactDslRootValue(); value.setValue(instance.format(example)); value.setMatcher(value.matchTimestamp(format)); return value; }
/** * Value that must match the provided date format * @param format date format to match * @param example example date to use for generated values */ public static PactDslRootValue date(String format, Date example) { FastDateFormat instance = FastDateFormat.getInstance(format); PactDslRootValue value = new PactDslRootValue(); value.setValue(instance.format(example)); value.setMatcher(value.matchDate(format)); return value; }
/** * Value that must match the given time format * @param format time format to match * @param example example time to use for generated bodies */ public static PactDslRootValue time(String format, Date example) { FastDateFormat instance = FastDateFormat.getInstance(format); PactDslRootValue value = new PactDslRootValue(); value.setValue(instance.format(example)); value.setMatcher(value.matchTime(format)); return value; }
/** * Combine all the matchers using AND * @param example Attribute example value * @param rules Matching rules to apply */ public static PactDslRootValue and(Object example, MatchingRule... rules) { PactDslRootValue value = new PactDslRootValue(); if (example != null) { value.setValue(example); } else { value.setValue(JSONObject.NULL); } value.matchers.setRules("", new MatchingRuleGroup(Arrays.asList(rules), RuleLogic.AND)); return value; }
@Override public DslPart close() { getMatchers().applyMatcherRootPrefix("$"); getGenerators().applyRootPrefix("$"); return this; }
/** * Value that must be formatted as an ISO date */ public static PactDslRootValue date() { return date(DateFormatUtils.ISO_DATE_FORMAT.getPattern()); }
/** * Value that can be any string * * @param example example value to use for generated bodies */ public static PactDslRootValue stringType(String example) { PactDslRootValue value = new PactDslRootValue(); value.setValue(example); value.setMatcher(TypeMatcher.INSTANCE); return value; }
/** * Value that must match the given timestamp format * @param format timestamp format * @param example example date and time to use for generated bodies */ public static PactDslRootValue timestamp(String format, Date example) { FastDateFormat instance = FastDateFormat.getInstance(format); PactDslRootValue value = new PactDslRootValue(); value.setValue(instance.format(example)); value.setMatcher(value.matchTimestamp(format)); return value; }
/** * Value that must match the provided date format * @param format date format to match * @param example example date to use for generated values */ public static PactDslRootValue date(String format, Date example) { FastDateFormat instance = FastDateFormat.getInstance(format); PactDslRootValue value = new PactDslRootValue(); value.setValue(instance.format(example)); value.setMatcher(value.matchDate(format)); return value; }
/** * Value that must match the given time format * @param format time format to match * @param example example time to use for generated bodies */ public static PactDslRootValue time(String format, Date example) { FastDateFormat instance = FastDateFormat.getInstance(format); PactDslRootValue value = new PactDslRootValue(); value.setValue(instance.format(example)); value.setMatcher(value.matchTime(format)); return value; }
/** * Combine all the matchers using OR * @param example Attribute name * @param rules Matching rules to apply */ public static PactDslRootValue or(Object example, MatchingRule... rules) { PactDslRootValue value = new PactDslRootValue(); if (example != null) { value.setValue(example); } else { value.setValue(JSONObject.NULL); } value.matchers.setRules("", new MatchingRuleGroup(Arrays.asList(rules), RuleLogic.OR)); return value; }
@Override public DslPart close() { getMatchers().applyMatcherRootPrefix("$"); getGenerators().applyRootPrefix("$"); return this; }
/** * Value that must be formatted as an ISO date */ public static PactDslRootValue date() { return date(DateFormatUtils.ISO_DATE_FORMAT.getPattern()); }
/** * Value that must be an IP4 address */ public static PactDslRootValue ipAddress() { PactDslRootValue value = new PactDslRootValue(); value.setValue("127.0.0.1"); value.setMatcher(value.regexp("(\\d{1,3}\\.)+\\d{1,3}")); return value; }
/** * Value that can be any number * @param number example number to use for generated bodies */ public static PactDslRootValue numberType(Number number) { PactDslRootValue value = new PactDslRootValue(); value.setValue(number); value.setMatcher(TypeMatcher.INSTANCE); return value; }
/** * Value that must match the given timestamp format * @param format timestamp format */ public static PactDslRootValue timestamp(String format) { PactDslRootValue value = new PactDslRootValue(); value.generators.addGenerator(Category.BODY, "", new DateTimeGenerator(format)); FastDateFormat instance = FastDateFormat.getInstance(format); value.setValue(instance.format(new Date(DATE_2000))); value.setMatcher(value.matchTimestamp(format)); return value; }