private String generateString(String algorithm) { try { MessageDigest messageDigest = MessageDigest.getInstance(algorithm); String characters = faker.lorem().characters(); messageDigest.update(characters.getBytes(), 0, characters.length()); return new BigInteger(1, messageDigest.digest()).toString(16); } catch (NoSuchAlgorithmException noSuchAlgorithmException) { throw new RuntimeException(noSuchAlgorithmException); } }
public String fileName(String dirOrNull, String nameOrNull, String extensionOrNull, String separatorOrNull) { final String sep = separatorOrNull == null ? System.getProperty("file.separator") : separatorOrNull; final String dir = dirOrNull == null ? faker.internet().slug() : dirOrNull; final String name = nameOrNull == null ? faker.lorem().word().toLowerCase() : nameOrNull; final String ext = extensionOrNull == null ? extension() : extensionOrNull; return new StringBuilder(dir).append(sep).append(name).append(".").append(ext).toString(); } }
/** * @param wordsOrNull if null, then 2 {@link Lorem} words * @param glueOrNull if null, "_" * @return a slug string combining wordsOrNull with glueOrNull (ex. x_y) */ public String slug(List<String> wordsOrNull, String glueOrNull) { final String glue = glueOrNull == null ? "_" : glueOrNull; final List<String> words = wordsOrNull == null ? faker.lorem().words(2) : wordsOrNull; final StringBuilder slug = new StringBuilder(); for (int i = 0; i < words.size(); i++) { if (i > 0) { slug.append(glue); } slug.append(words.get(i)); } return slug.toString(); }
/** * @return a slug using '_' as the word separator and two {@link Lorem} words as the values */ public String slug() { return slug(faker.lorem().words(2), "_"); }
public String password(int minimumLength, int maximumLength, boolean includeUppercase, boolean includeSpecial) { if (includeSpecial) { char[] password = faker.lorem().characters(minimumLength, maximumLength, includeUppercase).toCharArray(); char[] special = new char[]{'!', '@', '#', '$', '%', '^', '&', '*'}; for (int i = 0; i < faker.random().nextInt(minimumLength); i++) { password[faker.random().nextInt(password.length)] = special[faker.random().nextInt(special.length)]; } return new String(password); } else { return faker.lorem().characters(minimumLength, maximumLength, includeUppercase); } }
@Override public String getRandomValue() { return faker.lorem().sentence(); } }
@Override public String getRandomValue() { return faker.lorem().paragraph(); } }
@Override public String getRandomValue() { return faker.lorem().word(); } }
@Override public String getRandomValue() { return faker.lorem().word(); } }
@Override public String getRandomValue() { return faker.lorem().paragraph(); } }
@Override public String getRandomValue() { return faker.lorem().sentence(); } }
@Override public StringArrayInput generateExampleInput() { final Faker f = new Faker(); final List<String> items = Stream.generate(() -> f.lorem().fixedString(7)) .limit(4) .collect(toList()); return new StringArrayInput(items); } }
@Override public StringInput generateExampleInput() { final String s = new Faker().lorem().sentence(2); return new StringInput(s); } }
@Override protected void run(Bootstrap<ApplicationConfig> bootstrap, Namespace namespace, ApplicationConfig applicationConfig) throws Exception { final String specId = namespace.get(SPEC_NAME_ARG); final Path specsDir = Paths.get(applicationConfig.getJobSpecConfiguration().getDir()); final Path specFile = specsDir.resolve(specId).resolve(SPEC_DIR_SPEC_FILENAME); if (specFile.toFile().exists()) { final JobSpec jobSpec = readYAML(specFile, JobSpec.class); final JobSpecId jobSpecId = new JobSpecId(specId); final String jobName = new Faker().lorem().sentence(5); final Map<JobExpectedInputId, JsonNode> generatedInputs = generateInputs(jobSpec); final APIJobRequest jobRequest = new APIJobRequest(jobSpecId, jobName, generatedInputs); System.out.println(toJSON(jobRequest)); System.exit(0); } else { System.err.println(specFile + ": No such file"); System.exit(1); } }
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(); }); }