NotificationToEmailConverterCommon { public Set<String> getFullyQualifiedEmailAddresses(Set<String> recipients) { return recipients.stream() .map(s -> s.replaceAll(userDomainPrefix, "")) .map(r -> r + AT + emailDomainTo) .collect(Collectors.toSet()); } NotificationToEmailConverterCommon(); String readContentFromFile(ClassLoader classLoader, String fileName); String generateBodyFromTemplate(Map<String, String> metaDetails,
                                            String bodyTemplate,
                                            String bodyTemplateDetails,
                                            String tableValuesKey,
                                            int tableEntryNumColumns); String getTableEntryTemplate(int numOfColumns); String addCssStyleToBody(String body); String getSubject(String propertyName); Set<String> getFullyQualifiedEmailAddresses(Set<String> recipients); String getWorkflowUrl(); String getAthenzUIUrl();  }
@Test public void testGetFullyQualifiedEmailAddresses() { System.clearProperty("athenz.user_domain"); System.setProperty("athenz.user_domain", "entuser"); System.setProperty("athenz.notification_email_domain_from", "from.example.com"); System.setProperty("athenz.notification_email_domain_to", "example.com"); Set<String> recipients = new HashSet<>(Arrays.asList("entuser.user1", "entuser.user2", "entuser.user3")); NotificationToEmailConverterCommon notificationToEmailConverterCommon = new NotificationToEmailConverterCommon(); Set<String> recipientsResp = notificationToEmailConverterCommon.getFullyQualifiedEmailAddresses(recipients); assertNotNull(recipientsResp); assertEquals(recipientsResp.size(), 3); assertTrue(recipientsResp.contains("user1@example.com")); assertTrue(recipientsResp.contains("user2@example.com")); assertTrue(recipientsResp.contains("user3@example.com")); System.clearProperty("athenz.notification_email_domain_from"); System.clearProperty("athenz.notification_email_domain_to"); System.clearProperty("athenz.user_domain"); }
@Test public void testGetFullyQualifiedEmailAddressesDefaultUserDomain() { System.setProperty("athenz.notification_email_domain_from", "from.test.com"); System.setProperty("athenz.notification_email_domain_to", "test.com"); Set<String> recipients = new HashSet<>(Arrays.asList("user.user1", "user.user2", "user.user3")); NotificationToEmailConverterCommon notificationToEmailConverterCommon = new NotificationToEmailConverterCommon(); Set<String> recipientsResp = notificationToEmailConverterCommon.getFullyQualifiedEmailAddresses(recipients); assertNotNull(recipientsResp); assertEquals(recipientsResp.size(), 3); assertTrue(recipientsResp.contains("user1@test.com")); assertTrue(recipientsResp.contains("user2@test.com")); assertTrue(recipientsResp.contains("user3@test.com")); System.clearProperty("athenz.notification_email_domain_from"); System.clearProperty("athenz.notification_email_domain_to"); }