當前位置: 首頁>>代碼示例>>Java>>正文


Java RandomStringUtils類代碼示例

本文整理匯總了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());
}
 
開發者ID:michaelhoffmantech,項目名稱:patient-portal,代碼行數:17,代碼來源:AccountResourceIntTest.java

示例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());
}
 
開發者ID:deepu105,項目名稱:spring-io,代碼行數:17,代碼來源:AccountResourceIntTest.java

示例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());
}
 
開發者ID:torgcrm,項目名稱:TorgCRM-Server,代碼行數:17,代碼來源:AccountResourceIntTest.java

示例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());
}
 
開發者ID:michaelhoffmantech,項目名稱:patient-portal,代碼行數:17,代碼來源:AccountResourceIntTest.java

示例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();
}
 
開發者ID:michaelhoffmantech,項目名稱:patient-portal,代碼行數:20,代碼來源:AccountResourceIntTest.java

示例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());
}
 
開發者ID:PatternFM,項目名稱:tokamak,代碼行數:22,代碼來源:RolesEndpointAcceptanceTest.java

示例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();
}
 
開發者ID:deepu105,項目名稱:spring-io,代碼行數:17,代碼來源:AccountResourceIntTest.java

示例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());
}
 
開發者ID:asanzdiego,項目名稱:codemotion-2017-taller-de-jhipster,代碼行數:17,代碼來源:AccountResourceIntTest.java

示例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();
}
 
開發者ID:pascalgrimaud,項目名稱:qualitoast,代碼行數:25,代碼來源:AccountResourceIntTest.java

示例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);
	}
}
 
開發者ID:21ca,項目名稱:selenium-testng-template,代碼行數:25,代碼來源:DownloadUtils.java

示例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();
}
 
開發者ID:michaelhoffmantech,項目名稱:patient-portal,代碼行數:25,代碼來源:AccountResourceIntTest.java

示例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);
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:35,代碼來源:SocialService.java

示例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;
    }
 
開發者ID:lmartire,項目名稱:DoApp,代碼行數:32,代碼來源:GenericPathPatternURIGenerator.java

示例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();
}
 
開發者ID:conf4j,項目名稱:conf4j,代碼行數:14,代碼來源:ConsulFileConfigurationSourceTest.java


注:本文中的org.apache.commons.lang3.RandomStringUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。