Search in sources :

Example 1 with TYPE_UI_NOTIFIER

use of io.gravitee.am.management.service.impl.notifications.NotificationDefinitionUtils.TYPE_UI_NOTIFIER 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)1 Email (io.gravitee.am.common.email.Email)1 DomainNotifierServiceImpl (io.gravitee.am.management.service.impl.DomainNotifierServiceImpl)1 EmailNotifierConfiguration (io.gravitee.am.management.service.impl.notifications.EmailNotifierConfiguration)1 TYPE_EMAIL_NOTIFIER (io.gravitee.am.management.service.impl.notifications.NotificationDefinitionUtils.TYPE_EMAIL_NOTIFIER)1 TYPE_UI_NOTIFIER (io.gravitee.am.management.service.impl.notifications.NotificationDefinitionUtils.TYPE_UI_NOTIFIER)1 Certificate (io.gravitee.am.model.Certificate)1 Domain (io.gravitee.am.model.Domain)1 Environment (io.gravitee.am.model.Environment)1 Membership (io.gravitee.am.model.Membership)1 ReferenceType (io.gravitee.am.model.ReferenceType)1 Role (io.gravitee.am.model.Role)1 User (io.gravitee.am.model.User)1 Page (io.gravitee.am.model.common.Page)1 MemberType (io.gravitee.am.model.membership.MemberType)1 DefaultRole (io.gravitee.am.model.permissions.DefaultRole)1 SystemRole (io.gravitee.am.model.permissions.SystemRole)1 DomainService (io.gravitee.am.service.DomainService)1 EnvironmentService (io.gravitee.am.service.EnvironmentService)1 GroupService (io.gravitee.am.service.GroupService)1