List of usage examples for org.apache.commons.lang RandomStringUtils randomAlphabetic
public static String randomAlphabetic(int count)
Creates a random string whose length is the number of characters specified.
Characters will be chosen from the set of alphabetic characters.
From source file:datatest.TestMongoConfig.java
@Test public void testOnEmbeddedDocumentWithDifferentStructure() { //Create new Poi PoiTest poi = new PoiTest(); //Set random values poi.setName(RandomStringUtils.randomAlphabetic(10)); poi.setDescription(RandomStringUtils.randomAlphabetic(10)); //Create components list List<AbstractTestComponent> components = new LinkedList<AbstractTestComponent>(); //Create components Test1Component componentTest1 = new Test1Component(); Test2Component componentTest2 = new Test2Component(); //Set random values componentTest1.setTitle(RandomStringUtils.randomAlphabetic(10)); componentTest2.setName(RandomStringUtils.randomAlphabetic(10)); componentTest2.setSurname(RandomStringUtils.randomAlphabetic(10)); //Add components to component list components.add(componentTest2);/*from ww w .ja v a2 s .c om*/ components.add(componentTest1); //Add components to Poi poi.setComponents(components); //Insert Poi in database mongoOps.save(poi); //Retrieve Poi from database PoiTest outPoi = mongoOps.findById(poi.getId(), PoiTest.class); //Check not null assertNotNull(outPoi); //Get components List<AbstractTestComponent> outComponents = outPoi.getComponents(); //Check not null assertNotNull(outComponents); //Check size assertEquals(components.size(), outComponents.size()); //Check runtime type of single components for (AbstractTestComponent comp : outComponents) { //Check slug assertNotNull(comp.slug()); //Execute a cast based on slug value if ("test_com1".equals(comp.slug())) { //Check runtime type assertTrue(comp instanceof Test1Component); //Cast comp to Test1Component using reflection Test1Component casted = Test1Component.class.cast(comp); //Check values assertEquals(componentTest1.getTitle(), casted.getTitle()); } else if ("test_com2".equals(comp.slug())) { //Check runtime type assertTrue(comp instanceof Test2Component); //Cast comp to Test2Component using explicit casting Test2Component casted = (Test2Component) comp; //Check values assertEquals(componentTest2.getName(), casted.getName()); assertEquals(componentTest2.getSurname(), casted.getSurname()); } else { fail("unknown slug"); } } }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.api.MMXVersionResourceTest.java
public static AppEntity createRandomApp() throws Exception { String serverUserId = "serverUser"; String appName = "topictagresourcetestapp"; 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);//from w w w. j a v a 2s . 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.sjsu.crawler.util.RandomStringUtilsTest.java
/** * Test the implementation/*from w w w. ja v a 2 s. c om*/ */ @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:cgg.informatique.jfl.labo10.modeles.Token.java
/** * Generate a random salt that comply with the folowing policy * <p>The policy for a token's salt is:</p> * <ul>/* w w w . jav a2 s .co m*/ * <li><p>At least 8 chars</p></li> * <li><p>No longer than 50 chars</p></li> * </ul> * @return salt */ private static String generateRdmSalt() { int length = ThreadLocalRandom.current().nextInt(8, 50 + 1); return RandomStringUtils.randomAlphabetic(length); }
From source file:eu.scape_project.arc2warc.PayloadContent.java
public InputStream getPayloadContentAsInputStream() throws IOException { if (length >= buffer.length) { File tempDir = org.apache.commons.io.FileUtils.getTempDirectory(); final File tmp = File.createTempFile(RandomStringUtils.randomAlphabetic(10), "tmp", tempDir); tmp.deleteOnExit();/*from w w w . j av a 2s. c o m*/ FileOutputStream outputStream = null; try { outputStream = new FileOutputStream(tmp); copyAndCheck(outputStream); } finally { IOUtils.closeQuietly(outputStream); } return new FileInputStream(tmp); } else { final ByteBuffer wrap = ByteBuffer.wrap(buffer); wrap.clear(); OutputStream outStream = StreamUtils.newOutputStream(wrap); copyAndCheck(outStream); wrap.flip(); return StreamUtils.newInputStream(wrap); } }
From source file:com.haulmont.cuba.gui.components.filter.condition.DynamicAttributesCondition.java
public DynamicAttributesCondition(AbstractConditionDescriptor descriptor, String entityAlias, String propertyPath) {//from w w w. j a v a 2 s . c o m super(descriptor); this.entityAlias = entityAlias; this.name = RandomStringUtils.randomAlphabetic(10); Messages messages = AppBeans.get(Messages.class); this.locCaption = messages.getMainMessage("newDynamicAttributeCondition"); this.propertyPath = propertyPath; }
From source file:com.sourcesense.alfresco.opensso.integration.WebClientSSOIntegrationTest.java
@Test public void testDisplayNonEnglishChars() throws Exception { logoutFromOpenSSODomain();/*from w ww. ja v a 2 s . com*/ loginToOpenSSOConsoleAsAmAdmin(); createUserWithLoginAndPass("opensso1"); logoutFromOpenSSODomain(); loginToAlfrescoAs("opensso1", "opensso1"); selenium.click("link=Create a space in your home space"); selenium.waitForPageToLoad("40000"); String i18nText = "Aviao Civil-".concat(RandomStringUtils.randomAlphabetic(5)); selenium.type("dialog:dialog-body:name", i18nText); selenium.click("dialog:finish-button"); selenium.waitForPageToLoad("40000"); selenium.click("link=My Home"); selenium.waitForPageToLoad("40000"); assertTrue(selenium.isTextPresent(i18nText)); }
From source file:com.btoddb.chronicle.catchers.RestCatcherImplTest.java
@Test public void testIsJsonArrayTooMuchWhitespace() { RestCatcherImpl restEndpoint = new RestCatcherImpl(); assertThat(restEndpoint.isJsonArray( new ByteArrayInputStream(RandomStringUtils.randomAlphabetic(120).getBytes())), is(false)); }
From source file:mitm.common.security.certificate.X509CertificateBuilderBulkTest.java
private String generateRandomEmail() { return RandomStringUtils.randomAlphabetic(10) + "@example.com"; }
From source file:com.linkedin.paldb.TestReadThrouputRocksDB.java
private Measure measure(int keysCount, int valueLength, double cacheSizeRatio, final boolean frequentReads) { // Generate keys long seed = 4242; final Integer[] keys = GenerateTestData.generateRandomIntKeys(keysCount, Integer.MAX_VALUE, seed); // Write store File file = new File(TEST_FOLDER, "rocksdb" + keysCount + "-" + valueLength + ".store"); Options options = new Options(); options.setCreateIfMissing(true);/*from w w w .j a va 2 s.c o m*/ options.setAllowMmapWrites(false); options.setAllowMmapReads(true); options.setCompressionType(CompressionType.NO_COMPRESSION); options.setCompactionStyle(CompactionStyle.LEVEL); options.setMaxOpenFiles(-1); final BlockBasedTableConfig tableOptions = new BlockBasedTableConfig(); tableOptions.setFilter(new BloomFilter(10, false)); options.setTableFormatConfig(tableOptions); RocksDB db = null; try { db = RocksDB.open(options, file.getAbsolutePath()); for (Integer key : keys) { if (valueLength == 0) { db.put(key.toString().getBytes(), "1".getBytes()); } else { db.put(key.toString().getBytes(), RandomStringUtils.randomAlphabetic(valueLength).getBytes()); } } } catch (RocksDBException e) { throw new RuntimeException(e); } finally { if (db != null) { db.close(); } } options.dispose(); final ReadOptions readOptions = new ReadOptions(); readOptions.setVerifyChecksums(false); // Open NanoBench nanoBench = NanoBench.create(); try { options = new Options(); options.setAllowMmapWrites(false); options.setAllowMmapReads(true); options.setCompressionType(CompressionType.NO_COMPRESSION); options.setCompactionStyle(CompactionStyle.LEVEL); options.setMaxOpenFiles(-1); options.setTableFormatConfig(tableOptions); db = RocksDB.open(options, file.getAbsolutePath()); final RocksDB reader = db; // Measure nanoBench.cpuOnly().warmUps(5).measurements(20).measure("Measure %d reads for %d keys with cache", new Runnable() { @Override public void run() { Random r = new Random(); int length = keys.length; for (int i = 0; i < READS; i++) { int index; if (i % 2 == 0 && frequentReads) { index = r.nextInt(length / 10); } else { index = r.nextInt(length); } Integer key = keys[index]; try { reader.get(readOptions, key.toString().getBytes()); } catch (RocksDBException e) { } } } }); } catch (RocksDBException e) { throw new RuntimeException(e); } finally { if (db != null) { db.close(); } } // Return measure double rps = READS * nanoBench.getTps(); return new Measure(DirectoryUtils.folderSize(TEST_FOLDER), rps, valueLength, 0l, keys.length); }