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:gov.guilin.controller.shop.CartController.java
/** * /* w w w .ja v a 2 s .co m*/ */ @RequestMapping(value = "/add", method = RequestMethod.POST) public @ResponseBody Message add(Long id, Integer quantity, HttpServletRequest request, HttpServletResponse response) { if (quantity == null || quantity < 1) { return ERROR_MESSAGE; } Product product = productService.find(id); if (product == null) { return Message.warn("shop.cart.productNotExsit"); } if (!product.getIsMarketable()) { return Message.warn("shop.cart.productNotMarketable"); } if (product.getIsGift()) { return Message.warn("shop.cart.notForSale"); } Cart cart = cartService.getCurrent(); Member member = memberService.getCurrent(); if (cart == null) { cart = new Cart(); cart.setKey(UUID.randomUUID().toString() + DigestUtils.md5Hex(RandomStringUtils.randomAlphabetic(30))); cart.setMember(member); cartService.save(cart); } if (Cart.MAX_PRODUCT_COUNT != null && cart.getCartItems().size() >= Cart.MAX_PRODUCT_COUNT) { return Message.warn("shop.cart.addCountNotAllowed", Cart.MAX_PRODUCT_COUNT); } if (cart.contains(product)) { CartItem cartItem = cart.getCartItem(product); if (CartItem.MAX_QUANTITY != null && cartItem.getQuantity() + quantity > CartItem.MAX_QUANTITY) { return Message.warn("shop.cart.maxCartItemQuantity", CartItem.MAX_QUANTITY); } if (product.getStock() != null && cartItem.getQuantity() + quantity > product.getAvailableStock()) { return Message.warn("shop.cart.productLowStock"); } cartItem.add(quantity); cartItemService.update(cartItem); } else { if (CartItem.MAX_QUANTITY != null && quantity > CartItem.MAX_QUANTITY) { return Message.warn("shop.cart.maxCartItemQuantity", CartItem.MAX_QUANTITY); } if (product.getStock() != null && quantity > product.getAvailableStock()) { return Message.warn("shop.cart.productLowStock"); } CartItem cartItem = new CartItem(); cartItem.setQuantity(quantity); cartItem.setProduct(product); cartItem.setCart(cart); cartItemService.save(cartItem); cart.getCartItems().add(cartItem); } if (member == null) { WebUtils.addCookie(request, response, Cart.ID_COOKIE_NAME, cart.getId().toString(), Cart.TIMEOUT); WebUtils.addCookie(request, response, Cart.KEY_COOKIE_NAME, cart.getKey(), Cart.TIMEOUT); } return Message.success("shop.cart.addSuccess", cart.getQuantity(), currency(cart.getEffectivePrice(), true, false)); }
From source file:com.comcast.viper.flume2storm.event.F2SEventFactory.java
/** * @return An event with a payload containing a random alpha-numeric string * (and no headers)/* w w w . j ava 2 s . com*/ */ public F2SEvent createRandomWithHeaders() { F2SEventBuilder builder = new F2SEventBuilder(); for (int i = 0; i < random.nextInt(5); i++) { builder.header("H" + i, RandomStringUtils.randomAlphabetic(random.nextInt(64) + 1)); } builder.body(RandomStringUtils.randomAlphanumeric(random.nextInt(128) + 1).getBytes()); return builder.get(); }
From source file:com.dp2345.controller.mall.PasswordController.java
/** * ???//from ww w . j a v a 2s . co m */ @RequestMapping(value = "/find", method = RequestMethod.POST) public @ResponseBody Message find(String captchaId, String captcha, String username, String email) { if (!captchaService.isValid(CaptchaType.findPassword, captchaId, captcha)) { return Message.error("shop.captcha.invalid"); } if (StringUtils.isEmpty(username) || StringUtils.isEmpty(email)) { return Message.error("shop.common.invalid"); } Member member = memberService.findByUsername(username); if (member == null) { return Message.error("shop.password.memberNotExist"); } if (!member.getEmail().equalsIgnoreCase(email)) { return Message.error("shop.password.invalidEmail"); } Setting setting = SettingUtils.get(); SafeKey safeKey = new SafeKey(); safeKey.setValue(UUID.randomUUID().toString() + DigestUtils.md5Hex(RandomStringUtils.randomAlphabetic(30))); safeKey.setExpire(setting.getSafeKeyExpiryTime() != 0 ? DateUtils.addMinutes(new Date(), setting.getSafeKeyExpiryTime()) : null); member.setSafeKey(safeKey); memberService.update(member); mailService.sendFindPasswordMail(member.getEmail(), member.getUsername(), safeKey); return Message.success("shop.password.mailSuccess"); }
From source file:edu.sampleu.admin.CampusAftBase.java
protected void saveAndReload() throws InterruptedException { checkForDocError();//w w w. j a v a 2 s. c om 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:integration.report.ListIdentifiersIT.java
@Test public void testListPremisFullIdentifiers() throws Exception { createEntity(TestUtil.createTestEntity(RandomStringUtils.randomAlphabetic(16))); HttpResponse resp = getOAIPMHResponse(VerbType.LIST_IDENTIFIERS.value(), null, "premis-full-v2", null, null, null);/* w ww . j a v a 2 s .com*/ assertEquals(200, resp.getStatusLine().getStatusCode()); OAIPMHtype oaipmh = ((JAXBElement<OAIPMHtype>) this.unmarshaller.unmarshal(resp.getEntity().getContent())) .getValue(); assertEquals(0, oaipmh.getError().size()); assertNotNull(oaipmh.getRequest()); assertEquals(VerbType.LIST_IDENTIFIERS.value(), oaipmh.getRequest().getVerb().value()); assertTrue(oaipmh.getListIdentifiers().getHeader().size() > 0); }
From source file:edu.sampleu.admin.ConfigParameterTypeCreateNewAftBase.java
public void testConfigParameterTypeCreateNew() throws Exception { selectFrameIframePortlet();/*from w ww.j a v a 2 s .co m*/ waitAndClickByXpath(CREATE_NEW_XPATH); waitAndTypeByName("document.documentHeader.documentDescription", "Test description of parameter type create " + AutomatedFunctionalTestUtils.createUniqueDtsPlusTwoRandomCharsNot9Digits()); waitAndTypeByName("document.newMaintainableObject.code", RandomStringUtils.randomAlphabetic(5)); waitAndTypeByName("document.newMaintainableObject.name", "Test1ParmTypeCode" + AutomatedFunctionalTestUtils.createUniqueDtsPlusTwoRandomChars()); waitAndClickByName("methodToCall.route"); checkForDocError(); waitAndClickByName("methodToCall.close"); // waitAndClickByName("methodToCall.processAnswer.button1"); }
From source file:mitm.application.djigzo.xml.GenerateTestData.java
private String generateEmail() { return RandomStringUtils.randomAlphabetic(15) + "@" + RandomStringUtils.randomAlphabetic(10) + TLDs[random.nextInt(TLDs.length)]; }
From source file:edu.sampleu.main.TermMaintenanceEditCopyAft.java
protected void testCopyEditExistingTermWithParameter() throws InterruptedException { // Copy an existing term to test copy and to ensure we don't edit term T1000 copyExistingTermWithParameter();// w w w . j a v a 2 s . c o m // Edit a term selectTopFrame(); waitAndClickByLinkText("Main Menu", ""); waitAndClickByLinkText("Term Lookup", ""); selectFrameIframePortlet(); waitAndTypeByName("lookupCriteria[id]", "1*"); waitAndClickByXpath("//button[contains(text(),'Search')]"); waitAndClickEdit(); waitForTextPresent("campusSize"); waitForTextPresent("java.lang.Integer"); waitForElementPresentByXpath( "//label[contains(text(),'Specification Description')]/span[contains(text(),'Size in # of students of the campus')]"); clearTextByName("document.newMaintainableObject.dataObject.description"); String randomCode = RandomStringUtils.randomAlphabetic(9).toUpperCase(); waitAndTypeByName("document.newMaintainableObject.dataObject.description", "Edit Term - New ID " + StringUtils.substring(randomCode, 0, 4)); clearTextByName("document.newMaintainableObject.dataObject.parametersMap[Campus Code]"); waitAndTypeByName("document.newMaintainableObject.dataObject.parametersMap[Campus Code]", randomCode); submitSuccessfully(); waitForTextPresent(randomCode); }
From source file:de.hybris.platform.media.storage.impl.MediaCacheRecreatorTest.java
private void createRandomCachedFiles(final int num, final String folderName) throws IOException { for (int i = 0; i < num; i++) { final String location = RandomStringUtils.randomAlphabetic(10); Files.createTempFile(Paths.get(System.getProperty("java.io.tmpdir"), folderName), new String(Base64.encode(location.getBytes())) + DefaultLocalMediaFileCacheService.CACHE_FILE_NAME_DELIM, ".bin"); }/*from w ww . j av a2s . c om*/ }
From source file:com.linkedin.paldb.TestReadThroughput.java
private Measure measure(int keysCount, int valueLength, double cacheSizeRatio, final boolean frequentReads) { // Generate keys long seed = 4242; final Integer[] keys = GenerateTestData.generateRandomIntKeys(keysCount, Integer.MAX_VALUE, seed); // Write store File storeFile = new File(TEST_FOLDER, "paldb" + keysCount + "-" + valueLength + ".store"); StoreWriter writer = PalDB.createWriter(storeFile, new Configuration()); for (Integer key : keys) { if (valueLength == 0) { writer.put(key.toString(), Boolean.TRUE); } else {/* w ww . jav a 2s . com*/ writer.put(key.toString(), RandomStringUtils.randomAlphabetic(valueLength)); } } writer.close(); // Get reader long cacheSize = 0; Configuration config = PalDB.newConfiguration(); if (cacheSizeRatio > 0) { cacheSize = (long) (storeFile.length() * cacheSizeRatio); config.set(Configuration.CACHE_ENABLED, "true"); config.set(Configuration.CACHE_BYTES, String.valueOf(cacheSize)); } else { config.set(Configuration.CACHE_ENABLED, "false"); } final StoreReader reader = PalDB.createReader(storeFile, config); // Measure NanoBench nanoBench = NanoBench.create(); nanoBench.cpuOnly().warmUps(5).measurements(20).measure("Measure %d reads for %d keys with cache", new Runnable() { @Override public void run() { Random r = new Random(); int length = keys.length; for (int i = 0; i < READS; i++) { int index; if (i % 2 == 0 && frequentReads) { index = r.nextInt(length / 10); } else { index = r.nextInt(length); } Integer key = keys[index]; reader.get(key.toString()); } } }); // Close reader.close(); // Return measure double rps = READS * nanoBench.getTps(); return new Measure(storeFile.length(), rps, valueLength, cacheSize, keys.length); }