Example usage for org.apache.commons.lang RandomStringUtils randomAlphanumeric

List of usage examples for org.apache.commons.lang RandomStringUtils randomAlphanumeric

Introduction

In this page you can find the example usage for org.apache.commons.lang RandomStringUtils randomAlphanumeric.

Prototype

public static String randomAlphanumeric(int count) 

Source Link

Document

Creates a random string whose length is the number of characters specified.

Characters will be chosen from the set of alpha-numeric characters.

Usage

From source file:com.redhat.rhn.manager.satellite.ConfigureCertificateCommand.java

protected void writeStringToFile() throws FileNotFoundException {
    String tmpDir = System.getProperty("java.io.tmpdir");

    this.certificateFileName = tmpDir + "/cert_text" + RandomStringUtils.randomAlphanumeric(13) + ".cert";

    FileOutputStream out = new FileOutputStream(this.certificateFileName);
    PrintStream printer = new PrintStream(out);
    try {/*from w w w. java  2s  .  c  o  m*/
        printer.println(this.certificateText);
    } finally {
        printer.close();
    }
}

From source file:at.ac.tuwien.ims.latex2mobiformulaconv.tests.integration.EndToEndConversionTest.java

@Before
public void setUp() throws Exception {
    workingDirectory = TestUtils.getWorkingDirectory(this.getClass());
    logger.info("Working directory: " + workingDirectory.toAbsolutePath().toString());

    converter.setWorkingDirectory(workingDirectory);
    title = RandomStringUtils.randomAlphanumeric(64);
    logger.debug("Random title: " + title);

    inputPaths = new ArrayList<>();
    inputPaths.add(workingDirectory.resolve(Paths.get(inputFilename)));

    outputPath = workingDirectory.resolve("..");
    outputFilePath = outputPath.resolve(filename + ext);
    Files.deleteIfExists(outputFilePath);
}

From source file:com.example.bigtable.simpleperf.WritePerfTest.java

protected static void doPut(BufferedMutator mutator, byte[] value) throws IOException {
    byte[] key = Bytes.toBytes(RandomStringUtils.randomAlphanumeric(10));
    mutator.mutate(new Put(key, System.currentTimeMillis()).addColumn(BigtableUtilities.FAMILY,
            BigtableUtilities.QUALIFIER, value));
}

From source file:com.xtructure.xutil.id.UTestXId.java

public void getBaseReturnsExpectedString() {
    assertThat("", //
            XId.newId().getBase(), matches(UUID_REGEX));
    String idString = RandomStringUtils.randomAlphanumeric(20);
    assertThat("", //
            XId.newId(idString).getBase(), matches(idString));
}

From source file:com.flexive.tests.embedded.SequencerTest.java

@Test
public void customSequencer() throws Exception {
    List<CustomSequencer> startList = id.getCustomSequencers();
    String seq1 = "A" + RandomStringUtils.randomAlphanumeric(16).toUpperCase();
    String seq2 = "B" + RandomStringUtils.randomAlphanumeric(16).toUpperCase();
    String seq3 = "C" + RandomStringUtils.randomAlphanumeric(16).toUpperCase();
    id.createSequencer(seq1, true, 0);/*from  w  w w. j a v  a 2 s .  c o  m*/
    id.createSequencer(seq2, true, id.getMaxId());
    id.createSequencer(seq3, false, id.getMaxId());
    Assert.assertTrue(id.sequencerExists(seq1), "Expected sequencer " + seq1 + " to exist!");
    Assert.assertTrue(id.sequencerExists(seq2), "Expected sequencer " + seq2 + " to exist!");
    Assert.assertTrue(id.sequencerExists(seq3), "Expected sequencer " + seq3 + " to exist!");
    Assert.assertTrue(id.getCustomSequencerNames().contains(seq1));
    Assert.assertTrue(id.getCustomSequencerNames().contains(seq2));
    Assert.assertTrue(id.getCustomSequencerNames().contains(seq3));
    long i1 = id.getId(seq1);
    Assert.assertEquals(i1, 1);
    long i2 = id.getId(seq1);
    Assert.assertTrue(i2 > i1, "Expected a higher id after 2nd getId()!");
    i1 = id.getId(seq2); //call should cause the sequencer to roll over
    Assert.assertEquals(i1, 0, "Expected: " + 0 + ", got: " + i1);
    i1 = id.getId(seq2); //should be 1 after rollover
    Assert.assertEquals(i1, 1, "Expected: " + 1 + ", got: " + i1);
    Assert.assertTrue(i1 <= id.getCurrentId(seq2),
            "Expected " + i1 + " of " + seq2 + " to be <= " + id.getCurrentId(seq2));
    try {
        id.getId(seq3);
        Assert.fail("Expected an exception since seq3 should be exhausted!");
    } catch (FxApplicationException e) {
        //expected
    }

    List<CustomSequencer> g2 = id.getCustomSequencers();
    g2.removeAll(startList);
    Assert.assertTrue(g2.size() == 3, "Expected a size of 3, but got " + g2.size());
    Assert.assertTrue(g2.get(0).getName().equals(seq1), "Expected " + seq1 + " got " + g2.get(0).getName());
    Assert.assertTrue(g2.get(1).getName().equals(seq2), "Expected " + seq2 + " got " + g2.get(1).getName());
    Assert.assertTrue(g2.get(2).getName().equals(seq3), "Expected " + seq3 + " got " + g2.get(2).getName());
    Assert.assertTrue(g2.get(0).isAllowRollover());
    Assert.assertTrue(g2.get(1).isAllowRollover());
    Assert.assertFalse(g2.get(2).isAllowRollover());
    id.removeSequencer(seq1);
    id.removeSequencer(seq2);
    id.removeSequencer(seq3);
    Assert.assertTrue(id.getCustomSequencers().size() == startList.size());
    Assert.assertFalse(id.getCustomSequencerNames().contains(seq1));
    Assert.assertFalse(id.getCustomSequencerNames().contains(seq2));
    Assert.assertFalse(id.getCustomSequencerNames().contains(seq3));
}

