Search in sources :

Example 31 with User

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

the class UserMapper method userFromId.

public User userFromId(Long id) {
    if (id == null) {
        return null;
    }
    User user = new User();
    user.setId(id);
    return user;
}
Also used : User(com.furyviewer.domain.User)

Example 32 with User

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

the class AccountResourceIntTest method testRegisterDuplicateEmail.

@Test
@Transactional
public void testRegisterDuplicateEmail() throws Exception {
    // Good
    ManagedUserVM validUser = new ManagedUserVM(// id
    null, // login
    "john", // password
    "password", // firstName
    "John", // lastName
    "Doe", // email
    "john@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 email, different login
    ManagedUserVM duplicatedUser = new ManagedUserVM(validUser.getId(), "johnjr", validUser.getPassword(), validUser.getLogin(), validUser.getLastName(), validUser.getEmail(), 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 email
    restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(duplicatedUser))).andExpect(status().is4xxClientError());
    // Duplicate email - with uppercase email address
    final ManagedUserVM userWithUpperCaseEmail = new ManagedUserVM(validUser.getId(), "johnjr", validUser.getPassword(), validUser.getLogin(), validUser.getLastName(), validUser.getEmail().toUpperCase(), true, validUser.getImageUrl(), validUser.getLangKey(), validUser.getCreatedBy(), validUser.getCreatedDate(), validUser.getLastModifiedBy(), validUser.getLastModifiedDate(), validUser.getAuthorities());
    restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(userWithUpperCaseEmail))).andExpect(status().is4xxClientError());
    Optional<User> userDup = userRepository.findOneByLogin("johnjr");
    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 33 with User

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

the class AccountResourceIntTest method testRegisterAdminIsIgnored.

@Test
@Transactional
public void testRegisterAdminIsIgnored() throws Exception {
    ManagedUserVM validUser = new ManagedUserVM(// id
    null, // login
    "badguy", // password
    "password", // firstName
    "Bad", // lastName
    "Guy", // email
    "badguy@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.ADMIN)));
    restMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(validUser))).andExpect(status().isCreated());
    Optional<User> userDup = userRepository.findOneByLogin("badguy");
    assertThat(userDup.isPresent()).isTrue();
    assertThat(userDup.get().getAuthorities()).hasSize(1).containsExactly(authorityRepository.findOne(AuthoritiesConstants.USER));
}
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 34 with User

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

the class AccountResourceIntTest method testSaveExistingEmail.

@Test
@Transactional
@WithMockUser("save-existing-email")
public void testSaveExistingEmail() throws Exception {
    User user = new User();
    user.setLogin("save-existing-email");
    user.setEmail("save-existing-email@example.com");
    user.setPassword(RandomStringUtils.random(60));
    user.setActivated(true);
    userRepository.saveAndFlush(user);
    User anotherUser = new User();
    anotherUser.setLogin("save-existing-email2");
    anotherUser.setEmail("save-existing-email2@example.com");
    anotherUser.setPassword(RandomStringUtils.random(60));
    anotherUser.setActivated(true);
    userRepository.saveAndFlush(anotherUser);
    UserDTO userDTO = new UserDTO(// id
    null, // login
    "not-used", // firstName
    "firstname", // lastName
    "lastname", // email
    "save-existing-email2@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().isBadRequest());
    User updatedUser = userRepository.findOneByLogin("save-existing-email").orElse(null);
    assertThat(updatedUser.getEmail()).isEqualTo("save-existing-email@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 35 with User

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

the class AccountResourceIntTest method testSaveInvalidEmail.

@Test
@Transactional
@WithMockUser("save-invalid-email")
public void testSaveInvalidEmail() throws Exception {
    User user = new User();
    user.setLogin("save-invalid-email");
    user.setEmail("save-invalid-email@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
    "invalid email", // 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().isBadRequest());
    assertThat(userRepository.findOneByEmailIgnoreCase("invalid email")).isNotPresent();
}
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)

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