/** * Generates a String that matches the given regular expression. */ public String regexify(String regex) { Generex generex = new Generex(regex); generex.setSeed(randomService.nextLong()); return generex.random(); }
} else if (EXPRESSION.equals(parameter.getGenerate())) { Generex generex = new Generex(parameter.getFrom()); value = generex.random(); } else if (failOnMissing) { throw new IllegalArgumentException("No value available for parameter name: " + name);
@Override public String generate( SourceOfRandomness r, GenerationStatus s) { Generex regex = new Generex( matching != null ? matching.value() : ".*", r.toJDKRandom()); return regex.random(0, s.size()); }
} else if (EXPRESSION.equals(parameter.getGenerate())) { Generex generex = new Generex(parameter.getFrom()); parameterValue = generex.random(); } else if (parameter.getRequired() == null || !parameter.getRequired()) { parameterValue = "";
/** * Match a request header. A random example header value will be generated from the provided regular expression. * * @param header Header to match * @param regex Regular expression to match */ public PactDslRequestWithPath matchHeader(String header, String regex) { return matchHeader(header, regex, new Generex(regex).random()); }
/** * Match a query parameter with a regex. A random query parameter value will be generated from the regex. * * @param parameter Query parameter * @param regex Regular expression to match with */ public PactDslRequestWithPath matchQuery(String parameter, String regex) { return matchQuery(parameter, regex, new Generex(regex).random()); }
/** * The path of the request. This will generate a random path to use when generating requests * * @param pathRegex string path regular expression to match with */ public PactDslRequestWithPath matchPath(String pathRegex) { return matchPath(pathRegex, new Generex(pathRegex).random()); }
/** * The path of the request. This will generate a random path to use when generating requests * * @param pathRegex string path regular expression to match with */ public PactDslRequestWithPath matchPath(String pathRegex) { return matchPath(pathRegex, new Generex(pathRegex).random()); }
/** * Match a request header. A random example header value will be generated from the provided regular expression. * * @param header Header to match * @param regex Regular expression to match */ public PactDslRequestWithPath matchHeader(String header, String regex) { return matchHeader(header, regex, new Generex(regex).random()); }
/** * Generate data according to given regular expression. * * @return Generated value */ @Override public String generateAttribute() { Generex generex = new Generex(regexBasedAttrConfig.getPattern()); return generex.random(); // return null; }
/** * The path of the request. This will generate a random path to use when generating requests * * @param pathRegex string path regular expression to match with */ public PactDslRequestWithPath matchPath(String pathRegex) { return matchPath(pathRegex, new Generex(pathRegex).random()); }
/** * The path of the request. This will generate a random path to use when generating requests * * @param pathRegex string path regular expression to match with */ public PactDslRequestWithPath matchPath(String pathRegex) { return matchPath(pathRegex, new Generex(pathRegex).random()); }
/** * Match a response header. A random example header value will be generated from the provided regular expression. * * @param header Header to match * @param regexp Regular expression to match */ public PactDslResponse matchHeader(String header, String regexp) { return matchHeader(header, regexp, new Generex(regexp).random()); }
/** * Match a response header. A random example header value will be generated from the provided regular expression. * * @param header Header to match * @param regexp Regular expression to match */ public PactDslResponse matchHeader(String header, String regexp) { return matchHeader(header, regexp, new Generex(regexp).random()); }
/** * Attribute that must match the regular expression * @param name attribute name * @param regex regular expression * @deprecated Use the version that takes an example value */ @Deprecated public PactDslJsonBody stringMatcher(String name, String regex) { generators.addGenerator(Category.BODY, matcherKey(name), new RegexGenerator(regex)); stringMatcher(name, regex, new Generex(regex).random()); return this; }
/** * Attribute that must match the regular expression * @param name attribute name * @param regex regular expression * @deprecated Use the version that takes an example value */ @Deprecated public PactDslJsonBody stringMatcher(String name, String regex) { generators.addGenerator(Category.BODY, matcherKey(name), new RegexGenerator(regex)); stringMatcher(name, regex, new Generex(regex).random()); return this; }
/** * Element that must match the regular expression * @param regex regular expression * @deprecated Use the version that takes an example value */ @Deprecated public PactDslJsonArray stringMatcher(String regex) { generators.addGenerator(Category.BODY, rootPath + appendArrayIndex(1), new RandomStringGenerator(10)); stringMatcher(regex, new Generex(regex).random()); return this; }
/** * Element that must match the regular expression * @param regex regular expression * @deprecated Use the version that takes an example value */ @Deprecated public PactDslJsonArray stringMatcher(String regex) { generators.addGenerator(Category.BODY, rootPath + appendArrayIndex(1), new RandomStringGenerator(10)); stringMatcher(regex, new Generex(regex).random()); return this; }
/** * Value that must match the regular expression * @param regex regular expression * @deprecated Use the version that takes an example value */ @Deprecated public static PactDslRootValue stringMatcher(String regex) { PactDslRootValue rootValue = new PactDslRootValue(); rootValue.generators.addGenerator(Category.BODY, "", new RegexGenerator(regex)); rootValue.setValue(new Generex(regex).random()); rootValue.setMatcher(rootValue.regexp(regex)); return rootValue; }
protected DataProvider collectStringProperty(Swagger swagger, StringProperty schema, boolean clean) { return gen(() -> { StringProperty.Format uriFormat = StringProperty.Format.fromName(schema.getFormat()); if (uriFormat == StringProperty.Format.URI || uriFormat == StringProperty.Format.URL) return faker.internet().url(); else if (!isEmpty(schema.getPattern())) { Generex generex = new Generex(schema.getPattern()); return generex.random(); } else return faker.lorem().word(); }); }