Search in sources :

Example 1 with User

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

the class DomainUserDetailsServiceIntTest method init.

@Before
public void init() {
    userOne = new User();
    userOne.setLogin(USER_ONE_LOGIN);
    userOne.setPassword(RandomStringUtils.random(60));
    userOne.setActivated(true);
    userOne.setEmail(USER_ONE_EMAIL);
    userOne.setFirstName("userOne");
    userOne.setLastName("doe");
    userOne.setLangKey("en");
    userRepository.save(userOne);
    userTwo = new User();
    userTwo.setLogin(USER_TWO_LOGIN);
    userTwo.setPassword(RandomStringUtils.random(60));
    userTwo.setActivated(true);
    userTwo.setEmail(USER_TWO_EMAIL);
    userTwo.setFirstName("userTwo");
    userTwo.setLastName("doe");
    userTwo.setLangKey("en");
    userRepository.save(userTwo);
    userThree = new User();
    userThree.setLogin(USER_THREE_LOGIN);
    userThree.setPassword(RandomStringUtils.random(60));
    userThree.setActivated(false);
    userThree.setEmail(USER_THREE_EMAIL);
    userThree.setFirstName("userThree");
    userThree.setLastName("doe");
    userThree.setLangKey("en");
    userRepository.save(userThree);
}
Also used : User(com.arnaugarcia.uplace.domain.User) Before(org.junit.Before)

Example 2 with User

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

the class MailServiceIntTest method testSendEmailFromTemplate.

@Test
public void testSendEmailFromTemplate() throws Exception {
    User user = new User();
    user.setLogin("john");
    user.setEmail("john.doe@example.com");
    user.setLangKey("en");
    mailService.sendEmailFromTemplate(user, "testEmail", "email.test.title");
    verify(javaMailSender).send((MimeMessage) messageCaptor.capture());
    MimeMessage message = (MimeMessage) messageCaptor.getValue();
    assertThat(message.getSubject()).isEqualTo("test title");
    assertThat(message.getAllRecipients()[0].toString()).isEqualTo(user.getEmail());
    assertThat(message.getFrom()[0].toString()).isEqualTo("test@localhost");
    assertThat(message.getContent().toString()).isEqualTo("<html>test title, http://127.0.0.1:8080, john</html>\n");
    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 3 with User

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

the class MailServiceIntTest method testCreationEmail.

@Test
public void testCreationEmail() throws Exception {
    User user = new User();
    user.setLangKey(Constants.DEFAULT_LANGUAGE);
    user.setLogin("john");
    user.setEmail("john.doe@example.com");
    mailService.sendCreationEmail(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 4 with User

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

the class UserServiceIntTest method assertThatResetKeyMustBeValid.

@Test
@Transactional
public void assertThatResetKeyMustBeValid() {
    Instant daysAgo = Instant.now().minus(25, ChronoUnit.HOURS);
    user.setActivated(true);
    user.setResetDate(daysAgo);
    user.setResetKey("1234");
    userRepository.saveAndFlush(user);
    Optional<User> maybeUser = userService.completePasswordReset("johndoe2", user.getResetKey());
    assertThat(maybeUser).isNotPresent();
    userRepository.delete(user);
}
Also used : User(com.arnaugarcia.uplace.domain.User) Instant(java.time.Instant) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with User

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

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.arnaugarcia.uplace.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.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