List of usage examples for org.apache.commons.lang RandomStringUtils randomNumeric
public static String randomNumeric(int count)
Creates a random string whose length is the number of characters specified.
Characters will be chosen from the set of numeric characters.
From source file:org.apache.ambari.server.configuration.ConfigurationTest.java
@Test public void testGetClientHTTPSSettings() throws IOException { File passFile = File.createTempFile("https.pass.", "txt"); passFile.deleteOnExit();/*from www. jav a2s . c o m*/ String password = "pass12345"; FileUtils.writeStringToFile(passFile, password); Properties ambariProperties = new Properties(); ambariProperties.setProperty(Configuration.API_USE_SSL, "true"); ambariProperties.setProperty(Configuration.CLIENT_API_SSL_KSTR_DIR_NAME_KEY, passFile.getParent()); ambariProperties.setProperty(Configuration.CLIENT_API_SSL_CRT_PASS_FILE_NAME_KEY, passFile.getName()); String oneWayPort = RandomStringUtils.randomNumeric(4); String twoWayPort = RandomStringUtils.randomNumeric(4); ambariProperties.setProperty(Configuration.SRVR_TWO_WAY_SSL_PORT_KEY, twoWayPort.toString()); ambariProperties.setProperty(Configuration.SRVR_ONE_WAY_SSL_PORT_KEY, oneWayPort.toString()); Configuration conf = new Configuration(ambariProperties); Assert.assertTrue(conf.getApiSSLAuthentication()); //Different certificates for two-way SSL and HTTPS Assert.assertFalse(conf.getConfigsMap().get(Configuration.KSTR_NAME_KEY) .equals(conf.getConfigsMap().get(Configuration.CLIENT_API_SSL_KSTR_NAME_KEY))); Assert.assertFalse(conf.getConfigsMap().get(Configuration.SRVR_CRT_NAME_KEY) .equals(conf.getConfigsMap().get(Configuration.CLIENT_API_SSL_CRT_NAME_KEY))); Assert.assertEquals("https.keystore.p12", conf.getConfigsMap().get(Configuration.CLIENT_API_SSL_KSTR_NAME_KEY)); Assert.assertEquals(passFile.getName(), conf.getConfigsMap().get(Configuration.CLIENT_API_SSL_CRT_PASS_FILE_NAME_KEY)); Assert.assertEquals(password, conf.getConfigsMap().get(Configuration.CLIENT_API_SSL_CRT_PASS_KEY)); Assert.assertEquals(Integer.parseInt(twoWayPort), conf.getTwoWayAuthPort()); Assert.assertEquals(Integer.parseInt(oneWayPort), conf.getOneWayAuthPort()); }
From source file:org.apache.falcon.state.service.store.TestJDBCStateStore.java
private void initInstanceState(InstanceState instanceState) { instanceState.setCurrentState(InstanceState.STATE.READY); instanceState.getInstance().setExternalID(RandomStringUtils.randomNumeric(6)); instanceState.getInstance().setInstanceSequence(randomValGenerator.nextInt()); instanceState.getInstance().setActualStart(new DateTime(System.currentTimeMillis())); instanceState.getInstance().setActualEnd(new DateTime(System.currentTimeMillis())); List<Predicate> predicates = new ArrayList<>(); Predicate predicate = new Predicate(Predicate.TYPE.JOB_COMPLETION); predicates.add(predicate);//www . jav a 2 s . c o m instanceState.getInstance().setAwaitingPredicates(predicates); }
From source file:org.apache.hadoop.hdfs.util.TestPosixUserNameChecker.java
@Test public void test() { check("abc", true); check("a_bc", true); check("a1234bc", true); check("a1234bc45", true); check("_a1234bc45$", true); check("_a123-4bc45$", true); check("abc_", true); check("ab-c_$", true); check("_abc", true); check("ab-c$", true); check("-abc", false); check("-abc_", false); check("a$bc", false); check("9abc", false); check("-abc", false); check("$abc", false); check("", false); check(null, false);/*from w w w . j a va2 s. c o m*/ check(RandomStringUtils.randomAlphabetic(100).toLowerCase(), true); check(RandomStringUtils.randomNumeric(100), false); check("a" + RandomStringUtils.randomNumeric(100), true); check("_" + RandomStringUtils.randomNumeric(100), true); check("a" + RandomStringUtils.randomAlphanumeric(100).toLowerCase(), true); check("_" + RandomStringUtils.randomAlphanumeric(100).toLowerCase(), true); check(RandomStringUtils.random(1000), false); //unicode }
From source file:org.apache.james.server.core.MailImpl.java
private static String generateRandomSuffix(int suffixLength, char separator) { return "-" + separator + RandomStringUtils.randomNumeric(suffixLength - 2); }
From source file:org.apache.myfaces.examples.schedule.AddEntryHandler.java
public String add() { if (!from.before(until)) { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "start time must be before end time", null)); return "failure"; }/*from ww w . j a v a 2s .co m*/ DefaultScheduleEntry entry = new DefaultScheduleEntry(); entry.setId(RandomStringUtils.randomNumeric(32)); entry.setStartTime(from); entry.setEndTime(until); entry.setTitle(title); entry.setSubtitle(location); entry.setDescription(comments); model.addEntry(entry); model.refresh(); return "success"; }
From source file:org.apache.myfaces.examples.schedule.ScheduleExampleHandler.java
public void addSampleEntries(ActionEvent event) { if (model == null) return;/*from w w w . j a v a 2s . com*/ Calendar calendar = GregorianCalendar.getInstance(); calendar.setTime(model.getSelectedDate()); calendar.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY); calendar.set(Calendar.HOUR_OF_DAY, 14); DefaultScheduleEntry entry1 = new DefaultScheduleEntry(); // every entry in a schedule must have a unique id entry1.setId(RandomStringUtils.randomNumeric(32)); entry1.setStartTime(calendar.getTime()); calendar.add(Calendar.MINUTE, 45); entry1.setEndTime(calendar.getTime()); entry1.setTitle("Test MyFaces schedule component"); entry1.setSubtitle("my office"); entry1.setDescription("We need to get this thing out of the sandbox ASAP"); model.addEntry(entry1); DefaultScheduleEntry entry2 = new DefaultScheduleEntry(); entry2.setId(RandomStringUtils.randomNumeric(32)); // entry2 overlaps entry1 calendar.add(Calendar.MINUTE, -20); entry2.setStartTime(calendar.getTime()); calendar.add(Calendar.HOUR, 2); entry2.setEndTime(calendar.getTime()); entry2.setTitle("Show schedule component to boss"); entry2.setSubtitle("my office"); entry2.setDescription("Convince him to get time to thoroughly test it"); model.addEntry(entry2); DefaultScheduleEntry entry3 = new DefaultScheduleEntry(); entry3.setId(RandomStringUtils.randomNumeric(32)); calendar.add(Calendar.DATE, 1); calendar.set(Calendar.HOUR_OF_DAY, 9); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); entry3.setStartTime(calendar.getTime()); calendar.set(Calendar.HOUR_OF_DAY, 17); entry3.setEndTime(calendar.getTime()); entry3.setTitle("Thoroughly test schedule component"); model.addEntry(entry3); DefaultScheduleEntry entry4 = new DefaultScheduleEntry(); entry4.setId(RandomStringUtils.randomNumeric(32)); calendar.add(Calendar.MONTH, -1); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); calendar.set(Calendar.HOUR_OF_DAY, 11); entry4.setStartTime(calendar.getTime()); calendar.set(Calendar.HOUR_OF_DAY, 14); entry4.setEndTime(calendar.getTime()); entry4.setTitle("Long lunch"); model.addEntry(entry4); DefaultScheduleEntry entry5 = new DefaultScheduleEntry(); entry5.setId(RandomStringUtils.randomNumeric(32)); calendar.add(Calendar.MONTH, 2); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.HOUR_OF_DAY, 1); entry5.setStartTime(calendar.getTime()); calendar.set(Calendar.HOUR_OF_DAY, 5); entry5.setEndTime(calendar.getTime()); entry5.setTitle("Fishing trip"); model.addEntry(entry5); //Let's add a zero length entry... DefaultScheduleEntry entry6 = new DefaultScheduleEntry(); calendar.setTime(model.getSelectedDate()); calendar.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY); calendar.set(Calendar.HOUR_OF_DAY, 16); entry6.setId(RandomStringUtils.randomNumeric(32)); entry6.setStartTime(calendar.getTime()); entry6.setEndTime(calendar.getTime()); entry6.setTitle("Zero length entry"); entry6.setDescription("Is only rendered when the 'renderZeroLengthEntries' attribute is 'true'"); model.addEntry(entry6); //And also an allday event DefaultScheduleEntry entry7 = new DefaultScheduleEntry(); entry7.setId(RandomStringUtils.randomNumeric(32)); entry7.setTitle("All day event"); entry7.setSubtitle("This event renders as an all-day event"); entry7.setAllDay(true); model.addEntry(entry7); model.refresh(); }
From source file:org.apache.pig.builtin.TestOrcStoragePushdown.java
private static void createInputData() throws Exception { pigServer = new PigServer(Util.getLocalTestMode()); new File(inpbasedir).mkdirs(); new File(outbasedir).mkdirs(); String inputTxtFile = inpbasedir + File.separator + "input.txt"; BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(inputTxtFile), "UTF-8")); long[] lVal = new long[] { 100L, 200L, 300L }; float[] fVal = new float[] { 50.0f, 100.0f, 200.0f, 300.0f }; double[] dVal = new double[] { 1000.11, 2000.22, 3000.33 }; StringBuilder sb = new StringBuilder(); for (int i = 1; i <= 10000; i++) { sb.append((i > 6500 && i <= 9000) ? true : false).append("\t"); //boolean sb.append((i > 1000 && i < 3000) ? 1 : 5).append("\t"); //byte sb.append((i > 2500 && i <= 4500) ? 100 : 200).append("\t"); //short sb.append(i).append("\t"); //int sb.append(lVal[i % 3]).append("\t"); //long sb.append(fVal[i % 4]).append("\t"); //float sb.append((i > 2500 && i < 3500) ? dVal[i % 3] : dVal[i % 1]).append("\t"); //double sb.append((i % 2 == 1 ? "" : RandomStringUtils.random(100).replaceAll("\t", " ").replaceAll("\n", " ").replaceAll("\r", " "))) .append("\t"); //bytearray sb.append((i % 2 == 0 ? "" : RandomStringUtils.random(100).replaceAll("\t", " ").replaceAll("\n", " ").replaceAll("\r", " "))) .append("\t"); //string int year; if (i > 5000 && i <= 8000) { //datetime year = RandomUtils.nextInt(4) + 2010; } else {//w w w . java 2 s . com year = RandomUtils.nextInt(10) + 2000; } sb.append(new DateTime(year, RandomUtils.nextInt(12) + 1, RandomUtils.nextInt(28) + 1, RandomUtils.nextInt(24), RandomUtils.nextInt(60), DateTimeZone.UTC).toString()).append("\t"); // datetime String bigString; if (i > 7500) { bigString = RandomStringUtils.randomNumeric(9) + "." + RandomStringUtils.randomNumeric(5); } else { bigString = "1" + RandomStringUtils.randomNumeric(9) + "." + RandomStringUtils.randomNumeric(5); } sb.append(new BigDecimal(bigString)).append("\n"); //bigdecimal bw.write(sb.toString()); sb.setLength(0); } bw.close(); // Store only 1000 rows in each row block (MIN_ROW_INDEX_STRIDE is 1000. So can't use less than that) pigServer.registerQuery("A = load '" + Util.generateURI(inputTxtFile, pigServer.getPigContext()) + "' as (f1:boolean, f2:int, f3:int, f4:int, f5:long, f6:float, f7:double, f8:bytearray, f9:chararray, f10:datetime, f11:bigdecimal);"); pigServer.registerQuery("store A into '" + Util.generateURI(INPUT, pigServer.getPigContext()) + "' using OrcStorage('-r 1000 -s 100000');"); Util.copyFromLocalToCluster(cluster, INPUT, INPUT); }
From source file:org.artifactory.version.converter.v160.AddonsDefaultLayoutConverter.java
public Element getRepoLayoutElement(Element repoLayoutsElement, Namespace namespace, String name, String artifactPathPattern, String distinctiveDescriptorPathPattern, String descriptorPathPattern, String folderIntegrationRevisionRegExp, String fileIntegrationRevisionRegExp) { // Maybe the user already configured *-default, if so randomize the name for (Element repoLayoutElement : repoLayoutsElement.getChildren()) { if (name.equals(repoLayoutElement.getChild("name", namespace).getText())) { if (repoLayoutsElement.getChild("art-" + name, namespace) != null) { name += RandomStringUtils.randomNumeric(3); } else { name = "art-" + name; }//from w ww . java2s . c o m } } Element repoLayoutElement = new Element("repoLayout", namespace); Element nameElement = new Element("name", namespace); nameElement.setText(name); repoLayoutElement.addContent(nameElement); Element artifactPathPatternElement = new Element("artifactPathPattern", namespace); artifactPathPatternElement.setText(artifactPathPattern); repoLayoutElement.addContent(artifactPathPatternElement); Element distinctiveDescriptorPathPatternElement = new Element("distinctiveDescriptorPathPattern", namespace); distinctiveDescriptorPathPatternElement.setText(distinctiveDescriptorPathPattern); repoLayoutElement.addContent(distinctiveDescriptorPathPatternElement); if (StringUtils.isNotBlank(descriptorPathPattern)) { Element descriptorPathPatternElement = new Element("descriptorPathPattern", namespace); descriptorPathPatternElement.setText(descriptorPathPattern); repoLayoutElement.addContent(descriptorPathPatternElement); } if (StringUtils.isNotBlank(folderIntegrationRevisionRegExp)) { Element folderIntegrationRevisionRegExpElement = new Element("folderIntegrationRevisionRegExp", namespace); folderIntegrationRevisionRegExpElement.setText(folderIntegrationRevisionRegExp); repoLayoutElement.addContent(folderIntegrationRevisionRegExpElement); } if (StringUtils.isNotBlank(fileIntegrationRevisionRegExp)) { Element fileIntegrationRevisionRegExpElement = new Element("fileIntegrationRevisionRegExp", namespace); fileIntegrationRevisionRegExpElement.setText(fileIntegrationRevisionRegExp); repoLayoutElement.addContent(fileIntegrationRevisionRegExpElement); } return repoLayoutElement; }
From source file:org.beangle.emsapp.security.action.MyAction.java
/** * ???//w ww. ja v a 2 s . c om */ public String sendPassword() { String name = get("name"); String email = get("mail"); if (StringUtils.isEmpty(name) || StringUtils.isEmpty(email)) { addActionError("error.parameters.needed"); return (ERROR); } List<User> userList = entityDao.get(User.class, "name", name); User user = null; if (userList.isEmpty()) { return goErrorWithMessage("error.user.notExist"); } else { user = userList.get(0); } if (!StringUtils.equals(email, user.getMail())) { return goErrorWithMessage("error.email.notEqualToOrign"); } else { String longinName = user.getName(); String password = RandomStringUtils.randomNumeric(6); user.setRemark(password); user.setPassword(EncryptUtil.encode(password)); String title = getText("user.password.sendmail.title"); List<Object> values = CollectUtils.newArrayList(); values.add(longinName); values.add(password); String body = getText("user.password.sendmail.body", values); try { SimpleMailMessage msg = new SimpleMailMessage(message); msg.setTo(user.getMail()); msg.setSubject(title); msg.setText(body.toString()); mailSender.send(msg); } catch (Exception e) { e.printStackTrace(); logger.info("reset password error for user:" + user.getName() + " with email :" + user.getMail()); return goErrorWithMessage("error.email.sendError"); } } entityDao.saveOrUpdate(user); return forward("sendResult"); }
From source file:org.bigbluebutton.api.ParamsProcessorUtil.java
public String processTelVoice(String telNum) { return StringUtils.isEmpty(telNum) ? RandomStringUtils.randomNumeric(defaultNumDigitsForTelVoice) : telNum; }