From source file:com.sjsu.crawler.util.RandomStringUtilsTest.java

/**
 * Test the implementation/*  w  w  w .  j  a  v a 2s . co m*/
 */
@Test
public void testRandomStringUtils() {
    String r1 = RandomStringUtils.random(50);
    assertEquals("random(50) length", 50, r1.length());
    String r2 = RandomStringUtils.random(50);
    assertEquals("random(50) length", 50, r2.length());
    assertTrue("!r1.equals(r2)", !r1.equals(r2));

    r1 = RandomStringUtils.randomAscii(50);
    assertEquals("randomAscii(50) length", 50, r1.length());
    for (int i = 0; i < r1.length(); i++) {
        assertTrue("char between 32 and 127", r1.charAt(i) >= 32 && r1.charAt(i) <= 127);
    }
    r2 = RandomStringUtils.randomAscii(50);
    assertTrue("!r1.equals(r2)", !r1.equals(r2));

    r1 = RandomStringUtils.randomAlphabetic(50);
    assertEquals("randomAlphabetic(50)", 50, r1.length());
    for (int i = 0; i < r1.length(); i++) {
        assertTrue("r1 contains alphabetic",
                Character.isLetter(r1.charAt(i)) && !Character.isDigit(r1.charAt(i)));
    }
    r2 = RandomStringUtils.randomAlphabetic(50);
    assertTrue("!r1.equals(r2)", !r1.equals(r2));

    r1 = RandomStringUtils.randomAlphanumeric(50);
    assertEquals("randomAlphanumeric(50)", 50, r1.length());
    for (int i = 0; i < r1.length(); i++) {
        assertTrue("r1 contains alphanumeric", Character.isLetterOrDigit(r1.charAt(i)));
    }
    r2 = RandomStringUtils.randomAlphabetic(50);
    assertTrue("!r1.equals(r2)", !r1.equals(r2));

    r1 = RandomStringUtils.randomNumeric(50);
    assertEquals("randomNumeric(50)", 50, r1.length());
    for (int i = 0; i < r1.length(); i++) {
        assertTrue("r1 contains numeric", Character.isDigit(r1.charAt(i)) && !Character.isLetter(r1.charAt(i)));
    }
    r2 = RandomStringUtils.randomNumeric(50);
    assertTrue("!r1.equals(r2)", !r1.equals(r2));

    String set = "abcdefg";
    r1 = RandomStringUtils.random(50, set);
    assertEquals("random(50, \"abcdefg\")", 50, r1.length());
    for (int i = 0; i < r1.length(); i++) {
        assertTrue("random char in set", set.indexOf(r1.charAt(i)) > -1);
    }
    r2 = RandomStringUtils.random(50, set);
    assertTrue("!r1.equals(r2)", !r1.equals(r2));

    r1 = RandomStringUtils.random(50, (String) null);
    assertEquals("random(50) length", 50, r1.length());
    r2 = RandomStringUtils.random(50, (String) null);
    assertEquals("random(50) length", 50, r2.length());
    assertTrue("!r1.equals(r2)", !r1.equals(r2));

    set = "stuvwxyz";
    r1 = RandomStringUtils.random(50, set.toCharArray());
    assertEquals("random(50, \"stuvwxyz\")", 50, r1.length());
    for (int i = 0; i < r1.length(); i++) {
        assertTrue("random char in set", set.indexOf(r1.charAt(i)) > -1);
    }
    r2 = RandomStringUtils.random(50, set);
    assertTrue("!r1.equals(r2)", !r1.equals(r2));

    r1 = RandomStringUtils.random(50, (char[]) null);
    assertEquals("random(50) length", 50, r1.length());
    r2 = RandomStringUtils.random(50, (char[]) null);
    assertEquals("random(50) length", 50, r2.length());
    assertTrue("!r1.equals(r2)", !r1.equals(r2));

    final long seed = System.currentTimeMillis();
    r1 = RandomStringUtils.random(50, 0, 0, true, true, null, new Random(seed));
    r2 = RandomStringUtils.random(50, 0, 0, true, true, null, new Random(seed));
    assertEquals("r1.equals(r2)", r1, r2);

    r1 = RandomStringUtils.random(0);
    assertEquals("random(0).equals(\"\")", "", r1);
}

