use of com.yahoo.athenz.common.server.db.RolesProvider in project athenz by yahoo.
the class NotificationManagerTest method testCreateNotification.
@Test
public void testCreateNotification() {
System.clearProperty(NOTIFICATION_PROP_SERVICE_FACTORY_CLASS);
RolesProvider rolesProvider = Mockito.mock(RolesProvider.class);
DomainRoleMembersFetcher domainRoleMembersFetcher = new DomainRoleMembersFetcher(rolesProvider, USER_DOMAIN_PREFIX);
NotificationCommon notificationCommon = new NotificationCommon(domainRoleMembersFetcher, USER_DOMAIN_PREFIX);
Set<String> recipients = new HashSet<>();
recipients.add("user.recipient1");
recipients.add("user.recipient2");
Map<String, String> details = new HashMap<>();
details.put("key1", "value1");
details.put("key2", "value2");
NotificationToEmailConverter converter = Mockito.mock(NotificationToEmailConverter.class);
NotificationToMetricConverter metricConverter = Mockito.mock(NotificationToMetricConverter.class);
Notification notification = notificationCommon.createNotification(recipients, details, converter, metricConverter);
assertNotNull(notification);
assertTrue(notification.getRecipients().contains("user.recipient1"));
assertTrue(notification.getRecipients().contains("user.recipient2"));
assertEquals(notification.getDetails().size(), 2);
assertEquals(notification.getDetails().get("key1"), "value1");
assertEquals(notification.getDetails().get("key2"), "value2");
}
use of com.yahoo.athenz.common.server.db.RolesProvider in project athenz by yahoo.
the class NotificationManagerTest method testCreateNotificationsInvalidRecipient.
@Test
public void testCreateNotificationsInvalidRecipient() {
// 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
RolesProvider rolesProvider = Mockito.mock(RolesProvider.class);
DomainRoleMembersFetcher domainRoleMembersFetcher = new DomainRoleMembersFetcher(rolesProvider, USER_DOMAIN_PREFIX);
NotificationCommon notificationCommon = new NotificationCommon(domainRoleMembersFetcher, USER_DOMAIN_PREFIX);
Map<String, String> details = new HashMap<>();
NotificationToEmailConverter converter = Mockito.mock(NotificationToEmailConverter.class);
NotificationToMetricConverter metricConverter = Mockito.mock(NotificationToMetricConverter.class);
assertNull(notificationCommon.createNotification((String) null, details, converter, metricConverter));
assertNull(notificationCommon.createNotification("", details, converter, metricConverter));
assertNull(notificationCommon.createNotification("athenz", details, converter, metricConverter));
// valid service name but we have no valid domain so we're still
// going to get null notification
assertNull(notificationCommon.createNotification("athenz.service", details, converter, metricConverter));
}
use of com.yahoo.athenz.common.server.db.RolesProvider in project athenz by yahoo.
the class NotificationManagerTest method testCreateNotificationNoValidRecipients.
@Test
public void testCreateNotificationNoValidRecipients() {
Set<String> recipients = new HashSet<>();
recipients.add("unix.ykeykey");
recipients.add("testdom:role.role3");
RolesProvider rolesProvider = Mockito.mock(RolesProvider.class);
DomainRoleMembersFetcher domainRoleMembersFetcher = new DomainRoleMembersFetcher(rolesProvider, USER_DOMAIN_PREFIX);
NotificationCommon notificationCommon = new NotificationCommon(domainRoleMembersFetcher, USER_DOMAIN_PREFIX);
NotificationToEmailConverter converter = Mockito.mock(NotificationToEmailConverter.class);
NotificationToMetricConverter metricConverter = Mockito.mock(NotificationToMetricConverter.class);
Notification notification = notificationCommon.createNotification(recipients, null, converter, metricConverter);
assertNull(notification);
}
use of com.yahoo.athenz.common.server.db.RolesProvider in project athenz by yahoo.
the class NotificationManagerTest method testCreaeteNotificationNullRecipients.
@Test
public void testCreaeteNotificationNullRecipients() {
RolesProvider rolesProvider = Mockito.mock(RolesProvider.class);
DomainRoleMembersFetcher domainRoleMembersFetcher = new DomainRoleMembersFetcher(rolesProvider, USER_DOMAIN_PREFIX);
NotificationCommon notificationCommon = new NotificationCommon(domainRoleMembersFetcher, USER_DOMAIN_PREFIX);
assertNull(notificationCommon.createNotification((Set<String>) null, null, null, null));
assertNull(notificationCommon.createNotification(Collections.emptySet(), null, null, null));
}
use of com.yahoo.athenz.common.server.db.RolesProvider in project athenz by yahoo.
the class JDBCCertRecordStoreTest method testEnableNotifications.
@Test
public void testEnableNotifications() {
PoolableDataSource mockDataSrc = Mockito.mock(PoolableDataSource.class);
JDBCCertRecordStore store = new JDBCCertRecordStore(mockDataSrc);
boolean isEnabled = store.enableNotifications(null, null, null);
assertFalse(isEnabled);
NotificationManager notificationManager = Mockito.mock(NotificationManager.class);
RolesProvider rolesProvider = Mockito.mock(RolesProvider.class);
String serverName = "testServer";
isEnabled = store.enableNotifications(notificationManager, rolesProvider, serverName);
// Not supported for FileCertStore even if all dependencies provided
assertFalse(isEnabled);
}
Aggregations