本文整理匯總了Java中org.apache.commons.lang3.RandomStringUtils類的典型用法代碼示例。如果您正苦於以下問題:Java RandomStringUtils類的具體用法?Java RandomStringUtils怎麽用?Java RandomStringUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RandomStringUtils類屬於org.apache.commons.lang3包,在下文中一共展示了RandomStringUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testChangePasswordTooLong
import org.apache.commons.lang3.RandomStringUtils; //導入依賴的package包/類
@Test
@Transactional
@WithMockUser("change-password-too-long")
public void testChangePasswordTooLong() throws Exception {
User user = new User();
user.setPassword(RandomStringUtils.random(60));
user.setLogin("change-password-too-long");
user.setEmail("[email protected]");
userRepository.saveAndFlush(user);
restMvc.perform(post("/api/account/change_password").content(RandomStringUtils.random(101)))
.andExpect(status().isBadRequest());
User updatedUser = userRepository.findOneByLogin("change-password-too-long").orElse(null);
assertThat(updatedUser.getPassword()).isEqualTo(user.getPassword());
}
示例2: testChangePasswordTooSmall
import org.apache.commons.lang3.RandomStringUtils; //導入依賴的package包/類
@Test
@Transactional
@WithMockUser("change-password-too-small")
public void testChangePasswordTooSmall() throws Exception {
User user = new User();
user.setPassword(RandomStringUtils.random(60));
user.setLogin("change-password-too-small");
user.setEmail("[email protected]");
userRepository.saveAndFlush(user);
restMvc.perform(post("/api/account/change_password").content("new"))
.andExpect(status().isBadRequest());
User updatedUser = userRepository.findOneByLogin("change-password-too-small").orElse(null);
assertThat(updatedUser.getPassword()).isEqualTo(user.getPassword());
}
示例3: testChangePasswordEmpty
import org.apache.commons.lang3.RandomStringUtils; //導入依賴的package包/類
@Test
@Transactional
@WithMockUser("change-password-empty")
public void testChangePasswordEmpty() throws Exception {
User user = new User();
user.setPassword(RandomStringUtils.random(60));
user.setLogin("change-password-empty");
user.setEmail("[email protected]");
userRepository.saveAndFlush(user);
restMvc.perform(post("/api/account/change-password").content(RandomStringUtils.random(0)))
.andExpect(status().isBadRequest());
User updatedUser = userRepository.findOneByLogin("change-password-empty").orElse(null);
assertThat(updatedUser.getPassword()).isEqualTo(user.getPassword());
}
示例4: testChangePasswordEmpty
import org.apache.commons.lang3.RandomStringUtils; //導入依賴的package包/類
@Test
@Transactional
@WithMockUser("change-password-empty")
public void testChangePasswordEmpty() throws Exception {
User user = new User();
user.setPassword(RandomStringUtils.random(60));
user.setLogin("change-password-empty");
user.setEmail("[email protected]");
userRepository.saveAndFlush(user);
restMvc.perform(post("/api/account/change_password").content(RandomStringUtils.random(0)))
.andExpect(status().isBadRequest());
User updatedUser = userRepository.findOneByLogin("change-password-empty").orElse(null);
assertThat(updatedUser.getPassword()).isEqualTo(user.getPassword());
}
示例5: testActivateAccount
import org.apache.commons.lang3.RandomStringUtils; //導入依賴的package包/類
@Test
@Transactional
public void testActivateAccount() throws Exception {
final String activationKey = "some activation key";
User user = new User();
user.setLogin("activate-account");
user.setEmail("[email protected]");
user.setPassword(RandomStringUtils.random(60));
user.setActivated(false);
user.setActivationKey(activationKey);
userRepository.saveAndFlush(user);
restMvc.perform(get("/api/activate?key={activationKey}", activationKey))
.andExpect(status().isOk());
user = userRepository.findOneByLogin(user.getLogin()).orElse(null);
assertThat(user.getActivated()).isTrue();
}
示例6: shouldBeAbleToUpdateARole
import org.apache.commons.lang3.RandomStringUtils; //導入依賴的package包/類
@Test
public void shouldBeAbleToUpdateARole() {
RoleRepresentation role = role().thatIs().persistent(token).build();
pause(1000);
role.setName(RandomStringUtils.randomAlphabetic(10));
Result<RoleRepresentation> result = client.update(role, token.getAccessToken());
assertThat(result).accepted().withResponseCode(200);
RoleRepresentation updated = result.getInstance();
assertThat(updated.getId()).startsWith("rol_");
assertThat(updated.getCreated()).isNotNull();
assertThat(updated.getUpdated()).isNotNull();
assertThat(updated.getCreated()).isEqualTo(role.getCreated());
assertThat(updated.getCreated()).isBefore(updated.getUpdated());
assertThat(updated.getUpdated()).isAfter(role.getUpdated());
assertThat(updated.getName()).isEqualTo(role.getName());
}
示例7: testChangePassword
import org.apache.commons.lang3.RandomStringUtils; //導入依賴的package包/類
@Test
@Transactional
@WithMockUser("change-password")
public void testChangePassword() throws Exception {
User user = new User();
user.setPassword(RandomStringUtils.random(60));
user.setLogin("change-password");
user.setEmail("[email protected]");
userRepository.saveAndFlush(user);
restMvc.perform(post("/api/account/change_password").content("new password"))
.andExpect(status().isOk());
User updatedUser = userRepository.findOneByLogin("change-password").orElse(null);
assertThat(passwordEncoder.matches("new password", updatedUser.getPassword())).isTrue();
}
示例8: testChangePasswordTooSmall
import org.apache.commons.lang3.RandomStringUtils; //導入依賴的package包/類
@Test
@Transactional
@WithMockUser("change-password-too-small")
public void testChangePasswordTooSmall() throws Exception {
User user = new User();
user.setPassword(RandomStringUtils.random(60));
user.setLogin("change-password-too-small");
user.setEmail("[email protected]");
userRepository.saveAndFlush(user);
restMvc.perform(post("/api/account/change-password").content("new"))
.andExpect(status().isBadRequest());
User updatedUser = userRepository.findOneByLogin("change-password-too-small").orElse(null);
assertThat(updatedUser.getPassword()).isEqualTo(user.getPassword());
}
示例9: testFinishPasswordResetTooSmall
import org.apache.commons.lang3.RandomStringUtils; //導入依賴的package包/類
@Test
@Transactional
public void testFinishPasswordResetTooSmall() throws Exception {
User user = new User();
user.setPassword(RandomStringUtils.random(60));
user.setLogin("finish-password-reset-too-small");
user.setEmail("[email protected]");
user.setResetDate(Instant.now().plusSeconds(60));
user.setResetKey("reset key too small");
userRepository.saveAndFlush(user);
KeyAndPasswordVM keyAndPassword = new KeyAndPasswordVM();
keyAndPassword.setKey(user.getResetKey());
keyAndPassword.setNewPassword("foo");
restMvc.perform(
post("/api/account/reset-password/finish")
.contentType(TestUtil.APPLICATION_JSON_UTF8)
.content(TestUtil.convertObjectToJsonBytes(keyAndPassword)))
.andExpect(status().isBadRequest());
User updatedUser = userRepository.findOneByLogin(user.getLogin()).orElse(null);
assertThat(passwordEncoder.matches(keyAndPassword.getNewPassword(), updatedUser.getPassword())).isFalse();
}
示例10: prepareData
import org.apache.commons.lang3.RandomStringUtils; //導入依賴的package包/類
@Before
public void prepareData(){
TodoEntity nullNameTodo = new TodoEntity();
TodoEntity emptyNameTodo = new TodoEntity();
emptyNameTodo.setName("");
TodoEntity emptyNameButWithSpacesTodo = new TodoEntity();
emptyNameButWithSpacesTodo.setName(" ");
TodoEntity name101charsTodo = new TodoEntity();
name101charsTodo.setName(RandomStringUtils.randomAlphanumeric(101));
TodoEntity name500CharsTodo = new TodoEntity();
name500CharsTodo.setName(RandomStringUtils.randomAlphanumeric(500));
improperNameTodoList = Arrays.asList(nullNameTodo, emptyNameTodo, emptyNameButWithSpacesTodo, name101charsTodo, name500CharsTodo);
TodoEntity name100charsTodo = new TodoEntity();
name100charsTodo.setName(RandomStringUtils.randomAlphanumeric(100));
TodoEntity nameOneCharTodo = new TodoEntity();
nameOneCharTodo.setName("a");
properNameTodoList = Arrays.asList(name100charsTodo, nameOneCharTodo);
}
開發者ID:lukedd3,項目名稱:todo-list-webapp-angular2-spring-mvc-boot-data-rest,代碼行數:27,代碼來源:TodoControllerIntegrationTest.java
示例11: download
import org.apache.commons.lang3.RandomStringUtils; //導入依賴的package包/類
public static final String download(RemoteWebDriver driver, String url) {
String folder = DOWNLOAD_PATH + RandomStringUtils.randomAlphabetic(10);
new File(folder).mkdirs();
Map<String, String> headers = new HashMap<String, String>();
headers.put("Cookie", getCookie(driver));
byte[] data = HttpUtils.get(url, headers);
try {
String filename;
String contentDisposition = headers.get("Content-Disposition");
if (StringUtils.contains(contentDisposition, "=")) {
filename = contentDisposition.substring(contentDisposition.indexOf("=") + 1);
} else {
filename = new URL(url).getPath();
if (filename.contains("/")) {
filename = filename.substring(filename.lastIndexOf("/") + 1);
}
}
IOUtils.write(data, new FileOutputStream(folder + "/" + filename));
return folder + "/" + filename;
} catch (Exception e) {
throw new RuntimeException("Download failed!", e);
}
}
示例12: testFinishPasswordReset
import org.apache.commons.lang3.RandomStringUtils; //導入依賴的package包/類
@Test
@Transactional
public void testFinishPasswordReset() throws Exception {
User user = new User();
user.setPassword(RandomStringUtils.random(60));
user.setLogin("finish-password-reset");
user.setEmail("[email protected]");
user.setResetDate(Instant.now().plusSeconds(60));
user.setResetKey("reset key");
userRepository.saveAndFlush(user);
KeyAndPasswordVM keyAndPassword = new KeyAndPasswordVM();
keyAndPassword.setKey(user.getResetKey());
keyAndPassword.setNewPassword("new password");
restMvc.perform(
post("/api/account/reset_password/finish")
.contentType(TestUtil.APPLICATION_JSON_UTF8)
.content(TestUtil.convertObjectToJsonBytes(keyAndPassword)))
.andExpect(status().isOk());
User updatedUser = userRepository.findOneByLogin(user.getLogin()).orElse(null);
assertThat(passwordEncoder.matches(keyAndPassword.getNewPassword(), updatedUser.getPassword())).isTrue();
}
示例13: createUserIfNotExist
import org.apache.commons.lang3.RandomStringUtils; //導入依賴的package包/類
private User createUserIfNotExist(UserProfile userProfile, String langKey, String imageUrl) {
String email = userProfile.getEmail();
if (StringUtils.isBlank(email)) {
log.error("Cannot create social user because email is null");
throw new IllegalArgumentException("Email cannot be null");
} else {
Optional<UserLogin> user = userLoginRepository.findOneByLoginIgnoreCase(email);
if (user.isPresent()) {
log.info("User already exist associate the connection to this account");
return user.get().getUser();
}
}
String encryptedPassword = passwordEncoder.encode(RandomStringUtils.random(10));
Set<Authority> authorities = new HashSet<>(1);
authorities.add(authorityRepository.findOne("ROLE_USER"));
User newUser = new User();
newUser.setUserKey(UUID.randomUUID().toString());
newUser.setPassword(encryptedPassword);
newUser.setFirstName(userProfile.getFirstName());
newUser.setLastName(userProfile.getLastName());
newUser.setActivated(true);
newUser.setAuthorities(authorities);
newUser.setLangKey(langKey);
newUser.setImageUrl(imageUrl);
UserLogin userLogin = new UserLogin();
userLogin.setUser(newUser);
userLogin.setTypeKey(UserLoginType.EMAIL.getValue());
userLogin.setLogin(email);
newUser.getLogins().add(userLogin);
return userRepository.save(newUser);
}
示例14: getSemivalidSchemeHostPortPathPatternURIMalIntent
import org.apache.commons.lang3.RandomStringUtils; //導入依賴的package包/類
public static MalIntent getSemivalidSchemeHostPortPathPatternURIMalIntent(IntentDataInfo datafield) {
MalIntent mal = new MalIntent(datafield);
String scheme = datafield.scheme;
String host = datafield.host;
host = host.replace("*", RandomStringUtils.randomAlphanumeric(10));
String pathPattern = datafield.pathPattern;
String semivalidPathPattern;
if (pathPattern.contains(".*") || pathPattern.contains("*")) {
semivalidPathPattern = pathPattern.replace(".*", RandomStringUtils.randomAlphabetic(10));
semivalidPathPattern = semivalidPathPattern.replace("*", RandomStringUtils.randomAlphanumeric(10));
if (pathPattern.charAt(0) == '/') {
mal.setData(Uri.parse(scheme + "://" + host + semivalidPathPattern));
}
mal.setData(Uri.parse(scheme + "://" + host + "/" + semivalidPathPattern));
} else {
semivalidPathPattern = RandomStringUtils.randomAlphabetic(10);
if (pathPattern.equals("") || pathPattern.charAt(0) == '/') {
mal.setData(Uri.parse(scheme + "://" + host + semivalidPathPattern));
}
mal.setData(Uri.parse(scheme + "://" + host + "/" + semivalidPathPattern));
}
return mal;
}
示例15: testReloadStrategyIsNotNullWhenCallingReloadOnChange
import org.apache.commons.lang3.RandomStringUtils; //導入依賴的package包/類
@Test
public void testReloadStrategyIsNotNullWhenCallingReloadOnChange() throws Exception {
ConsulFileConfigurationSource source;
String filePath = RandomStringUtils.randomAlphanumeric(15);
source = createConfigurationSource(filePath, true, false);
assertThat(source.shouldWatchForChange()).isFalse();
assertThat(source.getReloadStrategy()).isNull();
source = createConfigurationSource(filePath, true, true);
assertThat(source.shouldWatchForChange()).isTrue();
assertThat(source.getReloadStrategy()).isNotNull();
}