/** * Value that must be an IP4 address */ public static PactDslJsonRootValue ipAddress() { PactDslJsonRootValue value = new PactDslJsonRootValue(); value.setValue("127.0.0.1"); value.setMatcher(value.regexp("(\\d{1,3}\\.)+\\d{1,3}")); return value; }
/** * Value that must be encoded as a hexadecimal value * @param hexValue example value to use for generated bodies */ public static PactDslJsonRootValue hexValue(String hexValue) { if (!hexValue.matches(HEXADECIMAL)) { throw new InvalidMatcherException(EXAMPLE + hexValue + "\" is not a hexadecimal value"); } PactDslJsonRootValue value = new PactDslJsonRootValue(); value.setValue(hexValue); value.setMatcher(value.regexp("[0-9a-fA-F]+")); return value; }
/** * Value that must be encoded as a hexadecimal value * @param hexValue example value to use for generated bodies */ public static PactDslJsonRootValue hexValue(String hexValue) { if (!hexValue.matches(HEXADECIMAL)) { throw new InvalidMatcherException(EXAMPLE + hexValue + "\" is not a hexadecimal value"); } PactDslJsonRootValue value = new PactDslJsonRootValue(); value.setValue(hexValue); value.setMatcher(value.regexp("[0-9a-fA-F]+")); return value; }
/** * Value that must be encoded as an UUID * @param uuid example UUID to use for generated bodies */ public static PactDslJsonRootValue uuid(String uuid) { if (!uuid.matches(UUID_REGEX)) { throw new InvalidMatcherException(EXAMPLE + uuid + "\" is not an UUID"); } PactDslJsonRootValue value = new PactDslJsonRootValue(); value.setValue(uuid); value.setMatcher(value.regexp(UUID_REGEX)); return value; }
/** * Value that must match the regular expression * @param regex regular expression * @param value example value to use for generated bodies */ public static PactDslJsonRootValue stringMatcher(String regex, String value) { if (!value.matches(regex)) { throw new InvalidMatcherException(EXAMPLE + value + "\" does not match regular expression \"" + regex + "\""); } PactDslJsonRootValue rootValue = new PactDslJsonRootValue(); rootValue.setValue(value); rootValue.setMatcher(rootValue.regexp(regex)); return rootValue; }
/** * Value that must be an IP4 address */ public static PactDslJsonRootValue ipAddress() { PactDslJsonRootValue value = new PactDslJsonRootValue(); value.setValue("127.0.0.1"); value.setMatcher(value.regexp("(\\d{1,3}\\.)+\\d{1,3}")); return value; }
/** * Value that must be encoded as an UUID * @param uuid example UUID to use for generated bodies */ public static PactDslJsonRootValue uuid(String uuid) { if (!uuid.matches(UUID_REGEX)) { throw new InvalidMatcherException(EXAMPLE + uuid + "\" is not an UUID"); } PactDslJsonRootValue value = new PactDslJsonRootValue(); value.setValue(uuid); value.setMatcher(value.regexp(UUID_REGEX)); return value; }
/** * Value that must be encoded as an UUID */ public static PactDslJsonRootValue uuid() { PactDslJsonRootValue value = new PactDslJsonRootValue(); value.generators.addGenerator(Category.BODY, "", UuidGenerator.INSTANCE); value.setValue("e2490de5-5bd3-43d5-b7c4-526e33f71304"); value.setMatcher(value.regexp(UUID_REGEX)); return value; }
/** * Value that must be encoded as an UUID */ public static PactDslJsonRootValue uuid() { PactDslJsonRootValue value = new PactDslJsonRootValue(); value.generators.addGenerator(Category.BODY, "", UuidGenerator.INSTANCE); value.setValue("e2490de5-5bd3-43d5-b7c4-526e33f71304"); value.setMatcher(value.regexp(UUID_REGEX)); return value; }
/** * Matches a URL that is composed of a base path and a sequence of path expressions * @param basePath The base path for the URL (like "http://localhost:8080/") which will be excluded from the matching * @param pathFragments Series of path fragments to match on. These can be strings or regular expressions. */ public PactDslJsonRootValue matchUrl(String basePath, Object... pathFragments) { UrlMatcherSupport urlMatcher = new UrlMatcherSupport(basePath, Arrays.asList(pathFragments)); PactDslJsonRootValue value = new PactDslJsonRootValue(); value.setValue(urlMatcher.getExampleValue()); value.setMatcher(value.regexp(urlMatcher.getRegexExpression())); return value; }
/** * Matches a URL that is composed of a base path and a sequence of path expressions * @param basePath The base path for the URL (like "http://localhost:8080/") which will be excluded from the matching * @param pathFragments Series of path fragments to match on. These can be strings or regular expressions. */ public PactDslJsonRootValue matchUrl(String basePath, Object... pathFragments) { UrlMatcherSupport urlMatcher = new UrlMatcherSupport(basePath, Arrays.asList(pathFragments)); PactDslJsonRootValue value = new PactDslJsonRootValue(); value.setValue(urlMatcher.getExampleValue()); value.setMatcher(value.regexp(urlMatcher.getRegexExpression())); return value; }
/** * Value that must be encoded as a hexadecimal value */ public static PactDslJsonRootValue hexValue() { PactDslJsonRootValue value = new PactDslJsonRootValue(); value.generators.addGenerator(Category.BODY, "", new RandomHexadecimalGenerator(10)); value.setValue("1234a"); value.setMatcher(value.regexp("[0-9a-fA-F]+")); return value; }
/** * Value that must match the regular expression * @param regex regular expression * @deprecated Use the version that takes an example value */ @Deprecated public static PactDslJsonRootValue stringMatcher(String regex) { PactDslJsonRootValue rootValue = new PactDslJsonRootValue(); rootValue.generators.addGenerator(Category.BODY, "", new RegexGenerator(regex)); rootValue.setValue(new Generex(regex).random()); rootValue.setMatcher(rootValue.regexp(regex)); return rootValue; }
/** * Value that must be encoded as a hexadecimal value */ public static PactDslJsonRootValue hexValue() { PactDslJsonRootValue value = new PactDslJsonRootValue(); value.generators.addGenerator(Category.BODY, "", new RandomHexadecimalGenerator(10)); value.setValue("1234a"); value.setMatcher(value.regexp("[0-9a-fA-F]+")); return value; }
/** * Value that must match the regular expression * @param regex regular expression * @deprecated Use the version that takes an example value */ @Deprecated public static PactDslJsonRootValue stringMatcher(String regex) { PactDslJsonRootValue rootValue = new PactDslJsonRootValue(); rootValue.generators.addGenerator(Category.BODY, "", new RegexGenerator(regex)); rootValue.setValue(new Generex(regex).random()); rootValue.setMatcher(rootValue.regexp(regex)); return rootValue; }