Search in sources :

Example 1 with GroupMemberExpiryNotificationTask

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

the class ZMSNotificationsTest method testDisableAllGroupExpiryNotification.

@Test
public void testDisableAllGroupExpiryNotification() {
    TopLevelDomain dom1 = zmsTestInitializer.createTopLevelDomainObject("test-domain1", "Test Domain1", "testOrg", zmsTestInitializer.getAdminUser());
    zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
    try {
        long currentTimeMillis = System.currentTimeMillis();
        List<GroupMember> groupMembers = generateGroupMembers(currentTimeMillis);
        Group group1 = zmsTestInitializer.createGroupObject("test-domain1", "Group1", groupMembers);
        // Now disable all notifications
        Map<String, TagValueList> disableUserTags = new HashMap<>();
        disableUserTags.put("zms.DisableReminderNotifications", new TagValueList().setList(Arrays.asList("3")));
        group1.setTags(disableUserTags);
        zmsTestInitializer.getZms().putGroup(zmsTestInitializer.getMockDomRsrcCtx(), "test-domain1", "Group1", zmsTestInitializer.getAuditRef(), group1);
        GroupMemberExpiryNotificationTask groupMemberExpiryNotificationTask = new GroupMemberExpiryNotificationTask(zmsTestInitializer.getZms().dbService, zmsTestInitializer.getZms().userDomainPrefix, zmsTestInitializer.getZms().notificationToEmailConverterCommon);
        List<Notification> notifications = groupMemberExpiryNotificationTask.getNotifications();
        assertEquals(notifications.size(), 0, "notificationRecipients: " + notificationsToRecipientString(notifications));
    } finally {
        zmsTestInitializer.getZms().deleteTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), "test-domain1", zmsTestInitializer.getAuditRef());
    }
}
Also used : GroupMemberExpiryNotificationTask(com.yahoo.athenz.zms.notification.GroupMemberExpiryNotificationTask) Notification(com.yahoo.athenz.common.server.notification.Notification)

Example 2 with GroupMemberExpiryNotificationTask

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

the class ZMSNotificationsTest method testGroupExpiryNotification.

@Test
public void testGroupExpiryNotification() {
    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<GroupMember> groupMembers = generateGroupMembers(currentTimeMillis);
        Group group1 = zmsTestInitializer.createGroupObject("test-domain1", "Group1", groupMembers);
        zmsTestInitializer.getZms().putGroup(zmsTestInitializer.getMockDomRsrcCtx(), "test-domain1", "Group1", zmsTestInitializer.getAuditRef(), group1);
        GroupMemberExpiryNotificationTask groupMemberExpiryNotificationTask = new GroupMemberExpiryNotificationTask(zmsTestInitializer.getZms().dbService, zmsTestInitializer.getZms().userDomainPrefix, zmsTestInitializer.getZms().notificationToEmailConverterCommon);
        List<Notification> notifications = groupMemberExpiryNotificationTask.getNotifications();
        // Email notifications should be sent every 7 days
        Set<String> emailNotificationMembers = new HashSet<>(Arrays.asList(new String[] { "user.expireddays0", "user.expireddays1", "user.expireddays7", "user.expireddays14", "user.expireddays21", "user.expireddays28" }));
        assertEquals(notifications.size(), 7, "notificationRecipients: " + notificationsToRecipientString(notifications));
        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 : GroupMemberExpiryNotificationTask(com.yahoo.athenz.zms.notification.GroupMemberExpiryNotificationTask) Timestamp(com.yahoo.rdl.Timestamp) Notification(com.yahoo.athenz.common.server.notification.Notification)

Example 3 with GroupMemberExpiryNotificationTask

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

the class ZMSNotificationsTest method testDisableAdminGroupExpiryNotification.

@Test
public void testDisableAdminGroupExpiryNotification() {
    TopLevelDomain dom1 = zmsTestInitializer.createTopLevelDomainObject("test-domain1", "Test Domain1", "testOrg", zmsTestInitializer.getAdminUser());
    zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
    try {
        long currentTimeMillis = System.currentTimeMillis();
        List<GroupMember> groupMembers = generateGroupMembers(currentTimeMillis);
        Group group1 = zmsTestInitializer.createGroupObject("test-domain1", "Group1", groupMembers);
        // Now disable notification for admins
        Map<String, TagValueList> disableUserTags = new HashMap<>();
        disableUserTags.put("zms.DisableReminderNotifications", new TagValueList().setList(Arrays.asList("2")));
        group1.setTags(disableUserTags);
        zmsTestInitializer.getZms().putGroup(zmsTestInitializer.getMockDomRsrcCtx(), "test-domain1", "Group1", zmsTestInitializer.getAuditRef(), group1);
        GroupMemberExpiryNotificationTask groupMemberExpiryNotificationTask = new GroupMemberExpiryNotificationTask(zmsTestInitializer.getZms().dbService, zmsTestInitializer.getZms().userDomainPrefix, zmsTestInitializer.getZms().notificationToEmailConverterCommon);
        List<Notification> notifications = groupMemberExpiryNotificationTask.getNotifications();
        // Email notifications should be sent every 7 days
        Set<String> emailNotificationMembers = new HashSet<>(Arrays.asList(new String[] { "user.expireddays0", "user.expireddays1", "user.expireddays7", "user.expireddays14", "user.expireddays21", "user.expireddays28" }));
        assertEquals(notifications.size(), 6, "notificationRecipients: " + notificationsToRecipientString(notifications));
        for (Notification notification : notifications) {
            assertEquals(notification.getRecipients().size(), 1, "notificationRecipients: " + notificationsToRecipientString(notifications));
            String recipient = notification.getRecipients().stream().findFirst().get();
            assertTrue(emailNotificationMembers.contains(recipient));
            emailNotificationMembers.remove(recipient);
        }
        assertTrue(emailNotificationMembers.isEmpty());
    } finally {
        zmsTestInitializer.getZms().deleteTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), "test-domain1", zmsTestInitializer.getAuditRef());
    }
}
Also used : GroupMemberExpiryNotificationTask(com.yahoo.athenz.zms.notification.GroupMemberExpiryNotificationTask) Notification(com.yahoo.athenz.common.server.notification.Notification)

