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());
}
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());
}
Aggregations