Search in sources :

Example 1 with NotifierService

use of io.gravitee.node.api.notifier.NotifierService in project gravitee-access-management by gravitee-io.

the class DomainNotificationServiceTest method shouldNotifyUserFromGroup.

@Test
public void shouldNotifyUserFromGroup() throws Exception {
    final Membership member = new Membership();
    member.setMemberType(MemberType.GROUP);
    member.setMemberId("groupId");
    when(membershipService.findByCriteria(eq(ReferenceType.DOMAIN), eq(DOMAIN_ID), any())).thenReturn(Flowable.just(member), Flowable.empty());
    final List<User> tenUsers = IntStream.range(0, 10).mapToObj(x -> {
        final User user = new User();
        user.setId("" + x);
        user.setEmail(x + "@acme.fr");
        return user;
    }).collect(Collectors.toList());
    final User singleUser = new User();
    singleUser.setId("single");
    singleUser.setEmail("single@acme.fr");
    when(groupService.findMembers(any(), any(), any(), anyInt(), anyInt())).thenReturn(Single.just(new Page<>(tenUsers, 0, 11)), Single.just(new Page<>(Arrays.asList(singleUser), 1, 11)));
    when(emailService.getFinalEmail(any(), any(), any(), any(), any())).thenReturn(new Email());
    cut.registerCertificateExpiration(certificate);
    // wait subscription execution
    Thread.sleep(1000);
    verify(notifierService, times(11)).register(any(), any(), any());
    verify(userService, never()).findById(any(), any(), any());
}
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) Page(io.gravitee.am.model.common.Page) Test(org.junit.Test)

Example 2 with NotifierService

use of io.gravitee.node.api.notifier.NotifierService 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)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Email (io.gravitee.am.common.email.Email)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 Membership (io.gravitee.am.model.Membership)2 ReferenceType (io.gravitee.am.model.ReferenceType)2 Role (io.gravitee.am.model.Role)2 User (io.gravitee.am.model.User)2 Page (io.gravitee.am.model.common.Page)2 MemberType (io.gravitee.am.model.membership.MemberType)2 DefaultRole (io.gravitee.am.model.permissions.DefaultRole)2 SystemRole (io.gravitee.am.model.permissions.SystemRole)2 DomainService (io.gravitee.am.service.DomainService)2 EnvironmentService (io.gravitee.am.service.EnvironmentService)2 GroupService (io.gravitee.am.service.GroupService)2