Search in sources :

Example 56 with User

use of com.arnaugarcia.uplace.domain.User in project uplace.es by Uplace.

the class AccountResourceIntTest method testRegisterDuplicateEmail.

@Test
@Transactional
public void testRegisterDuplicateEmail() throws Exception {
    // Good
    ManagedUserVM validUser = new ManagedUserVM();
    validUser.setLogin("john");
    validUser.setPassword("password");
    validUser.setFirstName("John");
    validUser.setLastName("Doe");
    validUser.setEmail("john@example.com");
    validUser.setActivated(true);
    validUser.setImageUrl("http://placehold.it/50x50");
    validUser.setLangKey(Constants.DEFAULT_LANGUAGE);
    validUser.setAuthorities(Collections.singleton(AuthoritiesConstants.USER));
    // Duplicate email, different login
    ManagedUserVM duplicatedUser = new ManagedUserVM();
    duplicatedUser.setLogin("johnjr");
    duplicatedUser.setPassword(validUser.getPassword());
    duplicatedUser.setFirstName(validUser.getFirstName());
    duplicatedUser.setLastName(validUser.getLastName());
    duplicatedUser.setEmail(validUser.getEmail());
    duplicatedUser.setActivated(validUser.isActivated());
    duplicatedUser.setImageUrl(validUser.getImageUrl());
    duplicatedUser.setLangKey(validUser.getLangKey());
    duplicatedUser.setCreatedBy(validUser.getCreatedBy());
    duplicatedUser.setCreatedDate(validUser.getCreatedDate());
    duplicatedUser.setLastModifiedBy(validUser.getLastModifiedBy());
    duplicatedUser.setLastModifiedDate(validUser.getLastModifiedDate());
    duplicatedUser.setAuthorities(new HashSet<>(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
    ManagedUserVM userWithUpperCaseEmail = new ManagedUserVM();
    userWithUpperCaseEmail.setId(validUser.getId());
    userWithUpperCaseEmail.setLogin("johnjr");
    userWithUpperCaseEmail.setPassword(validUser.getPassword());
    userWithUpperCaseEmail.setFirstName(validUser.getFirstName());
    userWithUpperCaseEmail.setLastName(validUser.getLastName());
    userWithUpperCaseEmail.setEmail(validUser.getEmail().toUpperCase());
    userWithUpperCaseEmail.setActivated(validUser.isActivated());
    userWithUpperCaseEmail.setImageUrl(validUser.getImageUrl());
    userWithUpperCaseEmail.setLangKey(validUser.getLangKey());
    userWithUpperCaseEmail.setCreatedBy(validUser.getCreatedBy());
    userWithUpperCaseEmail.setCreatedDate(validUser.getCreatedDate());
    userWithUpperCaseEmail.setLastModifiedBy(validUser.getLastModifiedBy());
    userWithUpperCaseEmail.setLastModifiedDate(validUser.getLastModifiedDate());
    userWithUpperCaseEmail.setAuthorities(new HashSet<>(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.arnaugarcia.uplace.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ManagedUserVM(com.arnaugarcia.uplace.web.rest.vm.ManagedUserVM) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 57 with User

use of com.arnaugarcia.uplace.domain.User in project uplace.es by Uplace.

the class UserJWTControllerIntTest method testAuthorize.

@Test
@Transactional
public void testAuthorize() throws Exception {
    User user = new User();
    user.setLogin("user-jwt-controller");
    user.setEmail("user-jwt-controller@example.com");
    user.setActivated(true);
    user.setPassword(passwordEncoder.encode("test"));
    userRepository.saveAndFlush(user);
    LoginVM login = new LoginVM();
    login.setUsername("user-jwt-controller");
    login.setPassword("test");
    mockMvc.perform(post("/api/authenticate").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(login))).andExpect(status().isOk()).andExpect(jsonPath("$.id_token").isString()).andExpect(jsonPath("$.id_token").isNotEmpty()).andExpect(header().string("Authorization", not(nullValue()))).andExpect(header().string("Authorization", not(isEmptyString())));
}
Also used : LoginVM(com.arnaugarcia.uplace.web.rest.vm.LoginVM) User(com.arnaugarcia.uplace.domain.User) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 58 with User

use of com.arnaugarcia.uplace.domain.User in project uplace.es by Uplace.

the class MailServiceIntTest method testSendActivationEmail.

@Test
public void testSendActivationEmail() throws Exception {
    User user = new User();
    user.setLangKey(Constants.DEFAULT_LANGUAGE);
    user.setLogin("john");
    user.setEmail("john.doe@example.com");
    mailService.sendActivationEmail(user);
    verify(javaMailSender).send((MimeMessage) messageCaptor.capture());
    MimeMessage message = (MimeMessage) messageCaptor.getValue();
    assertThat(message.getAllRecipients()[0].toString()).isEqualTo(user.getEmail());
    assertThat(message.getFrom()[0].toString()).isEqualTo("test@localhost");
    assertThat(message.getContent().toString()).isNotEmpty();
    assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
}
Also used : User(com.arnaugarcia.uplace.domain.User) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 59 with User

use of com.arnaugarcia.uplace.domain.User in project uplace.es by Uplace.

the class UserResourceIntTest method createUserWithExistingId.

@Test
@Transactional
public void createUserWithExistingId() throws Exception {
    int databaseSizeBeforeCreate = userRepository.findAll().size();
    ManagedUserVM managedUserVM = new ManagedUserVM();
    managedUserVM.setId(1L);
    managedUserVM.setLogin(DEFAULT_LOGIN);
    managedUserVM.setPassword(DEFAULT_PASSWORD);
    managedUserVM.setFirstName(DEFAULT_FIRSTNAME);
    managedUserVM.setLastName(DEFAULT_LASTNAME);
    managedUserVM.setEmail(DEFAULT_EMAIL);
    managedUserVM.setActivated(true);
    managedUserVM.setImageUrl(DEFAULT_IMAGEURL);
    managedUserVM.setLangKey(DEFAULT_LANGKEY);
    managedUserVM.setAuthorities(Collections.singleton(AuthoritiesConstants.USER));
    // An entity with an existing ID cannot be created, so this API call must fail
    restUserMockMvc.perform(post("/api/users").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(managedUserVM))).andExpect(status().isBadRequest());
    // Validate the User in the database
    List<User> userList = userRepository.findAll();
    assertThat(userList).hasSize(databaseSizeBeforeCreate);
}
Also used : User(com.arnaugarcia.uplace.domain.User) ManagedUserVM(com.arnaugarcia.uplace.web.rest.vm.ManagedUserVM) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 60 with User

use of com.arnaugarcia.uplace.domain.User in project uplace.es by Uplace.

the class UserResourceIntTest method testUserEquals.

@Test
@Transactional
public void testUserEquals() throws Exception {
    TestUtil.equalsVerifier(User.class);
    User user1 = new User();
    user1.setId(1L);
    User user2 = new User();
    user2.setId(user1.getId());
    assertThat(user1).isEqualTo(user2);
    user2.setId(2L);
    assertThat(user1).isNotEqualTo(user2);
    user1.setId(null);
    assertThat(user1).isNotEqualTo(user2);
}
Also used : User(com.arnaugarcia.uplace.domain.User) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

User (com.arnaugarcia.uplace.domain.User)61 Test (org.junit.Test)41 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)41 Transactional (org.springframework.transaction.annotation.Transactional)39 WithMockUser (org.springframework.security.test.context.support.WithMockUser)21 ManagedUserVM (com.arnaugarcia.uplace.web.rest.vm.ManagedUserVM)15 BadRequestAlertException (com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException)6 UserDTO (com.arnaugarcia.uplace.service.dto.UserDTO)5 Authority (com.arnaugarcia.uplace.domain.Authority)4 Instant (java.time.Instant)4 MimeMessage (javax.mail.internet.MimeMessage)4 Notification (com.arnaugarcia.uplace.domain.Notification)3 KeyAndPasswordVM (com.arnaugarcia.uplace.web.rest.vm.KeyAndPasswordVM)2 LoginVM (com.arnaugarcia.uplace.web.rest.vm.LoginVM)2 Timed (com.codahale.metrics.annotation.Timed)2 Before (org.junit.Before)2 Agent (com.arnaugarcia.uplace.domain.Agent)1 UserRepository (com.arnaugarcia.uplace.repository.UserRepository)1 EmailAlreadyUsedException (com.arnaugarcia.uplace.web.rest.errors.EmailAlreadyUsedException)1 LoginAlreadyUsedException (com.arnaugarcia.uplace.web.rest.errors.LoginAlreadyUsedException)1