Search in sources :

Example 1 with RoleMemberExpiryNotificationTask

use of com.yahoo.athenz.zms.notification.RoleMemberExpiryNotificationTask in project athenz by yahoo.

the class ZMSNotificationsTest method testRoleExpiryNotification.

@Test
public void testRoleExpiryNotification() {
    TopLevelDomain dom1 = zmsTestInitializer.createTopLevelDomainObject("test-domain1", "Test Domain1", "testOrg", zmsTestInitializer.getAdminUser());
    zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
    try {
        long currentTimeMillis = System.currentTimeMillis();
        Timestamp currentTimestamp = Timestamp.fromMillis(currentTimeMillis);
        List<RoleMember> roleMembers = generateRoleMembers(currentTimeMillis);
        Role role1 = zmsTestInitializer.createRoleObject("test-domain1", "Role1", null, roleMembers);
        zmsTestInitializer.getZms().putRole(zmsTestInitializer.getMockDomRsrcCtx(), "test-domain1", "Role1", zmsTestInitializer.getAuditRef(), role1);
        RoleMemberExpiryNotificationTask roleMemberExpiryNotificationTask = new RoleMemberExpiryNotificationTask(zmsTestInitializer.getZms().dbService, zmsTestInitializer.getZms().userDomainPrefix, zmsTestInitializer.getZms().notificationToEmailConverterCommon);
        List<Notification> notifications = roleMemberExpiryNotificationTask.getNotifications();
        // Email notifications should be sent every 7 days while metrics should be recorded every day
        Set<String> emailNotificationMembers = new HashSet<>(Arrays.asList(new String[] { "user.expireddays0", "user.expireddays1", "user.expireddays7", "user.expireddays14", "user.expireddays21", "user.expireddays28" }));
        for (Notification notification : notifications) {
            String recipient = notification.getRecipients().stream().findFirst().get();
            if (recipient.equals("user.testadminuser")) {
                verifyAdminNotifications(emailNotificationMembers, notification);
            } else {
                if (emailNotificationMembers.contains(recipient)) {
                    assertNotNull(notification.getNotificationAsEmail());
                } else {
                    assertNull(notification.getNotificationAsEmail());
                }
                assertNotNull(notification.getNotificationAsMetrics(currentTimestamp));
            }
        }
    } finally {
        zmsTestInitializer.getZms().deleteTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), "test-domain1", zmsTestInitializer.getAuditRef());
    }
}
Also used : RoleMemberExpiryNotificationTask(com.yahoo.athenz.zms.notification.RoleMemberExpiryNotificationTask) Timestamp(com.yahoo.rdl.Timestamp) Notification(com.yahoo.athenz.common.server.notification.Notification)

Aggregations

Notification (com.yahoo.athenz.common.server.notification.Notification)1 RoleMemberExpiryNotificationTask (com.yahoo.athenz.zms.notification.RoleMemberExpiryNotificationTask)1 Timestamp (com.yahoo.rdl.Timestamp)1