Example 4 with GroupMemberExpiryNotificationTask

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

the class ZMSNotificationsTest method testDisableUserGroupExpiryNotification.

@Test
public void testDisableUserGroupExpiryNotification() {
    TopLevelDomain dom1 = zmsTestInitializer.createTopLevelDomainObject("test-domain1", "Test Domain1", "testOrg", zmsTestInitializer.getAdminUser());
    zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
    try {
        long currentTimeMillis = System.currentTimeMillis();
        List<GroupMember> groupMembers = generateGroupMembers(currentTimeMillis);
        Group group1 = zmsTestInitializer.createGroupObject("test-domain1", "Group1", groupMembers);
        // Now disable notification for users
        Map<String, TagValueList> disableUserTags = new HashMap<>();
        disableUserTags.put("zms.DisableReminderNotifications", new TagValueList().setList(Arrays.asList("1")));
        group1.setTags(disableUserTags);
        zmsTestInitializer.getZms().putGroup(zmsTestInitializer.getMockDomRsrcCtx(), "test-domain1", "Group1", zmsTestInitializer.getAuditRef(), group1);
        GroupMemberExpiryNotificationTask groupMemberExpiryNotificationTask = new GroupMemberExpiryNotificationTask(zmsTestInitializer.getZms().dbService, zmsTestInitializer.getZms().userDomainPrefix, zmsTestInitializer.getZms().notificationToEmailConverterCommon);
        List<Notification> notifications = groupMemberExpiryNotificationTask.getNotifications();
        // Email notifications should be sent every 7 days
        Set<String> emailNotificationMembers = new HashSet<>(Arrays.asList(new String[] { "user.expireddays0", "user.expireddays1", "user.expireddays7", "user.expireddays14", "user.expireddays21", "user.expireddays28" }));
        assertEquals(notifications.size(), 1, "notificationRecipients: " + notificationsToRecipientString(notifications));
        Notification notification = notifications.get(0);
        assertEquals(notification.getRecipients().size(), 1, "notificationRecipients: " + notificationsToRecipientString(notifications));
        String recipient = notification.getRecipients().stream().findFirst().get();
        assertEquals(recipient, "user.testadminuser");
        verifyAdminNotifications(emailNotificationMembers, notification);
    } finally {
        zmsTestInitializer.getZms().deleteTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), "test-domain1", zmsTestInitializer.getAuditRef());
    }
}
Also used : GroupMemberExpiryNotificationTask(com.yahoo.athenz.zms.notification.GroupMemberExpiryNotificationTask) Notification(com.yahoo.athenz.common.server.notification.Notification)

Aggregations

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