Search in sources :

Example 41 with User

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

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

Example 42 with User

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

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

Example 43 with User

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

the class SocialServiceIntTest method testCreateSocialUserShouldNotChangeUserIfEmailAlreadyExist.

@Test
public void testCreateSocialUserShouldNotChangeUserIfEmailAlreadyExist() {
    // Setup
    createExistingUser("@OTHER_LOGIN", "mail@mail.com", "OTHER_FIRST_NAME", "OTHER_LAST_NAME", "OTHER_IMAGE_URL");
    Connection<?> connection = createConnection("@LOGIN", "mail@mail.com", "FIRST_NAME", "LAST_NAME", "IMAGE_URL", "PROVIDER");
    // Exercise
    socialService.createSocialUser(connection, "fr");
    // Verify
    User userToVerify = userRepository.findOneByEmailIgnoreCase("mail@mail.com").get();
    assertThat(userToVerify.getLogin()).isEqualTo("@other_login");
    assertThat(userToVerify.getFirstName()).isEqualTo("OTHER_FIRST_NAME");
    assertThat(userToVerify.getLastName()).isEqualTo("OTHER_LAST_NAME");
    assertThat(userToVerify.getImageUrl()).isEqualTo("OTHER_IMAGE_URL");
    // Teardown
    userRepository.delete(userToVerify);
}
Also used : User(com.furyviewer.domain.User) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 44 with User

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

the class SocialServiceIntTest method testCreateSocialUserShouldCreateUserWithSocialInformation.

@Test
public void testCreateSocialUserShouldCreateUserWithSocialInformation() {
    // Setup
    Connection<?> connection = createConnection("@LOGIN", "mail@mail.com", "FIRST_NAME", "LAST_NAME", "IMAGE_URL", "PROVIDER");
    // Exercise
    socialService.createSocialUser(connection, "fr");
    // Verify
    User user = userRepository.findOneByEmailIgnoreCase("mail@mail.com").get();
    assertThat(user.getFirstName()).isEqualTo("FIRST_NAME");
    assertThat(user.getLastName()).isEqualTo("LAST_NAME");
    assertThat(user.getImageUrl()).isEqualTo("IMAGE_URL");
    // Teardown
    userRepository.delete(user);
}
Also used : User(com.furyviewer.domain.User) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 45 with User

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

the class SocialServiceIntTest method testCreateSocialUserShouldNotCreateUserIfEmailAlreadyExist.

@Test
public void testCreateSocialUserShouldNotCreateUserIfEmailAlreadyExist() {
    // Setup
    createExistingUser("@OTHER_LOGIN", "mail@mail.com", "OTHER_FIRST_NAME", "OTHER_LAST_NAME", "OTHER_IMAGE_URL");
    long initialUserCount = userRepository.count();
    Connection<?> connection = createConnection("@LOGIN", "mail@mail.com", "FIRST_NAME", "LAST_NAME", "IMAGE_URL", "PROVIDER");
    // Exercise
    socialService.createSocialUser(connection, "fr");
    // Verify
    assertThat(userRepository.count()).isEqualTo(initialUserCount);
    // Teardown
    User userToDelete = userRepository.findOneByEmailIgnoreCase("mail@mail.com").get();
    userRepository.delete(userToDelete);
}
Also used : User(com.furyviewer.domain.User) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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