Search in sources :

Example 61 with User

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

the class UserMapper method userFromId.

public User userFromId(String id) {
    if (id == null) {
        return null;
    }
    User user = new User();
    user.setId(id);
    return user;
}
Also used : User(io.github.jhipster.sample.domain.User)

Example 62 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-cassandra 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) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 63 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-cassandra 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) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 64 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-cassandra 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) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 65 with User

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

the class AccountResourceIntTest method testChangePasswordWrongExistingPassword.

@Test
@WithMockUser("change-password-wrong-existing-password")
public void testChangePasswordWrongExistingPassword() throws Exception {
    User user = new User();
    user.setId(UUID.randomUUID().toString());
    String currentPassword = RandomStringUtils.random(60);
    user.setPassword(passwordEncoder.encode(currentPassword));
    user.setLogin("change-password-wrong-existing-password");
    user.setEmail("change-password-wrong-existing-password@example.com");
    userRepository.save(user);
    restMvc.perform(post("/api/account/change-password").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(new PasswordChangeDTO("1" + currentPassword, "new password")))).andExpect(status().isBadRequest());
    User updatedUser = userRepository.findOneByLogin("change-password-wrong-existing-password").orElse(null);
    assertThat(passwordEncoder.matches("new password", updatedUser.getPassword())).isFalse();
    assertThat(passwordEncoder.matches(currentPassword, updatedUser.getPassword())).isTrue();
}
Also used : User(io.github.jhipster.sample.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) PasswordChangeDTO(io.github.jhipster.sample.service.dto.PasswordChangeDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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