use of com.yahoo.athenz.zms.DBService in project athenz by yahoo.
the class PutRoleMembershipNotificationTaskTest method testGenerateAndSendPostPutMembershipNotificationInvalidType.
@Test
public void testGenerateAndSendPostPutMembershipNotificationInvalidType() {
DBService dbsvc = Mockito.mock(DBService.class);
Mockito.when(dbsvc.getPendingMembershipApproverRoles(1)).thenReturn(Collections.emptySet());
NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
NotificationServiceFactory testfact = () -> mockNotificationService;
NotificationManager notificationManager = getNotificationManager(dbsvc, testfact);
notificationManager.shutdown();
Role notifyRole = new Role().setAuditEnabled(false).setSelfServe(false);
List<Notification> notifications = new PutRoleMembershipNotificationTask("testdomain1", "neworg", notifyRole, null, dbsvc, USER_DOMAIN_PREFIX, notificationToEmailConverterCommon).getNotifications();
notificationManager.sendNotifications(notifications);
Mockito.verify(mockNotificationService, times(0)).notify(any());
}
use of com.yahoo.athenz.zms.DBService in project athenz by yahoo.
the class PendingGroupMembershipApprovalNotificationTaskTest method testSendPendingGroupMembershipApprovalReminders.
@Test
public void testSendPendingGroupMembershipApprovalReminders() {
DBService dbsvc = Mockito.mock(DBService.class);
NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
NotificationServiceFactory testfact = () -> mockNotificationService;
// we're going to return null for our first thread which will
// run during init call and then the real data for the second
// call
Mockito.when(dbsvc.getPendingGroupMembershipApproverRoles(1)).thenReturn(null).thenReturn(Collections.singleton("user.joe"));
NotificationManager notificationManager = getNotificationManager(dbsvc, testfact);
ZMSTestUtils.sleep(1000);
PendingGroupMembershipApprovalNotificationTask reminder = new PendingGroupMembershipApprovalNotificationTask(dbsvc, 0, "", USER_DOMAIN_PREFIX, new NotificationToEmailConverterCommon(null));
List<Notification> notifications = reminder.getNotifications();
// Verify contents of notification is as expected
assertEquals(notifications.size(), 1);
Notification expectedNotification = new Notification();
expectedNotification.setNotificationToEmailConverter(new PendingGroupMembershipApprovalNotificationTask.PendingGroupMembershipApprovalNotificationToEmailConverter(new NotificationToEmailConverterCommon(null)));
expectedNotification.setNotificationToMetricConverter(new PendingGroupMembershipApprovalNotificationTask.PendingGroupMembershipApprovalNotificationToMetricConverter());
expectedNotification.addRecipient("user.joe");
assertEquals(notifications.get(0), expectedNotification);
notificationManager.shutdown();
}
use of com.yahoo.athenz.zms.DBService in project athenz by yahoo.
the class PendingRoleMembershipApprovalNotificationTaskTest method testSendPendingMembershipApprovalReminders.
@Test
public void testSendPendingMembershipApprovalReminders() {
DBService dbsvc = Mockito.mock(DBService.class);
NotificationToEmailConverterCommon notificationToEmailConverterCommon = new NotificationToEmailConverterCommon(null);
NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
NotificationServiceFactory testfact = () -> mockNotificationService;
// we're going to return null for our first thread which will
// run during init call and then the real data for the second
// call
Mockito.when(dbsvc.getPendingMembershipApproverRoles(1)).thenReturn(null).thenReturn(Collections.singleton("user.joe"));
NotificationManager notificationManager = getNotificationManager(dbsvc, testfact);
ZMSTestUtils.sleep(1000);
PendingRoleMembershipApprovalNotificationTask reminder = new PendingRoleMembershipApprovalNotificationTask(dbsvc, 0, "", USER_DOMAIN_PREFIX, notificationToEmailConverterCommon);
List<Notification> notifications = reminder.getNotifications();
// Verify contents of notification is as expected
assertEquals(notifications.size(), 1);
Notification expectedNotification = new Notification();
expectedNotification.setNotificationToEmailConverter(new PendingRoleMembershipApprovalNotificationTask.PendingRoleMembershipApprovalNotificationToEmailConverter(notificationToEmailConverterCommon));
expectedNotification.setNotificationToMetricConverter(new PendingRoleMembershipApprovalNotificationTask.PendingRoleMembershipApprovalNotificationToMetricConverter());
expectedNotification.addRecipient("user.joe");
assertEquals(notifications.get(0), expectedNotification);
notificationManager.shutdown();
}
use of com.yahoo.athenz.zms.DBService in project athenz by yahoo.
the class PutRoleMembershipNotificationTaskTest method testGenerateAndSendPostPutMembershipNotificationSelfserve.
@Test
public void testGenerateAndSendPostPutMembershipNotificationSelfserve() {
DBService dbsvc = Mockito.mock(DBService.class);
NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
NotificationServiceFactory testfact = () -> mockNotificationService;
NotificationManager notificationManager = getNotificationManager(dbsvc, testfact);
notificationManager.shutdown();
Map<String, String> details = new HashMap<>();
details.put("domain", "testdomain1");
details.put("role", "role1");
List<RoleMember> roleMembers = new ArrayList<>();
RoleMember rm = new RoleMember().setMemberName("user.domadmin1").setActive(true);
roleMembers.add(rm);
rm = new RoleMember().setMemberName("user.domadmin2").setActive(true);
roleMembers.add(rm);
rm = new RoleMember().setMemberName("dom2.testsvc1").setActive(true);
roleMembers.add(rm);
Role adminRole = new Role().setName("testdomain1:role.admin").setRoleMembers(roleMembers);
List<Role> roles = new ArrayList<>();
roles.add(adminRole);
AthenzDomain athenzDomain = new AthenzDomain("testdomain1");
athenzDomain.setRoles(roles);
Mockito.when(dbsvc.getRolesByDomain("testdomain1")).thenReturn(athenzDomain.getRoles());
ArgumentCaptor<Notification> captor = ArgumentCaptor.forClass(Notification.class);
Role notifyRole = new Role().setAuditEnabled(false).setSelfServe(true);
List<Notification> notifications = new PutRoleMembershipNotificationTask("testdomain1", "neworg", notifyRole, details, dbsvc, USER_DOMAIN_PREFIX, notificationToEmailConverterCommon).getNotifications();
notificationManager.sendNotifications(notifications);
Notification notification = new Notification();
notification.addRecipient("user.domadmin1").addRecipient("user.domadmin2");
notification.addDetails("domain", "testdomain1").addDetails("role", "role1");
PutRoleMembershipNotificationTask.PutMembershipNotificationToEmailConverter converter = new PutRoleMembershipNotificationTask.PutMembershipNotificationToEmailConverter(notificationToEmailConverterCommon);
notification.setNotificationToEmailConverter(converter);
PutRoleMembershipNotificationTask.PutMembershipNotificationToMetricConverter metricConverter = new PutRoleMembershipNotificationTask.PutMembershipNotificationToMetricConverter();
notification.setNotificationToMetricConverter(metricConverter);
Mockito.verify(mockNotificationService, atLeastOnce()).notify(captor.capture());
Notification actualNotification = captor.getValue();
assertEquals(actualNotification, notification);
}
use of com.yahoo.athenz.zms.DBService in project athenz by yahoo.
the class PutRoleMembershipNotificationTaskTest method testDescription.
@Test
public void testDescription() {
DBService dbsvc = Mockito.mock(DBService.class);
PutRoleMembershipNotificationTask putMembershipNotificationTask = new PutRoleMembershipNotificationTask("testDomain", "testOrg", new Role(), new HashMap<>(), dbsvc, USER_DOMAIN_PREFIX, notificationToEmailConverterCommon);
String description = putMembershipNotificationTask.getDescription();
assertEquals("Membership Approval Notification", description);
}
Aggregations