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:com.haulmont.cuba.gui.components.filter.ConditionParamBuilderImpl.java
@Override public String createParamName(AbstractCondition condition) { return "component$" + condition.getFilterComponentName() + "." + condition.getName().replace('.', '_').replace(" ", "_") + RandomStringUtils.randomNumeric(5); }
From source file:edu.sampleu.admin.CampusAftBase.java
protected void saveAndReload() throws InterruptedException { checkForDocError();/*from www .ja va2 s . co m*/ waitAndClickByXpath(SAVE_XPATH); int attempts = 0; while (isTextPresent("a record with the same primary key already exists.") && ++attempts <= 10) { jGrowl("record with the same primary key already exists trying another, attempt: " + attempts); clearTextByName("document.newMaintainableObject.code"); // primary key String randomNumbeForCode = RandomStringUtils.randomNumeric(1); String randomAlphabeticForCode = RandomStringUtils.randomAlphabetic(1); jiraAwareTypeByName("document.newMaintainableObject.code", randomNumbeForCode + randomAlphabeticForCode); waitAndClickByXpath(SAVE_XPATH); } waitForTextPresent("Document was successfully saved"); waitAndClickByName("methodToCall.reload"); // waitAndClickByName("methodToCall.processAnswer.button1"); }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.servlet.MMXTopicResourceTest.java
private static void setupMocks() { new MockUp<TopicResource>() { @Mock/*from w w w .j a va 2 s . c o m*/ protected List<TopicSubscription> getTopicSubscriptions(String appId, String topicName) { LOGGER.trace("MOCKED getTopicSubscriptions : appid={}, topicName={}", appId, topicName); String topicId = TopicHelper.makeTopic(appId, null, topicName); List<TopicSubscription> list = new ArrayList<TopicSubscription>(10); for (int i = 0; i < 100; i++) { StubTopicSubscription subscription = new StubTopicSubscription(); subscription.setTopic(topicName); subscription.setUsername(RandomStringUtils.randomAlphanumeric(3)); subscription.setSubscriptionId(RandomStringUtils.randomAlphanumeric(10)); if (i % 3 == 0) { subscription.setDeviceId(RandomStringUtils.randomNumeric(10)); } list.add(subscription); } return list; } }; //for allowing auth new MockUp<AuthUtil>() { @Mock public boolean isAuthorized(HttpServletRequest headers) throws IOException { return true; } }; /** * For using the db unit datasource */ new MockUp<TopicResource>() { @Mock public ConnectionProvider getConnectionProvider() { return new BasicDataSourceConnectionProvider(ds); } }; }
From source file:com.qmetry.qaf.automation.util.StringUtil.java
public static String getRandomString(String format) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < format.length(); i++) { char c = format.charAt(i); char a = Character.isDigit(c) ? RandomStringUtils.randomNumeric(1).charAt(0) : Character.isLetter(c) ? RandomStringUtils.randomAlphabetic(c).charAt(0) : c; sb.append(a);/*from w ww .java 2s.c o m*/ } return sb.toString(); }
From source file:com.wso2telco.services.dep.sandbox.util.CommonUtil.java
public static String getResourceUrl(RequestDTO extendedRequestDTO) { StringBuilder resourceUrlBuilder = new StringBuilder(); String protocolVersion = extendedRequestDTO.getHttpRequest().getProtocol(); String[] protocolDetail = protocolVersion.split("/"); resourceUrlBuilder.append(protocolDetail[0].toLowerCase() + "://"); resourceUrlBuilder.append(extendedRequestDTO.getHttpRequest().getHeader("Host")); resourceUrlBuilder.append(//from w w w . j a v a2 s . c om extendedRequestDTO.getHttpRequest().getPathInfo() + "/" + RandomStringUtils.randomNumeric(5)); /*if (extendedRequestDTO.getHttpRequest().getQueryString() != null) { resourceUrlBuilder.append(QUERY_STRING_SEPARATOR); resourceUrlBuilder.append(extendedRequestDTO.getHttpRequest() .getQueryString()); }*/ return resourceUrlBuilder.toString(); }
From source file:com.sjsu.crawler.util.RandomStringUtilsTest.java
/** * Test the implementation//www .ja v a 2s.co m */ @Test public void testRandomStringUtils() { String r1 = RandomStringUtils.random(50); assertEquals("random(50) length", 50, r1.length()); String r2 = RandomStringUtils.random(50); assertEquals("random(50) length", 50, r2.length()); assertTrue("!r1.equals(r2)", !r1.equals(r2)); r1 = RandomStringUtils.randomAscii(50); assertEquals("randomAscii(50) length", 50, r1.length()); for (int i = 0; i < r1.length(); i++) { assertTrue("char between 32 and 127", r1.charAt(i) >= 32 && r1.charAt(i) <= 127); } r2 = RandomStringUtils.randomAscii(50); assertTrue("!r1.equals(r2)", !r1.equals(r2)); r1 = RandomStringUtils.randomAlphabetic(50); assertEquals("randomAlphabetic(50)", 50, r1.length()); for (int i = 0; i < r1.length(); i++) { assertTrue("r1 contains alphabetic", Character.isLetter(r1.charAt(i)) && !Character.isDigit(r1.charAt(i))); } r2 = RandomStringUtils.randomAlphabetic(50); assertTrue("!r1.equals(r2)", !r1.equals(r2)); r1 = RandomStringUtils.randomAlphanumeric(50); assertEquals("randomAlphanumeric(50)", 50, r1.length()); for (int i = 0; i < r1.length(); i++) { assertTrue("r1 contains alphanumeric", Character.isLetterOrDigit(r1.charAt(i))); } r2 = RandomStringUtils.randomAlphabetic(50); assertTrue("!r1.equals(r2)", !r1.equals(r2)); r1 = RandomStringUtils.randomNumeric(50); assertEquals("randomNumeric(50)", 50, r1.length()); for (int i = 0; i < r1.length(); i++) { assertTrue("r1 contains numeric", Character.isDigit(r1.charAt(i)) && !Character.isLetter(r1.charAt(i))); } r2 = RandomStringUtils.randomNumeric(50); assertTrue("!r1.equals(r2)", !r1.equals(r2)); String set = "abcdefg"; r1 = RandomStringUtils.random(50, set); assertEquals("random(50, \"abcdefg\")", 50, r1.length()); for (int i = 0; i < r1.length(); i++) { assertTrue("random char in set", set.indexOf(r1.charAt(i)) > -1); } r2 = RandomStringUtils.random(50, set); assertTrue("!r1.equals(r2)", !r1.equals(r2)); r1 = RandomStringUtils.random(50, (String) null); assertEquals("random(50) length", 50, r1.length()); r2 = RandomStringUtils.random(50, (String) null); assertEquals("random(50) length", 50, r2.length()); assertTrue("!r1.equals(r2)", !r1.equals(r2)); set = "stuvwxyz"; r1 = RandomStringUtils.random(50, set.toCharArray()); assertEquals("random(50, \"stuvwxyz\")", 50, r1.length()); for (int i = 0; i < r1.length(); i++) { assertTrue("random char in set", set.indexOf(r1.charAt(i)) > -1); } r2 = RandomStringUtils.random(50, set); assertTrue("!r1.equals(r2)", !r1.equals(r2)); r1 = RandomStringUtils.random(50, (char[]) null); assertEquals("random(50) length", 50, r1.length()); r2 = RandomStringUtils.random(50, (char[]) null); assertEquals("random(50) length", 50, r2.length()); assertTrue("!r1.equals(r2)", !r1.equals(r2)); final long seed = System.currentTimeMillis(); r1 = RandomStringUtils.random(50, 0, 0, true, true, null, new Random(seed)); r2 = RandomStringUtils.random(50, 0, 0, true, true, null, new Random(seed)); assertEquals("r1.equals(r2)", r1, r2); r1 = RandomStringUtils.random(0); assertEquals("random(0).equals(\"\")", "", r1); }
From source file:com.greenline.guahao.biz.manager.partners.unicom.impl.UnicomManagerImpl.java
@Override public String getorderMessageURL(String productid, String backurl) { String gettime = String.valueOf((new Date().getTime()) / 1000); String rand = RandomStringUtils.randomNumeric(5); String key = MD5Util.getMD5Format(spID + productid + gettime + spPassWord + rand); StringBuffer buffer = new StringBuffer(); buffer.append(orderurl).append("?spid=").append(spID).append("&productid=").append(productid) .append("&gettime=").append(gettime).append("&rand=").append(rand).append("&key=").append(key) .append("&backurl=").append(backurl); log.info("______________orderMessageurl:" + buffer.toString() + "______________"); return buffer.toString(); }
From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnRService.java
public DvnRService() { // initialization IdSuffix = RandomStringUtils.randomNumeric(6); RDataFileName = TMP_DIR_REMOTE + "/" + RDATA_FILE_NAME + "." + IdSuffix + RDATA_FILE_EXT; if (RConnectionPool == null) { dbgLog.fine("number of RServe connections: " + RSERVE_CONNECTION_POOLSIZE); RConnectionPool = new DvnRConnectionPool(RSERVE_CONNECTION_POOLSIZE); }/*from w ww . ja va 2 s . co m*/ }
From source file:edu.harvard.iq.dataverse.rserve.RemoteDataFrameService.java
public RemoteDataFrameService() { // initialization PID = RandomStringUtils.randomNumeric(6); tempFileNameIn = RSERVE_TMP_DIR + "/" + TMP_DATA_FILE_NAME + "." + PID + TMP_TABDATA_FILE_EXT; tempFileNameOut = RSERVE_TMP_DIR + "/" + RWRKSP_FILE_PREFIX + "." + PID + TMP_RDATA_FILE_EXT; dbgLog.fine("tempFileNameIn=" + tempFileNameIn); dbgLog.fine("tempFileNameOut=" + tempFileNameOut); }
From source file:com.haulmont.cuba.gui.components.filter.edit.DynamicAttributesConditionFrame.java
@Override public boolean commit() { if (!super.commit()) return false; String error = checkCondition(); if (error != null) { showNotification(messages.getMainMessage(error), Frame.NotificationType.TRAY); return false; }/*w ww.j a v a 2 s. c o m*/ CategoryAttribute attribute = attributeLookup.getValue(); String alias = condition.getEntityAlias(); String cavAlias = "cav" + RandomStringUtils.randomNumeric(5); String paramName; String operation = operationLookup.<Op>getValue().forJpql(); Op op = operationLookup.getValue(); Class javaClass = DynamicAttributesUtils.getAttributeClass(attribute); String propertyPath = Strings.isNullOrEmpty(condition.getPropertyPath()) ? "" : "." + condition.getPropertyPath(); ConditionParamBuilder paramBuilder = AppBeans.get(ConditionParamBuilder.class); paramName = paramBuilder.createParamName(condition); String cavEntityId = referenceToEntitySupport .getReferenceIdPropertyName(condition.getDatasource().getMetaClass()); String where; if (op == Op.NOT_EMPTY) { where = "(exists (select " + cavAlias + " from sys$CategoryAttributeValue " + cavAlias + " where " + cavAlias + ".entity." + cavEntityId + "=" + "{E}" + propertyPath + ".id and " + cavAlias + ".categoryAttribute.id='" + attributeLookup.<CategoryAttribute>getValue().getId() + "'))"; } else { String valueFieldName = "stringValue"; if (Entity.class.isAssignableFrom(javaClass)) valueFieldName = "entityValue." + referenceToEntitySupport.getReferenceIdPropertyName(metadata.getClassNN(javaClass)); else if (String.class.isAssignableFrom(javaClass)) valueFieldName = "stringValue"; else if (Integer.class.isAssignableFrom(javaClass)) valueFieldName = "intValue"; else if (Double.class.isAssignableFrom(javaClass)) valueFieldName = "doubleValue"; else if (Boolean.class.isAssignableFrom(javaClass)) valueFieldName = "booleanValue"; else if (Date.class.isAssignableFrom(javaClass)) valueFieldName = "dateValue"; if (!attribute.getIsCollection()) { condition.setJoin(", sys$CategoryAttributeValue " + cavAlias + " "); String paramStr = " ? "; where = cavAlias + ".entity." + cavEntityId + "=" + "{E}" + propertyPath + ".id and " + cavAlias + "." + valueFieldName + " " + operation + (op.isUnary() ? " " : paramStr) + "and " + cavAlias + ".categoryAttribute.id='" + attributeLookup.<CategoryAttribute>getValue().getId() + "'"; where = where.replace("?", ":" + paramName); } else { where = "(exists (select " + cavAlias + " from sys$CategoryAttributeValue " + cavAlias + " where " + cavAlias + ".entity." + cavEntityId + "=" + "{E}" + propertyPath + ".id and " + cavAlias + "." + valueFieldName + " = :" + paramName + " and " + cavAlias + ".categoryAttribute.id='" + attributeLookup.<CategoryAttribute>getValue().getId() + "'))"; } } condition.setWhere(where); condition.setUnary(op.isUnary()); condition.setEntityParamView(null); condition.setEntityParamWhere(null); condition.setInExpr(Op.IN.equals(op) || Op.NOT_IN.equals(op)); condition.setOperator(operationLookup.<Op>getValue()); Class paramJavaClass = op.isUnary() ? Boolean.class : javaClass; condition.setJavaClass(javaClass); Param param = Param.Builder.getInstance().setName(paramName).setJavaClass(paramJavaClass) .setDataSource(condition.getDatasource()) .setProperty(DynamicAttributesUtils.getMetaPropertyPath(null, attribute).getMetaProperty()) .setInExpr(condition.getInExpr()).setRequired(condition.getRequired()) .setCategoryAttrId(attribute.getId()).build(); Object defaultValue = condition.getParam().getDefaultValue(); param.setDefaultValue(defaultValue); condition.setParam(param); condition.setCategoryId(categoryLookup.<Category>getValue().getId()); condition.setCategoryAttributeId(attributeLookup.<CategoryAttribute>getValue().getId()); condition.setIsCollection( BooleanUtils.isTrue(attributeLookup.<CategoryAttribute>getValue().getIsCollection())); condition.setLocCaption(attribute.getLocaleName()); condition.setCaption(caption.getValue()); return true; }