List of usage examples for org.apache.commons.lang RandomStringUtils randomAlphanumeric
public static String randomAlphanumeric(int count)
Creates a random string whose length is the number of characters specified.
Characters will be chosen from the set of alpha-numeric characters.
From source file:com.flexive.core.stream.BinaryUploadProtocol.java
/** * {@inheritDoc}/*from www.ja va 2 s .c om*/ */ @Override public DataPacket<BinaryUploadPayload> processPacket(DataPacket<BinaryUploadPayload> dataPacket) throws StreamException { if (dataPacket.isExpectResponse() && !this.protoInit) { this.protoInit = true; this.timeToLive = dataPacket.getPayload().getTimeToLive(); this.expectedLength = dataPacket.getPayload().getExpectedLength(); if (LOG.isDebugEnabled()) LOG.debug("Receive started at " + new Date(System.currentTimeMillis())); this.handle = RandomStringUtils.randomAlphanumeric(32); this.mimeType = dataPacket.getPayload().getMimeType(); this.division = dataPacket.getPayload().getDivision(); if (this.expectedLength == 0) { //create an empty transit entry try { pout = getContentStorage().receiveTransitBinary(division, handle, mimeType, expectedLength, timeToLive); } catch (Exception e) { LOG.error(e); } } return new DataPacket<BinaryUploadPayload>(new BinaryUploadPayload(handle, this.mimeType), false, this.expectedLength > 0 || this.expectedLength == -1L); } else { cleanup(); } return null; }
From source file:net.nelz.simplesm.aop.ReadThroughMultiCacheTest.java
@Test public void testInitialKey2Result() { final AnnotationData annotation = new AnnotationData(); annotation.setNamespace(RandomStringUtils.randomAlphanumeric(6)); final Map<String, Object> expectedString2Object = new HashMap<String, Object>(); final Map<String, Object> key2Result = new HashMap<String, Object>(); final Set<Object> missObjects = new HashSet<Object>(); final int length = 15; for (int ix = 0; ix < length; ix++) { final String object = RandomStringUtils.randomAlphanumeric(2 + ix); final String key = cut.buildCacheKey(object, annotation); expectedString2Object.put(key, object); // There are 3 possible outcomes when fetching by key from memcached: // 0) You hit, and the key & result are in the map // 1) You hit, but the result is null, which counts as a miss. // 2) You miss, and the key doesn't even get into the result map. final int option = RandomUtils.nextInt(3); if (option == 0) { key2Result.put(key, key + RandomStringUtils.randomNumeric(5)); }/*from ww w . j ava2 s .com*/ if (option == 1) { key2Result.put(key, null); missObjects.add(object); } if (option == 2) { missObjects.add(object); } } try { coord.setInitialKey2Result(null); fail("Expected Exception."); } catch (RuntimeException ex) { } coord.getKey2Obj().putAll(expectedString2Object); coord.setInitialKey2Result(key2Result); assertTrue(coord.getMissObjects().containsAll(missObjects)); assertTrue(missObjects.containsAll(coord.getMissObjects())); }
From source file:fr.fg.server.core.TerritoryManager.java
public synchronized void updateTerritoryMap(int idSector) { ImageCache territory = new ImageCache(createTerritoryMap(idSector)); String hash;/*from w ww .ja v a 2s . c o m*/ do { hash = RandomStringUtils.randomAlphanumeric(32); } while (territoriesHash.get(hash) != null); String oldHash = getTerritoryHashBySector(idSector); territoriesMaps.put(idSector, territory); territoriesHash.put(hash, idSector); territoriesHash.remove(oldHash); }
From source file:com.flexive.tests.embedded.MandatorTest.java
@BeforeClass public void beforeClass() throws Exception { me = EJBLookup.getMandatorEngine();/* www .j ava 2s .c om*/ te = EJBLookup.getTypeEngine(); ce = EJBLookup.getContentEngine(); ass = EJBLookup.getAssignmentEngine(); login(TestUsers.SUPERVISOR); try { testMandator = me.create("MANDATOR_" + RandomStringUtils.randomAlphanumeric(10), true); testType = te.save(FxTypeEdit.createNew("TEST_" + RandomStringUtils.randomAlphanumeric(10))); } catch (FxApplicationException e) { LOG.error(e); } }
From source file:net.nelz.simplesm.test.dao.TestDAOImpl.java
@ReadThroughSingleCache(namespace = "Charlie", expiration = 1000) public String getRandomString(@ParameterValueKeyProvider final Long key) { try {/*from w ww .j a v a2 s . c o m*/ Thread.sleep(500); } catch (InterruptedException ex) { } return RandomStringUtils.randomAlphanumeric(25 + RandomUtils.nextInt(30)); }
From source file:com.consol.citrus.admin.service.FileBrowserServiceTest.java
private File createRandomDirectory(File rootDirectory) throws IOException { File tmpDir = new File(rootDirectory, RandomStringUtils.randomAlphanumeric(8)); if (tmpDir.mkdir()) { return tmpDir; }// w w w .ja v a2 s . c o m throw new RuntimeException(String.format("Could not create directory '%s'", tmpDir.getAbsolutePath())); }
From source file:com.qatickets.service.UserService.java
@Transactional(readOnly = false) public UserProfile saveOrUpdateUser(UserProfile currentUser, String userName, String email, int timezone, int userId) throws Exception { UserProfile profile = null;/*from w w w . j a v a2 s . c o m*/ userName = spamService.clean(StringUtils.trim(userName), 32); email = spamService.clean(StringUtils.trim(email), 128); if (false == this.isValidEmail(email)) { throw new EmailNotValidException(); } if (userId == 0) { // new user profile = new UserProfile(); profile.setDate(new Date()); final String password = RandomStringUtils.randomAlphanumeric(DEFAULT_PASSWORD_LENGTH); profile.setPassword(password); } else { profile = this.findById(userId); if (profile == null) { throw new ProfileNotFoundException(); } // if not the same user or owner, quit if (false == currentUser.equals(profile)) { throw new ProfileNotFoundException(); } } if (profile.isNew() || false == profile.getEmail().equals(email)) { log.debug("Email was asked to changed/set to: " + email + " for " + profile); if (this.isEmailRegistered(email)) { log.debug("The e-mail address is used by other user"); throw new EmailAlreadyRegisteredException(); } profile.setEmail(email); } profile.setName(userName); profile.setTimezone(timezone); this.save(profile); // TODO send email to both owner and new user with the new password log.debug("User saved: " + profile); return profile; }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.api.tags.MMXUserTagsResourceTest.java
public static AppEntity createRandomApp() throws Exception { String serverUserId = "serverUser"; String appName = "usertagresourcetestapp"; 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 ww w .j a v a 2s . 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.xtructure.xutil.xml.UTestXmlUnit.java
public void getTypeReturnsExpectedClass() { String name = RandomStringUtils.randomAlphanumeric(10); assertThat("", // XmlUnit.newAttribute(name).getType(), isNull()); assertThat("", // XmlUnit.newAttribute(name, Double.class).getType(), isEqualTo(Double.class)); assertThat("", // XmlUnit.newElement(name).getType(), isNull()); assertThat("", // XmlUnit.newElement(name, Double.class).getType(), isEqualTo(Double.class)); }
From source file:com.splunk.shuttl.testutil.TUtilsFile.java
private static File getUniquelyNamedFileWithPrefix(String prefix) { Class<?> callerToThisMethod = MethodCallerHelper.getCallerToMyMethod(); String tempDirName = prefix + "-" + callerToThisMethod.getSimpleName(); File file = getFileInShuttlTestDirectory(tempDirName); while (file.exists()) { tempDirName += "-" + RandomStringUtils.randomAlphanumeric(2); file = getFileInShuttlTestDirectory(tempDirName); }/*from w w w.j a v a 2 s .com*/ return file; }