Search in sources :

Example 6 with User

use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.

the class AccountResourceIntTest method testFinishPasswordReset.

@Test
@Transactional
public void testFinishPasswordReset() throws Exception {
    User user = new User();
    user.setPassword(RandomStringUtils.random(60));
    user.setLogin("finish-password-reset");
    user.setEmail("finish-password-reset@example.com");
    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();
}
Also used : KeyAndPasswordVM(com.furyviewer.web.rest.vm.KeyAndPasswordVM) User(com.furyviewer.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with User

use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.

the class AccountResourceIntTest method testRequestPasswordReset.

@Test
@Transactional
public void testRequestPasswordReset() throws Exception {
    User user = new User();
    user.setPassword(RandomStringUtils.random(60));
    user.setActivated(true);
    user.setLogin("password-reset");
    user.setEmail("password-reset@example.com");
    userRepository.saveAndFlush(user);
    restMvc.perform(post("/api/account/reset-password/init").content("password-reset@example.com")).andExpect(status().isOk());
}
Also used : User(com.furyviewer.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with User

use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.

the class AccountResourceIntTest method testSaveExistingEmailAndLogin.

@Test
@Transactional
@WithMockUser("save-existing-email-and-login")
public void testSaveExistingEmailAndLogin() throws Exception {
    User user = new User();
    user.setLogin("save-existing-email-and-login");
    user.setEmail("save-existing-email-and-login@example.com");
    user.setPassword(RandomStringUtils.random(60));
    user.setActivated(true);
    userRepository.saveAndFlush(user);
    UserDTO userDTO = new UserDTO(// id
    null, // login
    "not-used", // firstName
    "firstname", // lastName
    "lastname", // email
    "save-existing-email-and-login@example.com", // activated
    false, // imageUrl
    "http://placehold.it/50x50", // langKey
    Constants.DEFAULT_LANGUAGE, // createdBy
    null, // createdDate
    null, // lastModifiedBy
    null, // lastModifiedDate
    null, new HashSet<>(Collections.singletonList(AuthoritiesConstants.ADMIN)));
    restMvc.perform(post("/api/account").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(userDTO))).andExpect(status().isOk());
    User updatedUser = userRepository.findOneByLogin("save-existing-email-and-login").orElse(null);
    assertThat(updatedUser.getEmail()).isEqualTo("save-existing-email-and-login@example.com");
}
Also used : User(com.furyviewer.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) UserDTO(com.furyviewer.service.dto.UserDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with User

use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.

the class AccountResourceIntTest method testRegisterDuplicateLogin.

@Test
@Transactional
public void testRegisterDuplicateLogin() throws Exception {
    // Good
    ManagedUserVM validUser = new ManagedUserVM(// id
    null, // login
    "alice", // password
    "password", // firstName
    "Alice", // lastName
    "Something", // email
    "alice@example.com", // activated
    true, // imageUrl
    "http://placehold.it/50x50", // langKey
    Constants.DEFAULT_LANGUAGE, // createdBy
    null, // createdDate
    null, // lastModifiedBy
    null, // lastModifiedDate
    null, new HashSet<>(Collections.singletonList(AuthoritiesConstants.USER)));
    // Duplicate login, different email
    ManagedUserVM duplicatedUser = new ManagedUserVM(validUser.getId(), validUser.getLogin(), validUser.getPassword(), validUser.getFirstName(), validUser.getLastName(), "alicejr@example.com", true, validUser.getImageUrl(), validUser.getLangKey(), validUser.getCreatedBy(), validUser.getCreatedDate(), validUser.getLastModifiedBy(), validUser.getLastModifiedDate(), validUser.getAuthorities());
    // Good user
    restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(validUser))).andExpect(status().isCreated());
    // Duplicate login
    restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(duplicatedUser))).andExpect(status().is4xxClientError());
    Optional<User> userDup = userRepository.findOneByEmailIgnoreCase("alicejr@example.com");
    assertThat(userDup.isPresent()).isFalse();
}
Also used : User(com.furyviewer.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ManagedUserVM(com.furyviewer.web.rest.vm.ManagedUserVM) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with User

use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.

the class AccountResourceIntTest method testActivateAccount.

@Test
@Transactional
public void testActivateAccount() throws Exception {
    final String activationKey = "some activation key";
    User user = new User();
    user.setLogin("activate-account");
    user.setEmail("activate-account@example.com");
    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();
}
Also used : User(com.furyviewer.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

User (com.furyviewer.domain.User)65 Test (org.junit.Test)52 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)52 Transactional (org.springframework.transaction.annotation.Transactional)37 WithMockUser (org.springframework.security.test.context.support.WithMockUser)22 ManagedUserVM (com.furyviewer.web.rest.vm.ManagedUserVM)16 Authority (com.furyviewer.domain.Authority)6 UserDTO (com.furyviewer.service.dto.UserDTO)5 Instant (java.time.Instant)4 MimeMessage (javax.mail.internet.MimeMessage)4 Timed (com.codahale.metrics.annotation.Timed)2 KeyAndPasswordVM (com.furyviewer.web.rest.vm.KeyAndPasswordVM)2 LoginVM (com.furyviewer.web.rest.vm.LoginVM)2 UserExt (com.furyviewer.domain.UserExt)1 UserRepository (com.furyviewer.repository.UserRepository)1 BadRequestAlertException (com.furyviewer.web.rest.errors.BadRequestAlertException)1 EmailAlreadyUsedException (com.furyviewer.web.rest.errors.EmailAlreadyUsedException)1 LoginAlreadyUsedException (com.furyviewer.web.rest.errors.LoginAlreadyUsedException)1 URI (java.net.URI)1 java.util (java.util)1