From source file:net.przemkovv.sphinx.executor.SimpleExecutorEchoNGTest.java

@Test()
public void testExecuteEcho() throws Exception {
    SimpleExecutor instance;/*from  ww w .  ja  va  2s .  c om*/
    instance = new SimpleExecutor(executable, prepare_env);
    List<String> input = new ArrayList<>();
    input.add(RandomStringUtils.randomAlphanumeric(16));
    ExecutionResult result = instance.execute(input);
    assertEquals(result.exit_value, 0);
    assertTrue(result.output_error.isEmpty(), "Invalid output error.");
    assertEquals(result.output, input, "Invalid output.");

}

From source file:com.linkedin.pinot.perf.StringDictionaryPerfTest.java

/**
 * Helper method to build a segment:// ww  w  . j a  va 2s . c o  m
 * <ul>
 *   <li> Segment contains one string column </li>
 *   <li> Row values for the column are randomly generated strings of length 1 to 100 </li>
 * </ul>
 *
 * @param dictLength Length of the dictionary
 * @throws Exception
 */
public void buildSegment(int dictLength) throws Exception {
    Schema schema = new Schema();
    String segmentName = "perfTestSegment" + System.currentTimeMillis();
    _indexDir = new File(TMP_DIR + File.separator + segmentName);
    _indexDir.deleteOnExit();

    FieldSpec fieldSpec = new DimensionFieldSpec(COLUMN_NAME, FieldSpec.DataType.STRING, true);
    schema.addField(fieldSpec);

    _dictLength = dictLength;
    _inputStrings = new String[dictLength];

    SegmentGeneratorConfig config = new SegmentGeneratorConfig(schema);
    config.setOutDir(_indexDir.getParent());
    config.setFormat(FileFormat.AVRO);
    config.setSegmentName(segmentName);

    Random random = new Random(System.nanoTime());
    final List<GenericRow> data = new ArrayList<>();
    Set<String> uniqueStrings = new HashSet<>(dictLength);

    int i = 0;
    while (i < dictLength) {
        HashMap<String, Object> map = new HashMap<>();
        String randomString = RandomStringUtils.randomAlphanumeric(1 + random.nextInt(MAX_STRING_LENGTH));

        if (uniqueStrings.contains(randomString)) {
            continue;
        }

        _inputStrings[i] = randomString;
        uniqueStrings.add(randomString);
        map.put("test", _inputStrings[i++]);

        GenericRow genericRow = new GenericRow();
        genericRow.init(map);
        data.add(genericRow);
    }

    SegmentIndexCreationDriverImpl driver = new SegmentIndexCreationDriverImpl();
    RecordReader reader = getGenericRowRecordReader(schema, data);
    driver.init(config, reader);
    driver.build();
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.api.tags.MMXDeviceTagsResourceTest.java

public static AppEntity createRandomApp() throws Exception {

    String serverUserId = "serverUser";
    String appName = "devicetagresourcetestapp";
    String appId = RandomStringUtils.randomAlphanumeric(10);
    String apiKey = UUID.randomUUID().toString();
    String googleApiKey = UUID.randomUUID().toString();
    String googleProjectId = RandomStringUtils.randomAlphanumeric(8);
    String apnsPwd = RandomStringUtils.randomAlphanumeric(10);
    String ownerId = RandomStringUtils.randomAlphabetic(10);
    String ownerEmail = RandomStringUtils.randomAlphabetic(4) + "@magnet.com";
    String guestSecret = RandomStringUtils.randomAlphabetic(10);
    boolean apnsProductionEnvironment = false;

    AppEntity appEntity = new AppEntity();
    appEntity.setServerUserId(serverUserId);
    appEntity.setName(appName);/*ww w  .j  a v a  2  s .  c o m*/
    appEntity.setAppId(appId);
    appEntity.setAppAPIKey(apiKey);
    appEntity.setGoogleAPIKey(googleApiKey);
    appEntity.setGoogleProjectId(googleProjectId);
    appEntity.setApnsCertPassword(apnsPwd);
    appEntity.setOwnerId(ownerId);
    appEntity.setOwnerEmail(ownerEmail);
    appEntity.setGuestSecret(guestSecret);
    appEntity.setApnsCertProduction(apnsProductionEnvironment);
    DBTestUtil.getAppDAO().persist(appEntity);
    return appEntity;
}

From source file:com.xtructure.xutil.xml.UTestXmlUnit.java

public void getNameReturnsExpectedString() {
    String name = RandomStringUtils.randomAlphanumeric(10);
    assertThat("", //
            XmlUnit.newAttribute(name).getName(), isEqualTo(name));
    assertThat("", //
            XmlUnit.newAttribute(name, Double.class).getName(), isEqualTo(name));
    assertThat("", //
            XmlUnit.newElement(name).getName(), isEqualTo(name));
    assertThat("", //
            XmlUnit.newElement(name, Double.class).getName(), isEqualTo(name));
}