Example usage for org.apache.commons.text RandomStringGenerator generate

List of usage examples for org.apache.commons.text RandomStringGenerator generate

Introduction

In this page you can find the example usage for org.apache.commons.text RandomStringGenerator generate.

Prototype

public String generate(final int length) 

Source Link

Document

Generates a random string, containing the specified number of code points.

Usage

From source file:mekhq.campaign.mission.Contract.java

public static String generateRandomContractName() {
    RandomStringGenerator generator = new RandomStringGenerator.Builder().withinRange('0', 'Z')
            .filteredBy(UpperCaseAndDigits.UPPERANDDIGITS).build();
    return generator.generate(15);
}

From source file:org.egov.ptis.client.util.PropertyTaxUtil.java

public String generateUserName(final String mobileNumber) {
    final StringBuilder userNameBuilder = new StringBuilder();
    String userName;/*w w w .jav  a  2s.co m*/
    if (mobileNumber.length() < 10)
        userName = String.format("%-10s", mobileNumber).replace(' ', '0');
    else
        userName = mobileNumber.substring(0, 10).replace(' ', '0');
    RandomStringGenerator generator = new RandomStringGenerator.Builder().withinRange('0', '9').build();
    userNameBuilder.append(userName).append(generator.generate(5));
    return userNameBuilder.toString();
}

From source file:org.jbb.board.impl.forum.ForumCategoryServiceIT.java

@Test(expected = ForumCategoryException.class)
public void shouldThrowForumCategoryException_whenNameLengthGreaterThan255_duringAddition() {
    // given/*from   ww w  . j  a  v  a 2s  .c  o  m*/
    RandomStringGenerator randomStringGenerator = new RandomStringGenerator.Builder()
            .filteredBy(CharacterPredicates.LETTERS).build();
    String tooLongName = randomStringGenerator.generate(256);

    // when
    forumCategoryService.addCategory(buildCategory(tooLongName));

    // then
    // throw ForumCategoryException
}

From source file:org.jbb.board.impl.forum.ForumCategoryServiceIT.java

@Test(expected = ForumCategoryException.class)
public void shouldThrowForumCategoryException_whenNameLengthGreaterThan255_duringEdit() {
    // given//  w  w w. j av  a  2  s.c  o m
    ForumCategory firstCategory = buildCategory("firstCategory");
    ForumCategoryEntity forumCategoryEntity = (ForumCategoryEntity) forumCategoryService
            .addCategory(firstCategory);
    forumCategoryService.addCategory(forumCategoryEntity);

    RandomStringGenerator randomStringGenerator = new RandomStringGenerator.Builder()
            .filteredBy(CharacterPredicates.LETTERS).build();
    String tooLongName = randomStringGenerator.generate(256);

    // when
    forumCategoryEntity.setName(tooLongName);
    forumCategoryService.editCategory(forumCategoryEntity);

    // then
    // throw ForumCategoryException
}

From source file:org.jbb.board.impl.forum.ForumServiceIT.java

@Test(expected = ForumException.class)
public void shouldThrowForumException_whenNameLengthGreaterThan255_duringAdding() throws Exception {
    // given/*from  w ww .  j av  a  2  s  .co  m*/
    String categoryName = "category";
    RandomStringGenerator randomStringGenerator = new RandomStringGenerator.Builder()
            .filteredBy(CharacterPredicates.LETTERS).build();
    String tooLongName = randomStringGenerator.generate(256);

    ForumCategory category = forumCategoryService.addCategory(buildCategory(categoryName));

    // when
    forumService.addForum(buildForum(tooLongName, null, true), category);

    // then
    // throws ForumException
}

From source file:org.jbb.board.impl.forum.ForumServiceIT.java

@Test(expected = ForumException.class)
public void shouldThrowForumException_whenNameLengthGreaterThan255_duringEdit() throws Exception {
    // given//  w w  w . ja va 2  s  .co  m
    String categoryName = "category";
    String forumName = "forum name";

    ForumCategory category = forumCategoryService.addCategory(buildCategory(categoryName));
    ForumEntity forumEntity = (ForumEntity) forumService.addForum(buildForum(forumName, null, true), category);

    // when
    RandomStringGenerator randomStringGenerator = new RandomStringGenerator.Builder()
            .filteredBy(CharacterPredicates.LETTERS).build();
    forumEntity.setName(randomStringGenerator.generate(256));
    forumService.editForum(forumEntity);

    // then
    // throws ForumException
}

From source file:org.jbb.e2e.serenity.web.forum.ForumManagementStories.java

private String getRandomString(int length) {
    RandomStringGenerator randomStringGenerator = new RandomStringGenerator.Builder()
            .filteredBy(CharacterPredicates.LETTERS).build();
    return randomStringGenerator.generate(length);
}

From source file:org.jbb.security.impl.password.PasswordPolicyManagerTest.java

@Test
public void shouldMeetCriteria_whenNoMaximumLength_andReallyLongPassword() {
    // given/* w w  w .  j  a v  a 2  s.  c om*/
    RandomStringGenerator randomStringGenerator = new RandomStringGenerator.Builder()
            .filteredBy(CharacterPredicates.LETTERS).build();
    String password = randomStringGenerator.generate(10000);
    given(propertiesMock.passwordMinimumLength()).willReturn(1);
    given(propertiesMock.passwordMaximumLength()).willReturn(Integer.MAX_VALUE);

    // when
    boolean meet = passwordPolicyManager.assertMeetCriteria(password);

    // then
    assertThat(meet).isTrue();
}

From source file:org.jbb.system.impl.logging.LoggingSettingsServiceForLoggersIT.java

private AppLogger correctAppLogger() {
    AppLogger appLogger = new AppLogger();
    appLogger.setName("org.jbb.testing");
    appLogger.setLevel(LogLevel.ERROR);/*  www  .j ava2 s.c o m*/
    appLogger.setAddivity(false);

    LogFileAppender fileAppender = correctAppender();
    RandomStringGenerator randomStringGenerator = new RandomStringGenerator.Builder()
            .filteredBy(CharacterPredicates.LETTERS).build();
    fileAppender.setName(randomStringGenerator.generate(20));
    loggingSettingsService.addAppender(fileAppender);

    appLogger.setAppenders(Lists.newArrayList(fileAppender));

    return appLogger;
}

From source file:org.jbb.system.web.logging.controller.CommonLoggingConfiguration.java

public static AppLogger correctAppLogger() {
    AppLogger appLogger = new AppLogger();
    appLogger.setName("org.jbb.testing");
    appLogger.setLevel(LogLevel.ERROR);//from ww w.ja  v  a  2 s.c o m
    appLogger.setAddivity(false);

    LogFileAppender fileAppender = correctFileAppender();
    RandomStringGenerator randomStringGenerator = new RandomStringGenerator.Builder()
            .filteredBy(CharacterPredicates.LETTERS).build();
    fileAppender.setName(randomStringGenerator.generate(20));

    appLogger.setAppenders(Lists.newArrayList(fileAppender));

    return appLogger;
}