本文整理汇总了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();
}