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:mitm.common.security.certificate.X509CertificateBuilderBulkTest.java
private String generateRandomCommonName() { return RandomStringUtils.randomAlphabetic(10) + " " + RandomStringUtils.randomAlphabetic(10); }
From source file:eu.scape_project.up2ti.container.ArcContainer.java
/** * Create temporary files and create bidirectional file-record map. * * @throws IOException IO Error/*from ww w. j a va 2 s . c o m*/ */ private void arcRecContentsToTempFiles() throws IOException { extractDirectoryName = "/tmp/up2ti_" + RandomStringUtils.randomAlphabetic(10) + "/"; File destDir = new File(extractDirectoryName); destDir.mkdir(); Iterator<ArcRecordBase> recordIterator = reader.iterator(); try { // K: Record key V: Temporary file while (recordIterator.hasNext()) { ArcRecordBase arcRecord = recordIterator.next(); String archiveDateStr = arcRecord.getArchiveDateStr(); archiveRecords.add(arcRecord); String recordIdentifier = arcRecord.getUrlStr(); String recordKey = containerFileName + "/" + archiveDateStr + "/" + recordIdentifier; if (arcRecord.hasPayload() && arcRecord.getPayload().getRemaining() < Integer.MAX_VALUE) { File tmpFile = IOUtils.copyStreamToTempFileInDir(arcRecord.getPayloadContent(), extractDirectoryName, ".tmp"); this.put(recordKey, tmpFile.getAbsolutePath()); } } } catch (RuntimeException ex) { LOG.error("ARC reader error, skipped.", ex); } }
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);//from www . j av a 2 s . co 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.comcast.viper.flume2storm.connection.KryoNetConnectionParametersTest.java
/** * Test {@link KryoNetConnectionParameters} using the default constructor * //w w w . j a v a 2s . co m * @throws F2SConfigurationException * If the configuration is invalid */ @Test public void testFromScratch() throws F2SConfigurationException { KryoNetConnectionParameters params = new KryoNetConnectionParameters(); String strValue = RandomStringUtils.randomAlphabetic(10); params.setAddress(strValue); Assert.assertEquals(strValue, params.getAddress()); int value = TestUtils.getRandomPositiveInt(65000); params.setServerPort(value); Assert.assertEquals(value, params.getPort()); value = TestUtils.getRandomPositiveInt(100000); params.setObjectBufferSize(value); Assert.assertEquals(value, params.getObjectBufferSize()); value = TestUtils.getRandomPositiveInt(100000); params.setWriteBufferSize(value); Assert.assertEquals(value, params.getWriteBufferSize()); }
From source file:com.datastax.example.PreparedVsNonPreparedStatement.java
public void test2() { Random rnd = new Random(); final File file = new File("/Users/patrick/projects/PreparedVsNonPreparedStatement.csv"); final CsvReporter reporter = CsvReporter.forRegistry(metrics).formatFor(Locale.US) .convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS) .build(new File("/Users/patrick/projects/")); logger.info("Beginning PreparedVsNonPreparedStatement:Test2"); PreparedStatement userInsertStatement = session.prepare( "insert into users (id, firstname, lastname, street, post_code, phone) VALUES (?, ?, ?, ?, ?, ?)"); BoundStatement userInsert = new BoundStatement(userInsertStatement); reporter.start(1, TimeUnit.SECONDS); //Insert 10000 for (int i = 1000000; i < 2000000; i++) { String firstName = RandomStringUtils.randomAlphabetic(10); String lastName = RandomStringUtils.randomAlphabetic(10); String street = RandomStringUtils.randomAlphabetic(8); int post_code = rnd.nextInt(99999); int phone = rnd.nextInt(99999999); final Timer.Context context = test2.time(); session.execute(userInsert.bind(i, firstName, lastName, street, post_code, phone)); context.stop();/*ww w . java 2 s. c om*/ } logger.info("Completed PreparedVsNonPreparedStatement:Test2"); }
From source file:edu.cornell.med.icb.goby.alignments.TestAlignmentReader.java
/** * Validate that the method/*from w w w . j av a 2 s . c om*/ * {@link AlignmentReaderImpl#getBasename(String)} * produces the proper results. */ @Test public void basename() { assertNull("Basename should be null", AlignmentReaderImpl.getBasename(null)); assertEquals("Basename should be unchanged", "", AlignmentReaderImpl.getBasename("")); assertEquals("Basename should be unchanged", "foobar", AlignmentReaderImpl.getBasename("foobar")); assertEquals("Basename should be unchanged", "foobar.txt", AlignmentReaderImpl.getBasename("foobar.txt")); for (final String extension : FileExtensionHelper.COMPACT_ALIGNMENT_FILE_EXTS) { final String basename = RandomStringUtils.randomAlphabetic(8); final String filename = basename + extension; assertEquals("Basename not stripped properly from '" + filename + "'", basename, AlignmentReaderImpl.getBasename(basename)); } assertEquals("Only the extension should have been removed", "foo.entries.bar", AlignmentReaderImpl.getBasename("foo.entries.bar.entries")); assertEquals("Only the extension should have been removed", "entries.foo.bar", AlignmentReaderImpl.getBasename("entries.foo.bar.entries")); }
From source file:com.b2international.index.OffsetLimitTest.java
public void testOffsetLimit() throws Exception { Map<String, Data> documents = newTreeMap(); for (int i = 0; i < NUM_DOCS; i++) { String item = null;/*from w ww . j av a2s . c om*/ while (item == null || documents.keySet().contains(item)) { item = RandomStringUtils.randomAlphabetic(10); } final Data data = new Data(); data.setField1(item); documents.put(item, data); } indexDocuments(documents); final Query<Data> ascendingQuery = Query.select(Data.class).where(Expressions.matchAll()) // .offset(offset) .limit(limit).sortBy(SortBy.field("field1", Order.ASC)).build(); final Hits<Data> ascendingHits = search(ascendingQuery); final String[] ascendingFields = FluentIterable.from(ascendingHits).transform(data -> data.getField1()) .toArray(String.class); assertEquals(expectedDocs, ascendingFields.length); final String[] expectedFields = FluentIterable.from(documents.keySet()).skip(offset).limit(limit) .toArray(String.class); assertArrayEquals(expectedFields, ascendingFields); }
From source file:com.b2international.index.ScrollTest.java
private void indexDocs(int numberOfDocs) { final Map<String, Data> docsToIndex = newHashMap(); for (int i = 0; i < numberOfDocs; i++) { Data doc = new Data(); doc.setAnalyzedField(RandomStringUtils.randomAlphabetic(20)); doc.setField1("field1" + i); doc.setFloatField(rnd.nextFloat()); doc.setIntField(rnd.nextInt());//from w w w . jav a 2 s. co m docsToIndex.put("key" + i, doc); } indexDocuments(docsToIndex); }
From source file:com.thebodgeitstore.selenium.tests.FunctionalTest.java
public void tstRegisterAndLoginUser() { // Create random username so we can rerun test String randomUser = RandomStringUtils.randomAlphabetic(10) + "@test.com"; this.registerUser(randomUser, "password"); assertTrue(driver.getPageSource().indexOf("You have successfully registered with The BodgeIt Store.") > 0); checkMenu("Logout", "logout.jsp"); this.loginUser(randomUser, "password"); assertTrue(driver.getPageSource().indexOf("You have logged in successfully:") > 0); }
From source file:eu.scape_project.tpid.ContainerProcessing.java
/** * Prepare input/*from ww w. ja va 2 s. c o m*/ * * @param pt * @throws IOException IO Error * @throws java.lang.InterruptedException */ public void prepareInput(Path pt) throws InterruptedException, IOException { FileSystem fs = FileSystem.get(context.getConfiguration()); InputStream containerFileStream = fs.open(pt); String containerFileName = pt.getName(); ArcReader reader; // Read first two bytes to check if we have a gzipped input stream PushbackInputStream pb = new PushbackInputStream(containerFileStream, 2); byte[] signature = new byte[2]; pb.read(signature); pb.unread(signature); // use compressed reader if gzip magic number is matched if (signature[0] == (byte) 0x1f && signature[1] == (byte) 0x8b) { reader = ArcReaderFactory.getReaderCompressed(pb); } else { reader = ArcReaderFactory.getReaderUncompressed(pb); } long currTM = System.currentTimeMillis(); String unpackHdfsPath = conf.get("unpack_hdfs_path", "tpid_unpacked"); String hdfsUnpackDirStr = StringUtils.normdir(unpackHdfsPath, Long.toString(currTM)); String hdfsJoboutputPath = conf.get("tooloutput_hdfs_path", "tpid_tooloutput"); String hdfsOutputDirStr = StringUtils.normdir(hdfsJoboutputPath, Long.toString(currTM)); Iterator<ArcRecordBase> arcIterator = reader.iterator(); // Number of files which should be processed per invokation int numItemsPerInvocation = conf.getInt("num_items_per_task", 50); int numItemCounter = numItemsPerInvocation; // List of input files to be processed String inliststr = ""; // List of output files to be generated String outliststr = ""; try { while (arcIterator.hasNext()) { ArcRecordBase arcRecord = arcIterator.next(); String recordKey = getRecordKey(arcRecord, containerFileName); String outFileName = RandomStringUtils.randomAlphabetic(25); String hdfsPathStr = hdfsUnpackDirStr + outFileName; Path hdfsPath = new Path(hdfsPathStr); String outputFileSuffix = conf.get("output_file_suffix", ".fits.xml"); String hdfsOutPathStr = hdfsOutputDirStr + outFileName + outputFileSuffix; FSDataOutputStream hdfsOutStream = fs.create(hdfsPath); ArcUtils.recordToOutputStream(arcRecord, hdfsOutStream); Text key = new Text(recordKey); Text value = new Text(fs.getHomeDirectory() + File.separator + hdfsOutPathStr); mos.write("keyfilmapping", key, value); String scapePlatformInvoke = conf.get("scape_platform_invoke", "fits dirxml"); Text ptmrkey = new Text(scapePlatformInvoke); // for the configured number of items per invokation, add the // files to the input and output list of the command. inliststr += "," + fs.getHomeDirectory() + File.separator + hdfsPathStr; outliststr += "," + fs.getHomeDirectory() + File.separator + hdfsOutPathStr; if (numItemCounter > 1 && arcIterator.hasNext()) { numItemCounter--; } else if (numItemCounter == 1 || !arcIterator.hasNext()) { inliststr = inliststr.substring(1); // cut off leading comma outliststr = outliststr.substring(1); // cut off leading comma String pattern = conf.get("tomar_param_pattern", "%1$s %2$s"); String ptMrStr = StringUtils.formatCommandOutput(pattern, inliststr, outliststr); Text ptmrvalue = new Text(ptMrStr); // emit tomar input line where the key is the tool invokation // (tool + operation) and the value is the parameter list // where input and output strings contain file lists. mos.write("tomarinput", ptmrkey, ptmrvalue); numItemCounter = numItemsPerInvocation; inliststr = ""; outliststr = ""; } } } catch (Exception ex) { mos.write("error", new Text("Error"), new Text(pt.toString())); } }