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.genericconf.bbbgateway.domain.Meeting.java
private synchronized void ensureUniqueAttendeeName(Attendee att) { if (getAttendeeByName(att.getName()) != null) { att.setName(att.getName() + " - " + RandomStringUtils.randomAlphanumeric(4)); ensureUniqueAttendeeName(att);/*from w w w.ja v a2s. c o m*/ } }
From source file:com.adobe.acs.commons.designer.impl.OptionsServletTest.java
@Test public void testWithNormalType() throws Exception { Map<String, ClientLibrary> libraries = new HashMap<String, ClientLibrary>(); String jsOnlyCategory1 = RandomStringUtils.randomAlphanumeric(5); String jsOnlyCategory2 = RandomStringUtils.randomAlphanumeric(5); String bothCategory1 = RandomStringUtils.randomAlphanumeric(5); String bothCategory2 = RandomStringUtils.randomAlphanumeric(5); addLibrary(libraries, RandomStringUtils.random(10), new String[] { "js" }, new String[] { jsOnlyCategory1, jsOnlyCategory2 }); addLibrary(libraries, RandomStringUtils.random(10), new String[] { "js" }, new String[] { jsOnlyCategory2 }); addLibrary(libraries, RandomStringUtils.random(10), new String[] { "js", "css" }, new String[] { bothCategory1, bothCategory2 }); addLibrary(libraries, RandomStringUtils.random(10), new String[] { "js", "css" }, new String[] { bothCategory2 }); when(manager.getLibraries()).thenReturn(libraries); MockSlingHttpServletRequest request = new MockSlingHttpServletRequest( "/apps/acs-commons/components/utilities/designer/clientlibsmanager/options", "js", "json", null, null);//from ww w .j a v a 2s . co m MockSlingHttpServletResponse response = new MockSlingHttpServletResponse(); servlet.doGet(request, response); assertEquals("application/json", response.getContentType()); JSONArray array = new JSONArray(response.getOutput().toString()); assertEquals(4, array.length()); }
From source file:JasperPDF.PDF.java
/** * Metodo pdf/*from www . j av a 2 s . c om*/ * * @param jasperFile * @throws javax.xml.bind.JAXBException */ public synchronized byte[] getReport(String jasperFile, Object data, Connection con, String hashId) throws JRException, JAXBException, IOException { HashMap<String, Object> parametros = new HashMap<String, Object>(); File pdf; pdf = new File(RandomStringUtils.randomAlphanumeric(15) + ".pdf"); parametros.put("logo", image); parametros.put("hashId", hashId); setParameters(data, parametros); try { JasperPrint jasperPrint; jasperPrint = JasperFillManager.fillReport(new FileInputStream(jasperFile), parametros, con); JRExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_FILE, pdf); exporter.exportReport(); FileInputStream inputStream = new FileInputStream(pdf); byte[] bytePDF = IOUtils.toByteArray(inputStream); inputStream.close(); pdf.delete(); return bytePDF; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:com.cfitzarl.cfjwed.service.impl.InviteeRegistrationServiceImpl.java
/** {@inheritDoc} **/ @Override//from www . j a v a 2s. c om public void register(Account account) { Invitation invitation = invitationDao.findByCode(account.getInvitationCode()); if (invitation == null) { throw new BadRequestException("errors.code.invalid"); } if (invitation.getAccount() != null) { throw new BadRequestException("errors.code.used"); } // Associate account with invitation invitation.setAccount(accountService.save(account)); invitationDao.save(invitation); String activationToken = RandomStringUtils.randomAlphanumeric(32); // Send registration email String title = configDao.findByKey(ConfigKey.TITLE).getValue(); String subject = localizationService.getMessage("email.activation.invitee.subject", Collections.singletonList(title)); Map<String, Object> attrs = getCommonEmailAttrs(activationToken, account); emailDispatcher.send(account.getEmail(), subject, "invitee-activation-email", attrs); // Create activation createActivation(activationToken, account); }
From source file:it.infn.ct.security.actions.PassRecovery.java
@Override public String execute() throws Exception { String code = RandomStringUtils.randomAlphanumeric(12); if (user == null) { user = LDAPUtils.findUserByMail(email); }//www . ja va2s . co m ActionContext.getContext().getSession().put("passResetCode", code); ActionContext.getContext().getSession().put("user", user); try { sendMail(code); } catch (MailException me) { _log.error(me); return ERROR; } return SUCCESS; }
From source file:com.joyfulmongo.db.JFMongoCmdCreate.java
protected String generateObjectId() { String objectId = null;/*w w w. jav a2 s . c om*/ while (objectId == null) { objectId = RandomStringUtils.randomAlphanumeric(10); boolean unique = verifyObjectIdUnique(objectId); if (unique) { break; } else { objectId = null; } } return objectId; }
From source file:com.adobe.acs.commons.xss.XSSFunctionsTest.java
@Test public void testGetValidJSToken() { final String token = RandomStringUtils.randomAlphanumeric(10); final String defaultValue = RandomStringUtils.randomAlphanumeric(10); XSSFunctions.getValidJSToken(xssAPI, token, defaultValue); verify(xssAPI, only()).getValidJSToken(token, defaultValue); }
From source file:com.kixeye.chassis.bootstrap.app.AppIntegrationTest.java
@SuppressWarnings("unchecked") @Test(timeout = 40000)//from www . j a v a 2 s. c o m public void runSpringWithZookeeperConfig() throws Exception { String value = RandomStringUtils.randomAlphanumeric(5); TestUtils.addAppProperties(UNIT_TEST_SPRING_APP, environment, VERSION, curator, new SimpleEntry<String, String>(KEY, value)); Arguments arguments = new Arguments(); arguments.environment = environment; arguments.appClass = TestApplicationConfiguration.class.getName(); arguments.zookeeper = zookeeper.getConnectString(); arguments.skipModuleScanning = true; arguments.skipServerInstanceContextInitialization = true; application = new Application(arguments).start(); //grab the TestComponent that has been component-scanned into the app's spring context. Map<String, TestComponent> beans = application.getApplicationContext().getBeansOfType(TestComponent.class); TestComponent testComponent = beans.values().iterator().next(); //assert that the TestComponent has been injected with a property value from zookeeper. Assert.assertEquals(value, testComponent.getTestProperty()); }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.tests.integration.PandocLatexToHtmlConverterTest.java
@Before public void setUp() throws Exception { converter = new PandocLatexToHtmlConverter(); workingDirectory = TestUtils.getWorkingDirectory(this.getClass()); logger.debug("Working directory: " + workingDirectory.toAbsolutePath().toString()); inputFile = workingDirectory.resolve("formulas.tex").toFile(); mainCss = FileUtils.readFileToString(workingDirectory.resolve("main.css").toFile(), "UTF-8"); // ignore UNIX / Windows new line mainCss = mainCss.trim().replace("\n", "").replace("\r", ""); title = RandomStringUtils.randomAlphanumeric(64); logger.debug("Random title: " + title); }
From source file:com.kixeye.chassis.scala.transport.serde.ScalaCaseClassTest.java
@Test public void testYamlSerDe() throws Exception { final YamlJacksonMessageSerDe serDe = new YamlJacksonMessageSerDe(); final TestObject obj = new TestObject(RandomStringUtils.randomAlphanumeric(64), new SomeOtherObject(RandomStringUtils.randomAlphanumeric(64))); final byte[] serializedObj = serDe.serialize(obj); dumpToLog(serDe, serializedObj);//from w w w .j a v a 2 s . c om final TestObject deserializedObj = serDe.deserialize(serializedObj, 0, serializedObj.length, TestObject.class); Assert.assertEquals(obj, deserializedObj); }