List of usage examples for org.apache.commons.lang RandomStringUtils randomAlphabetic
public static String randomAlphabetic(int count)
Creates a random string whose length is the number of characters specified.
Characters will be chosen from the set of alphabetic characters.
From source file:com.sjsu.crawler.util.RandomStringUtilsTest.java
/** * Make sure boundary alpha characters are generated by randomAlphabetic * This test will fail randomly with probability = 4 * (51/52)**1000 ~ 1.58E-8 *//*from w w w. j av a 2 s . c o m*/ @Test public void testRandomAlphabetic() { final char[] testChars = { 'a', 'z', 'A', 'Z' }; final boolean[] found = { false, false, false, false }; for (int i = 0; i < 100; i++) { final String randString = RandomStringUtils.randomAlphabetic(10); for (int j = 0; j < testChars.length; j++) { if (randString.indexOf(testChars[j]) > 0) { found[j] = true; } } } for (int i = 0; i < testChars.length; i++) { if (!found[i]) { fail("alphanumeric character not generated in 1000 attempts: " + testChars[i] + " -- repeated failures indicate a problem "); } } }
From source file:com.b2international.index.SortIndexTest.java
@Test public void sortScore() throws Exception { final List<String> orderedItems = newArrayList(); final Map<String, Data> documents = newHashMap(); for (int i = 0; i < NUM_DOCS; i++) { String item = null;//from w ww. j a va2 s .co m while (item == null || orderedItems.contains(item)) { item = RandomStringUtils.randomAlphabetic(10); } orderedItems.add(item); final Data data = new Data(); data.setField1(item); data.setFloatField(100.0f - i); documents.put(Integer.toString(i), data); } indexDocuments(documents); final Query<Data> descendingQuery = Query.select(Data.class) .where(Expressions.scriptScore(Expressions.matchAll(), Data.Scripts.FIELD_SCORE)).limit(NUM_DOCS) .sortBy(SortBy.SCORE).build(); checkDocumentOrder(descendingQuery, data -> data.getField1(), ImmutableSet.copyOf(orderedItems), String.class); final Query<Data> ascendingQuery = Query.select(Data.class) .where(Expressions.scriptScore(Expressions.matchAll(), Data.Scripts.FIELD_SCORE)).limit(NUM_DOCS) .sortBy(SortBy.field(SortBy.FIELD_SCORE, Order.ASC)).build(); checkDocumentOrder(ascendingQuery, data -> data.getField1(), ImmutableSet.copyOf(Lists.reverse(orderedItems)), String.class); }
From source file:gov.nih.nci.firebird.web.action.investigator.registration.common.ReviewRegistrationFormActionProcessorTest.java
private String getLongText() { return RandomStringUtils.randomAlphabetic(LONG_TEXT_LENGTH); }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.servlet.MMXUserResourceTest.java
private String getUserJsonString() { MMXUserInfo userInfo = new MMXUserInfo(); userInfo.setAppId(RandomStringUtils.randomAlphabetic(10)); userInfo.setEmail(RandomStringUtils.randomAlphabetic(5) + "@magnet.com"); userInfo.setName(RandomStringUtils.randomAlphabetic(5) + " " + RandomStringUtils.randomAlphabetic(5)); userInfo.setUsername(RandomStringUtils.randomAlphabetic(10)); userInfo.setPassword(RandomStringUtils.randomAlphanumeric(4 + RandomUtils.nextInt(6))); return new GsonBuilder().setPrettyPrinting().create().toJson(userInfo); }
From source file:com.haulmont.restapi.service.filter.RestFilterParser.java
protected String generateQueryParamName() { return RandomStringUtils.randomAlphabetic(10); }
From source file:com.wso2telco.services.dep.sandbox.servicefactory.customerinfo.GetProfileRequestHandler.java
private void populateResponse(ManageNumber number, CustomerInfoDTO customerInfoDTO, GetProfileRequestWrapper extendedRequestDTO) throws Exception { Customer customer = new Customer(); CustomerDTOWrapper customerDTOWrapper = new CustomerDTOWrapper(); ObjectMapper mapper = new ObjectMapper(); customer.setMsisdn(number.getNumber()); customer.setTitle(customerInfoDTO.getTitle()); customer.setFirstName(customerInfoDTO.getFirstName()); customer.setLastName(customerInfoDTO.getLastName()); customer.setImsi(CommonUtil.getNullOrTrimmedValue(extendedRequestDTO.getImsi())); customer.setOnBehalfOf(CommonUtil.getNullOrTrimmedValue(extendedRequestDTO.getOnBehalfOf())); customer.setPurchaseCategoryCode(/* ww w. j a va2 s .c o m*/ CommonUtil.getNullOrTrimmedValue(extendedRequestDTO.getPurchaseCategoryCode())); customer.setRequestIdentifier(CommonUtil.getNullOrTrimmedValue(extendedRequestDTO.getRequestIdentifier())); customer.setResponseIdentifier("RES" + RandomStringUtils.randomAlphabetic(8)); customer.setDob(customerInfoDTO.getDob()); customer.setIdentificationType(customerInfoDTO.getIdentificationType()); customer.setIdentificationNumber(customerInfoDTO.getIdentificationNumber()); customer.setAccountType(customerInfoDTO.getAccountType()); customer.setOwnerType(customerInfoDTO.getOwnerType()); customer.setStatus(customerInfoDTO.getStatus()); if (customerInfoDTO.getAddress() != null) { customer.setAddress(mapper.readValue(customerInfoDTO.getAddress(), JsonNode.class)); } if (customerInfoDTO.getAdditionalInfo() != null) { customer.setAdditionalInfo(mapper.readValue(customerInfoDTO.getAdditionalInfo(), JsonNode.class)); } customer.setResourceURL(CommonUtil.getResourceUrl(requestWrapperDTO)); customerDTOWrapper.setCustomer(customer); responseWrapperDTO.setCustomerDTOWrapper(customerDTOWrapper); }
From source file:com.haulmont.cuba.gui.relatedentities.RelatedEntitiesBean.java
@Nullable protected AbstractCondition getManyToManyCondition(List<Object> parentIds, CollectionDatasource datasource, String filterComponentName, String relatedPrimaryKey, MetaDataDescriptor descriptor) { MetaClass metaClass = descriptor.getMetaClass(); String parentPrimaryKey = metadataTools.getPrimaryKeyName(metaClass); CustomCondition customCondition = getParentEntitiesCondition(parentIds, parentPrimaryKey, datasource, filterComponentName, metaClass); String parentEntityAlias = RandomStringUtils.randomAlphabetic(6); String entityAlias = RandomStringUtils.randomAlphabetic(6); String select = String.format("select %s.%s from %s %s ", entityAlias, relatedPrimaryKey, metaClass, parentEntityAlias);//from w ww. j av a2s .c om String joinWhere = String.format("join %s.%s %s where %s.%s in :%s", parentEntityAlias, descriptor.getMetaProperty().getName(), entityAlias, parentEntityAlias, parentPrimaryKey, customCondition.getParam().getName()); String whereString = String.format("{E}.%s in (%s)", relatedPrimaryKey, select + joinWhere); customCondition.setWhere(whereString); return customCondition; }
From source file:com.aliyun.odps.mapred.bridge.LotReducerUDTFTest.java
@Test public void profile() throws IOException, UDFException { BridgeJobConf conf = new BridgeJobConf(); conf.setReducerClass(WordCount.SumReducer.class); conf.setMapOutputKeySchema(SchemaUtils.fromString("word:string")); conf.setMapOutputValueSchema(SchemaUtils.fromString("count:bigint")); conf.setOutputSchema(SchemaUtils.fromString("word:string,count:bigint"), TableInfo.DEFAULT_LABEL); InputUtils.addTable(TableInfo.builder().tableName("in_tbl").build(), conf); OutputUtils.addTable(TableInfo.builder().tableName("out_tbl").build(), conf); MockReducerUDTF udtf = new MockReducerUDTF(conf); udtf.setup(ctx);/*from w w w. jav a 2 s. c om*/ Object[][] testData = new Object[1000000][2]; for (int i = 0; i < 1000000; i++) { Object[] item = new Object[] { new Text(RandomStringUtils.randomAlphabetic(2)), new LongWritable(1) }; testData[i] = item; } udtf.setTestData(testData); udtf.run(); udtf.close(); int sum = 0; for (Object[] item : udtf.getForwarded()) { sum += ((LongWritable) item[1]).get(); } assertEquals(1000000, sum); }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.servlet.MMXUserResourceTest.java
private MMXUserInfo getUserInfo(boolean isAdmin) { MMXUserInfo userInfo = new MMXUserInfo(); userInfo.setAppId(RandomStringUtils.randomAlphabetic(10)); userInfo.setEmail(RandomStringUtils.randomAlphabetic(5) + "@magnet.com"); userInfo.setName(RandomStringUtils.randomAlphabetic(5) + " " + RandomStringUtils.randomAlphabetic(5)); userInfo.setUsername(RandomStringUtils.randomAlphabetic(10)); userInfo.setPassword(RandomStringUtils.randomAlphanumeric(4 + RandomUtils.nextInt(6))); userInfo.setIsAdmin(isAdmin);/*w w w . j av a 2s.c o m*/ return userInfo; }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.api.tags.MMXTopicTagsResourceTest.java
@Test public void testInvalidTagChars() { List<String> tagList1 = Arrays.asList(RandomStringUtils.randomAlphabetic(1000), "tag2", "tag3", "tag4", "tag5", "tag6"); List<String> tagList2 = Arrays.asList("tag1", "", "tag3", "tag4", "tag5", "tag6"); List<String> tagList3 = Arrays.asList("tag1", null, "tag3", "tag4", "tag5", "tag6"); String topicId = TopicHelper.parseNode(appTopicEntityList.get(0).getNodeId()).getName(); //set tags// ww w . j av a 2s . c o m { Response response = setTags(topicId, tagList1); assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode()); response.close(); } //set tags { Response response = setTags(topicId, tagList2); assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode()); response.close(); } //set tags { Response response = setTags(topicId, tagList3); assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode()); response.close(); } }