Search in sources :

Example 1 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-dto by jhipster.

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(io.github.jhipster.sample.domain.User) Before(org.junit.Before)

Example 2 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-dto by jhipster.

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, "mail/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(io.github.jhipster.sample.domain.User) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-dto by jhipster.

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(io.github.jhipster.sample.domain.User) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-dto by jhipster.

the class MailServiceIntTest method testSendPasswordResetMail.

@Test
public void testSendPasswordResetMail() throws Exception {
    User user = new User();
    user.setLangKey(Constants.DEFAULT_LANGUAGE);
    user.setLogin("john");
    user.setEmail("john.doe@example.com");
    mailService.sendPasswordResetMail(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(io.github.jhipster.sample.domain.User) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-dto by jhipster.

the class UserServiceIntTest method assertThatResetKeyMustNotBeOlderThan24Hours.

@Test
@Transactional
public void assertThatResetKeyMustNotBeOlderThan24Hours() {
    Instant daysAgo = Instant.now().minus(25, ChronoUnit.HOURS);
    String resetKey = RandomUtil.generateResetKey();
    user.setActivated(true);
    user.setResetDate(daysAgo);
    user.setResetKey(resetKey);
    userRepository.saveAndFlush(user);
    Optional<User> maybeUser = userService.completePasswordReset("johndoe2", user.getResetKey());
    assertThat(maybeUser).isNotPresent();
    userRepository.delete(user);
}
Also used : User(io.github.jhipster.sample.domain.User) Instant(java.time.Instant) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

User (io.github.jhipster.sample.domain.User)329 Test (org.junit.Test)251 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)251 Transactional (org.springframework.transaction.annotation.Transactional)150 WithMockUser (org.springframework.security.test.context.support.WithMockUser)138 ManagedUserVM (io.github.jhipster.sample.web.rest.vm.ManagedUserVM)90 AbstractCassandraTest (io.github.jhipster.sample.AbstractCassandraTest)38 UserDTO (io.github.jhipster.sample.service.dto.UserDTO)32 Authority (io.github.jhipster.sample.domain.Authority)24 PasswordChangeDTO (io.github.jhipster.sample.service.dto.PasswordChangeDTO)24 MimeMessage (javax.mail.internet.MimeMessage)24 Instant (java.time.Instant)21 Before (org.junit.Before)13 Timed (com.codahale.metrics.annotation.Timed)12 KeyAndPasswordVM (io.github.jhipster.sample.web.rest.vm.KeyAndPasswordVM)12 Scheduled (org.springframework.scheduling.annotation.Scheduled)8 GrantedAuthority (org.springframework.security.core.GrantedAuthority)7 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)7 UserDetails (org.springframework.security.core.userdetails.UserDetails)7 PersistentToken (io.github.jhipster.sample.domain.PersistentToken)6