AWSZTSHealthNotificationTask implements NotificationTask { @Override public List<Notification> getNotifications() { List<Notification> notificationList = new ArrayList<>(); Map<String, String> details = getNotificationDetails(); Notification notification = notificationCommon.createNotification( ResourceUtils.roleResourceName(athenzAdminDomain, ADMIN_ROLE_NAME), details, awsZTSHealthNotificationToEmailConverter, NOTIFICATION_TYPE); if (notification != null) { notificationList.add(notification); } return notificationList; } AWSZTSHealthNotificationTask(ZTSClientNotification ztsClientNotification,
                                        RolesProvider rolesProvider,
                                        String userDomainPrefix,
                                        String serverName); @Override List<Notification> getNotifications(); @Override String getDescription();  }
@Test public void testNoNotifications() { AWSZTSHealthNotificationTask awsztsHealthNotificationTask = new AWSZTSHealthNotificationTask( ztsClientNotification, dataStore, userDomainPrefix, serverName); List<Notification> notifications = awsztsHealthNotificationTask.getNotifications(); assertEquals(0, notifications.size()); }
@Test public void testGetNotifications() { System.setProperty(ZTSConsts.ZTS_PROP_NOTIFICATION_AWS_HEALTH_DOMAIN, "testDomain"); ZTSClientNotification clientNotification = new ZTSClientNotification( "zts.url", "role", "AWS", 1592346376, false, "testDomain" ); RoleMember roleMember1 = new RoleMember(); roleMember1.setMemberName("user.test1"); RoleMember roleMember2 = new RoleMember(); roleMember2.setMemberName("user.test2"); List<RoleMember> roleMembers = new ArrayList<>(); roleMembers.add(roleMember1); roleMembers.add(roleMember2); Role adminRole = new Role(); adminRole.setRoleMembers(roleMembers); adminRole.setName("testDomain:role.admin"); List<Role> roles = new ArrayList<>(); roles.add(adminRole); when(dataStore.getRolesByDomain(eq("testDomain"))).thenReturn(roles); AWSZTSHealthNotificationTask awsztsHealthNotificationTask = new AWSZTSHealthNotificationTask( clientNotification, dataStore, userDomainPrefix, serverName); List<Notification> notifications = awsztsHealthNotificationTask.getNotifications(); assertEquals(1, notifications.size()); assertTrue(notifications.get(0).getRecipients().contains("user.test1")); assertTrue(notifications.get(0).getRecipients().contains("user.test2")); assertEquals("zts.url;testDomain;role;1592346376;Fail to get token of type AWS. ", notifications.get(0).getDetails().get("awsZtsHealth")); assertEquals("testServer", notifications.get(0).getDetails().get("affectedZts")); System.clearProperty(ZTSConsts.ZTS_PROP_NOTIFICATION_AWS_HEALTH_DOMAIN); }