Search in sources :

Example 11 with Email

use of io.gravitee.am.common.email.Email in project gravitee-access-management by gravitee-io.

the class EmailServiceImpl method send.

@Override
public void send(Domain domain, Application client, io.gravitee.am.model.Template template, User user) {
    if (enabled) {
        // get raw email template
        io.gravitee.am.model.Email emailTemplate = getEmailTemplate(template, user);
        // prepare email
        Email email = prepareEmail(domain, client, template, emailTemplate, user);
        // send email
        sendEmail(email, user);
    }
}
Also used : Email(io.gravitee.am.common.email.Email)

Example 12 with Email

use of io.gravitee.am.common.email.Email in project gravitee-access-management by gravitee-io.

the class DomainNotificationServiceTest method shouldNotifyUser_EmailAndUI.

@Test
public void shouldNotifyUser_EmailAndUI() throws Exception {
    ReflectionTestUtils.setField(cut, "uiNotifierEnabled", true);
    final Membership member = new Membership();
    member.setMemberType(MemberType.USER);
    member.setMemberId("userid");
    when(membershipService.findByCriteria(eq(ReferenceType.DOMAIN), eq(DOMAIN_ID), any())).thenReturn(Flowable.just(member), Flowable.empty());
    final User user = new User();
    user.setEmail("user@acme.fr");
    when(userService.findById(ReferenceType.ORGANIZATION, env.getOrganizationId(), member.getMemberId())).thenReturn(Single.just(user));
    when(emailService.getFinalEmail(any(), any(), any(), any(), any())).thenReturn(new Email());
    cut.registerCertificateExpiration(certificate);
    // wait subscription execution
    Thread.sleep(1000);
    verify(notifierService).register(argThat(def -> def.getType().equals(TYPE_UI_NOTIFIER)), any(), any());
    verify(notifierService).register(argThat(def -> def.getType().equals(TYPE_EMAIL_NOTIFIER)), any(), any());
    verify(groupService, never()).findMembers(any(), any(), any(), anyInt(), anyInt());
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Certificate(io.gravitee.am.model.Certificate) EnvironmentService(io.gravitee.am.service.EnvironmentService) DomainNotifierServiceImpl(io.gravitee.am.management.service.impl.DomainNotifierServiceImpl) Arrays(java.util.Arrays) SystemRole(io.gravitee.am.model.permissions.SystemRole) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Role(io.gravitee.am.model.Role) Maybe(io.reactivex.Maybe) RunWith(org.junit.runner.RunWith) DomainService(io.gravitee.am.service.DomainService) Environment(io.gravitee.am.model.Environment) Mockito.argThat(org.mockito.Mockito.argThat) Single(io.reactivex.Single) Flowable(io.reactivex.Flowable) After(org.junit.After) Email(io.gravitee.am.common.email.Email) ReferenceType(io.gravitee.am.model.ReferenceType) User(io.gravitee.am.model.User) GroupService(io.gravitee.am.service.GroupService) MembershipService(io.gravitee.am.service.MembershipService) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) RoleService(io.gravitee.am.service.RoleService) NotifierService(io.gravitee.node.api.notifier.NotifierService) Page(io.gravitee.am.model.common.Page) MemberType(io.gravitee.am.model.membership.MemberType) TYPE_EMAIL_NOTIFIER(io.gravitee.am.management.service.impl.notifications.NotificationDefinitionUtils.TYPE_EMAIL_NOTIFIER) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Domain(io.gravitee.am.model.Domain) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) DefaultRole(io.gravitee.am.model.permissions.DefaultRole) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) Membership(io.gravitee.am.model.Membership) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) Mockito.never(org.mockito.Mockito.never) OrganizationUserService(io.gravitee.am.service.OrganizationUserService) Mockito.anyInt(org.mockito.Mockito.anyInt) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) EmailNotifierConfiguration(io.gravitee.am.management.service.impl.notifications.EmailNotifierConfiguration) TYPE_UI_NOTIFIER(io.gravitee.am.management.service.impl.notifications.NotificationDefinitionUtils.TYPE_UI_NOTIFIER) User(io.gravitee.am.model.User) Email(io.gravitee.am.common.email.Email) Membership(io.gravitee.am.model.Membership) Test(org.junit.Test)

Example 13 with Email

use of io.gravitee.am.common.email.Email in project gravitee-access-management by gravitee-io.

the class DomainNotificationServiceTest method shouldNotifyUser_EmailOnly.

@Test
public void shouldNotifyUser_EmailOnly() throws Exception {
    final Membership member = new Membership();
    member.setMemberType(MemberType.USER);
    member.setMemberId("userid");
    when(membershipService.findByCriteria(eq(ReferenceType.DOMAIN), eq(DOMAIN_ID), any())).thenReturn(Flowable.just(member), Flowable.empty());
    final User user = new User();
    user.setEmail("user@acme.fr");
    when(userService.findById(ReferenceType.ORGANIZATION, env.getOrganizationId(), member.getMemberId())).thenReturn(Single.just(user));
    when(emailService.getFinalEmail(any(), any(), any(), any(), any())).thenReturn(new Email());
    cut.registerCertificateExpiration(certificate);
    // wait subscription execution
    Thread.sleep(1000);
    verify(notifierService).register(any(), any(), any());
    verify(groupService, never()).findMembers(any(), any(), any(), anyInt(), anyInt());
}
Also used : User(io.gravitee.am.model.User) Email(io.gravitee.am.common.email.Email) Membership(io.gravitee.am.model.Membership) Test(org.junit.Test)

Aggregations

Email (io.gravitee.am.common.email.Email)13 Template (freemarker.template.Template)3 TemplateException (freemarker.template.TemplateException)3 EmailBuilder (io.gravitee.am.common.email.EmailBuilder)3 Membership (io.gravitee.am.model.Membership)3 User (io.gravitee.am.model.User)3 IOException (java.io.IOException)3 StringReader (java.io.StringReader)3 FreeMarkerTemplateUtils.processTemplateIntoString (org.springframework.ui.freemarker.FreeMarkerTemplateUtils.processTemplateIntoString)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 DomainNotifierServiceImpl (io.gravitee.am.management.service.impl.DomainNotifierServiceImpl)2 EmailNotifierConfiguration (io.gravitee.am.management.service.impl.notifications.EmailNotifierConfiguration)2 TYPE_EMAIL_NOTIFIER (io.gravitee.am.management.service.impl.notifications.NotificationDefinitionUtils.TYPE_EMAIL_NOTIFIER)2 TYPE_UI_NOTIFIER (io.gravitee.am.management.service.impl.notifications.NotificationDefinitionUtils.TYPE_UI_NOTIFIER)2 Certificate (io.gravitee.am.model.Certificate)2 Domain (io.gravitee.am.model.Domain)2 Environment (io.gravitee.am.model.Environment)2 ReferenceType (io.gravitee.am.model.ReferenceType)2 Role (io.gravitee.am.model.Role)2 Page (io.gravitee.am.model.common.Page)2