Search in sources :

Example 1 with RolesProvider

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");
}
Also used : RolesProvider(com.yahoo.athenz.common.server.db.RolesProvider) Test(org.testng.annotations.Test)

Example 2 with RolesProvider

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));
}
Also used : RolesProvider(com.yahoo.athenz.common.server.db.RolesProvider) Test(org.testng.annotations.Test)

Example 3 with RolesProvider

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);
}
Also used : RolesProvider(com.yahoo.athenz.common.server.db.RolesProvider) Test(org.testng.annotations.Test)

Example 4 with RolesProvider

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));
}
Also used : RolesProvider(com.yahoo.athenz.common.server.db.RolesProvider) Test(org.testng.annotations.Test)

Example 5 with RolesProvider

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);
}
Also used : NotificationManager(com.yahoo.athenz.common.server.notification.NotificationManager) PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource) RolesProvider(com.yahoo.athenz.common.server.db.RolesProvider) Test(org.testng.annotations.Test)

Aggregations

RolesProvider (com.yahoo.athenz.common.server.db.RolesProvider)14 Test (org.testng.annotations.Test)14 NotificationManager (com.yahoo.athenz.common.server.notification.NotificationManager)8 PoolableDataSource (com.yahoo.athenz.common.server.db.PoolableDataSource)2 ZTSClientNotificationSenderImpl (com.yahoo.athenz.zts.notification.ZTSClientNotificationSenderImpl)2 Authority (com.yahoo.athenz.auth.Authority)1 ZTSClientNotification (com.yahoo.athenz.zts.ZTSClientNotification)1 File (java.io.File)1