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:db.PGKeys.java
public static String randomCode() { return RandomStringUtils.randomAlphanumeric(N_CODE_CHAR); }
From source file:name.richardson.james.bukkit.utilities.command.argument.suggester.PlayerMatcherTest.java
protected Player[] getPlayers() { List<Player> playerList = new ArrayList<Player>(); do {//from ww w . j a v a2 s .c o m Player player = mock(Player.class); when(player.getName()).thenReturn(RandomStringUtils.randomAlphanumeric(8)); playerList.add(player); } while (playerList.size() != 55); return playerList.toArray(new Player[55]); }
From source file:com.xtructure.xutil.valid.strategy.UTestArgumentValidationStrategy.java
public void processFailureBehavesAsExpected() { Condition predicate = isNotNull(); Object object = null;/*from ww w.j a v a 2s . c o m*/ String msg = RandomStringUtils.randomAlphanumeric(10); ArgumentValidationStrategy<Object> vs = new ArgumentValidationStrategy<Object>(predicate); try { vs.validate(object); } catch (IllegalArgumentException e) { if (!String.format("%s (%s): %s", ArgumentValidationStrategy.DEFAULT_MSG, object, predicate) .equals(e.getMessage())) { throw new AssertionError(); } } try { vs.validate(object, msg); } catch (IllegalArgumentException e) { if (!String.format("%s (%s): %s", msg, object, predicate).equals(e.getMessage())) { throw new AssertionError(); } } }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.tests.unit.MfencedTest.java
@Test public void testRenderContentListWithDifferentSeparators() throws Exception { int count = new Random().nextInt(31) + 2; logger.debug("Content list length: " + count); final String separators = RandomStringUtils.randomAlphanumeric(count); mfenced.setSeparators(separators);/* w w w.ja v a2 s . c om*/ List<FormulaElement> list = new ArrayList<>(); for (int i = 0; i < count; i++) { FormulaElement mockedFormulaElement = mock(FormulaElement.class); when(mockedFormulaElement.render(or(any(FormulaElement.class), isNull(FormulaElement.class)), or(anyListOf(FormulaElement.class), isNull(List.class)))).thenReturn(new Element(HTML_SPAN)); list.add(mockedFormulaElement); } mfenced.setContent(list); Element result = mfenced.render(possibleParent, null); assertEquals(HTML_SPAN, result.getName()); assertEquals("mfenced", result.getAttributeValue(HTML_CLASS)); for (FormulaElement mockedElement : list) { verify(mockedElement).render(or(eq(mfenced), isNull(FormulaElement.class)), or(anyListOf(FormulaElement.class), isNull(List.class))); } List<Element> spans = result.getChildren(HTML_SPAN); Element openingFence = spans.get(0); assertEquals("mfenced-open", openingFence.getAttributeValue(HTML_CLASS)); for (int i = 1; i < spans.size() - 1; i = i + 2) { assertEquals("mfenced-content", spans.get(i).getAttributeValue(HTML_CLASS)); } // Check separators String collectedSeparators = ""; for (int i = 2; i < spans.size() - 1; i = i + 2) { Element separatorSpan = spans.get(i); assertEquals("mo mfenced-separator", separatorSpan.getAttributeValue(HTML_CLASS)); collectedSeparators += spans.get(i).getText(); } assertEquals(separators, collectedSeparators); Element closingFence = result.getChildren().get(result.getChildren(HTML_SPAN).size() - 1); assertEquals("mfenced-close", closingFence.getAttributeValue(HTML_CLASS)); }
From source file:gemlite.core.internal.testing.generator.writer.impl.LogInfoWriter.java
/** * support save data to absolute path or relative path. * /* w ww .j a v a2 s .c o m*/ * @param filePath * @param fileName * @param lineSep * @param deleteOldFile * @param absolutePath */ public LogInfoWriter(String filePath, String fileName, String lineSep, boolean deleteOldFile, boolean absolutePath) { if (StringUtils.isBlank(filePath)) filePath = RandomStringUtils.randomAlphanumeric(4) + "/"; else { if (!filePath.endsWith("/")) filePath = filePath + "/"; if (!filePath.startsWith("/")) filePath = "/" + filePath; } if (!absolutePath) // relative path { if (StringUtils.isBlank(fileName)) fileName = RandomStringUtils.randomAlphanumeric(6) + ".txt"; String nodeName = ServerConfigHelper.getConfig(ITEMS.NODE_NAME); if (nodeName == null || nodeName.equals("")) nodeName = "basic"; String path = "/server/" + nodeName + filePath; String gs_work = ServerConfigHelper.getConfig(ITEMS.GS_WORK); WorkPathHelper.verifyPath(gs_work, path, false); fullFilePath = gs_work + path + fileName; } else {// absolute path File dirs = new File(filePath); if (!dirs.exists()) { dirs.mkdirs(); } fullFilePath = filePath + fileName; } File f = new File(fullFilePath); try { // delete old file if (deleteOldFile) { if (f != null && f.isFile() && f.exists()) FileUtils.deleteQuietly(f); } } catch (Exception e1) { } try { fw = new FileWriterWithEncoding(f, TEST_FILE_ENCODING); } catch (IOException e) { e.printStackTrace(); fw = null; fullFilePath = null; } this.lineSep = (lineSep != null ? lineSep : "\n"); }
From source file:com.netflix.ndbench.core.generators.StringDataGenerator.java
private void initialize(int lowerBound, int upperBound) { if (config.getUseVariableDataSize()) { for (int i = 0; i < config.getNumKeys(); i++) { if (i % 1000 == 0) { logger.info("Still initializing sample data for variable data size values"); }//www . ja v a 2 s. c o m int valueSize = upperBound; if (upperBound > lowerBound) { valueSize = vvRandom.nextInt(upperBound - lowerBound) + lowerBound; } String value = RandomStringUtils.randomAlphanumeric(valueSize); values.add(value); } } }
From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManagerTest.java
@Test public void addUserAccount() { try {//from w w w . ja v a 2 s.c om Assert.assertTrue(manager.addUserAccount( new ArrayList<String>(Arrays.asList("junit-test", RandomStringUtils.randomAlphanumeric(64), "Test", "User", "test@test.com", SQLUserManagerTest.GUID, "Test User")), new ArrayList<String>(Arrays.asList("USER")))); } catch (UserManagementException umx) { Assert.fail(umx.getMessage()); } }
From source file:com.cws.esolutions.security.dao.usermgmt.impl.LDAPUserManagerTest.java
@Test public void addUserAccount() { try {//from w w w. ja v a2 s. c o m Assert.assertTrue(manager.addUserAccount( new ArrayList<String>(Arrays.asList("junit-test", RandomStringUtils.randomAlphanumeric(64), "Test", "User", "test@test.com", LDAPUserManagerTest.GUID, "Test User")), new ArrayList<String>(Arrays.asList("USER")))); } catch (UserManagementException umx) { Assert.fail(umx.getMessage()); } }
From source file:com.adobe.acs.commons.xss.XSSFunctionsTest.java
@Test public void testGetValidInteger() { final String integer = RandomStringUtils.randomAlphanumeric(10); final int defaultValue = new Random().nextInt(); XSSFunctions.getValidInteger(xssAPI, integer, defaultValue); verify(xssAPI, only()).getValidInteger(integer, defaultValue); }
From source file:com.tasktop.c2c.server.tasks.tests.service.InternalTaskServiceTest.java
@Test public void testProvisionAccount_NewAccount() { String username = RandomStringUtils.randomAlphanumeric(16); String email = username + "@test.com"; String firstName = "firstName"; String lastName = "lastName"; String displayName = firstName + " " + lastName; taskService.provisionAccount(createTaskUserProfile(username, displayName)); AuthenticationToken authenticationToken = new AuthenticationToken(); authenticationToken.setFirstName(firstName); authenticationToken.setLastName(lastName); authenticationToken.setIssued(new Date()); authenticationToken.setExpiry(new Date(authenticationToken.getIssued().getTime() + 100000000L)); authenticationToken.setKey(UUID.randomUUID().toString()); authenticationToken.setUsername(username); authenticationToken.setLanguage("en"); TestSecurity.login(authenticationToken); Profile currentUserProfile = taskService.getCurrentUserProfile(); assertNotNull(currentUserProfile);/* www .ja v a 2s. c om*/ assertEquals(displayName, currentUserProfile.getRealname()); // Change our last name, and make sure it's reflected in the DB lastName = "newLastName"; authenticationToken.setLastName(lastName); displayName = firstName + " " + lastName; taskService.provisionAccount(createTaskUserProfile(username, displayName)); currentUserProfile = taskService.getCurrentUserProfile(); assertNotNull(currentUserProfile); assertEquals(displayName, currentUserProfile.getRealname()); }