Search in sources :

Example 1 with DBService

use of com.yahoo.athenz.zms.DBService in project athenz by yahoo.

the class PutRoleMembershipNotificationTaskTest method testGenerateAndSendPostPutMembershipNotificationInvalidType.

@Test
public void testGenerateAndSendPostPutMembershipNotificationInvalidType() {
    DBService dbsvc = Mockito.mock(DBService.class);
    Mockito.when(dbsvc.getPendingMembershipApproverRoles(1)).thenReturn(Collections.emptySet());
    NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
    NotificationServiceFactory testfact = () -> mockNotificationService;
    NotificationManager notificationManager = getNotificationManager(dbsvc, testfact);
    notificationManager.shutdown();
    Role notifyRole = new Role().setAuditEnabled(false).setSelfServe(false);
    List<Notification> notifications = new PutRoleMembershipNotificationTask("testdomain1", "neworg", notifyRole, null, dbsvc, USER_DOMAIN_PREFIX, notificationToEmailConverterCommon).getNotifications();
    notificationManager.sendNotifications(notifications);
    Mockito.verify(mockNotificationService, times(0)).notify(any());
}
Also used : DBService(com.yahoo.athenz.zms.DBService) Role(com.yahoo.athenz.zms.Role) ZMSNotificationManagerTest.getNotificationManager(com.yahoo.athenz.zms.notification.ZMSNotificationManagerTest.getNotificationManager) MetricNotificationService(com.yahoo.athenz.common.server.notification.impl.MetricNotificationService) Test(org.testng.annotations.Test)

Example 2 with DBService

use of com.yahoo.athenz.zms.DBService in project athenz by yahoo.

the class PendingGroupMembershipApprovalNotificationTaskTest method testSendPendingGroupMembershipApprovalReminders.

@Test
public void testSendPendingGroupMembershipApprovalReminders() {
    DBService dbsvc = Mockito.mock(DBService.class);
    NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
    NotificationServiceFactory testfact = () -> mockNotificationService;
    // 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
    Mockito.when(dbsvc.getPendingGroupMembershipApproverRoles(1)).thenReturn(null).thenReturn(Collections.singleton("user.joe"));
    NotificationManager notificationManager = getNotificationManager(dbsvc, testfact);
    ZMSTestUtils.sleep(1000);
    PendingGroupMembershipApprovalNotificationTask reminder = new PendingGroupMembershipApprovalNotificationTask(dbsvc, 0, "", USER_DOMAIN_PREFIX, new NotificationToEmailConverterCommon(null));
    List<Notification> notifications = reminder.getNotifications();
    // Verify contents of notification is as expected
    assertEquals(notifications.size(), 1);
    Notification expectedNotification = new Notification();
    expectedNotification.setNotificationToEmailConverter(new PendingGroupMembershipApprovalNotificationTask.PendingGroupMembershipApprovalNotificationToEmailConverter(new NotificationToEmailConverterCommon(null)));
    expectedNotification.setNotificationToMetricConverter(new PendingGroupMembershipApprovalNotificationTask.PendingGroupMembershipApprovalNotificationToMetricConverter());
    expectedNotification.addRecipient("user.joe");
    assertEquals(notifications.get(0), expectedNotification);
    notificationManager.shutdown();
}
Also used : DBService(com.yahoo.athenz.zms.DBService) ZMSNotificationManagerTest.getNotificationManager(com.yahoo.athenz.zms.notification.ZMSNotificationManagerTest.getNotificationManager) Test(org.testng.annotations.Test)

Example 3 with DBService

use of com.yahoo.athenz.zms.DBService in project athenz by yahoo.

the class PendingRoleMembershipApprovalNotificationTaskTest method testSendPendingMembershipApprovalReminders.

@Test
public void testSendPendingMembershipApprovalReminders() {
    DBService dbsvc = Mockito.mock(DBService.class);
    NotificationToEmailConverterCommon notificationToEmailConverterCommon = new NotificationToEmailConverterCommon(null);
    NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
    NotificationServiceFactory testfact = () -> mockNotificationService;
    // 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
    Mockito.when(dbsvc.getPendingMembershipApproverRoles(1)).thenReturn(null).thenReturn(Collections.singleton("user.joe"));
    NotificationManager notificationManager = getNotificationManager(dbsvc, testfact);
    ZMSTestUtils.sleep(1000);
    PendingRoleMembershipApprovalNotificationTask reminder = new PendingRoleMembershipApprovalNotificationTask(dbsvc, 0, "", USER_DOMAIN_PREFIX, notificationToEmailConverterCommon);
    List<Notification> notifications = reminder.getNotifications();
    // Verify contents of notification is as expected
    assertEquals(notifications.size(), 1);
    Notification expectedNotification = new Notification();
    expectedNotification.setNotificationToEmailConverter(new PendingRoleMembershipApprovalNotificationTask.PendingRoleMembershipApprovalNotificationToEmailConverter(notificationToEmailConverterCommon));
    expectedNotification.setNotificationToMetricConverter(new PendingRoleMembershipApprovalNotificationTask.PendingRoleMembershipApprovalNotificationToMetricConverter());
    expectedNotification.addRecipient("user.joe");
    assertEquals(notifications.get(0), expectedNotification);
    notificationManager.shutdown();
}
Also used : DBService(com.yahoo.athenz.zms.DBService) ZMSNotificationManagerTest.getNotificationManager(com.yahoo.athenz.zms.notification.ZMSNotificationManagerTest.getNotificationManager) Test(org.testng.annotations.Test)

Example 4 with DBService

use of com.yahoo.athenz.zms.DBService in project athenz by yahoo.

the class PutRoleMembershipNotificationTaskTest method testGenerateAndSendPostPutMembershipNotificationSelfserve.

@Test
public void testGenerateAndSendPostPutMembershipNotificationSelfserve() {
    DBService dbsvc = Mockito.mock(DBService.class);
    NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
    NotificationServiceFactory testfact = () -> mockNotificationService;
    NotificationManager notificationManager = getNotificationManager(dbsvc, testfact);
    notificationManager.shutdown();
    Map<String, String> details = new HashMap<>();
    details.put("domain", "testdomain1");
    details.put("role", "role1");
    List<RoleMember> roleMembers = new ArrayList<>();
    RoleMember rm = new RoleMember().setMemberName("user.domadmin1").setActive(true);
    roleMembers.add(rm);
    rm = new RoleMember().setMemberName("user.domadmin2").setActive(true);
    roleMembers.add(rm);
    rm = new RoleMember().setMemberName("dom2.testsvc1").setActive(true);
    roleMembers.add(rm);
    Role adminRole = new Role().setName("testdomain1:role.admin").setRoleMembers(roleMembers);
    List<Role> roles = new ArrayList<>();
    roles.add(adminRole);
    AthenzDomain athenzDomain = new AthenzDomain("testdomain1");
    athenzDomain.setRoles(roles);
    Mockito.when(dbsvc.getRolesByDomain("testdomain1")).thenReturn(athenzDomain.getRoles());
    ArgumentCaptor<Notification> captor = ArgumentCaptor.forClass(Notification.class);
    Role notifyRole = new Role().setAuditEnabled(false).setSelfServe(true);
    List<Notification> notifications = new PutRoleMembershipNotificationTask("testdomain1", "neworg", notifyRole, details, dbsvc, USER_DOMAIN_PREFIX, notificationToEmailConverterCommon).getNotifications();
    notificationManager.sendNotifications(notifications);
    Notification notification = new Notification();
    notification.addRecipient("user.domadmin1").addRecipient("user.domadmin2");
    notification.addDetails("domain", "testdomain1").addDetails("role", "role1");
    PutRoleMembershipNotificationTask.PutMembershipNotificationToEmailConverter converter = new PutRoleMembershipNotificationTask.PutMembershipNotificationToEmailConverter(notificationToEmailConverterCommon);
    notification.setNotificationToEmailConverter(converter);
    PutRoleMembershipNotificationTask.PutMembershipNotificationToMetricConverter metricConverter = new PutRoleMembershipNotificationTask.PutMembershipNotificationToMetricConverter();
    notification.setNotificationToMetricConverter(metricConverter);
    Mockito.verify(mockNotificationService, atLeastOnce()).notify(captor.capture());
    Notification actualNotification = captor.getValue();
    assertEquals(actualNotification, notification);
}
Also used : DBService(com.yahoo.athenz.zms.DBService) ZMSNotificationManagerTest.getNotificationManager(com.yahoo.athenz.zms.notification.ZMSNotificationManagerTest.getNotificationManager) AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) MetricNotificationService(com.yahoo.athenz.common.server.notification.impl.MetricNotificationService) Role(com.yahoo.athenz.zms.Role) RoleMember(com.yahoo.athenz.zms.RoleMember) Test(org.testng.annotations.Test)

Example 5 with DBService

use of com.yahoo.athenz.zms.DBService in project athenz by yahoo.

the class PutRoleMembershipNotificationTaskTest method testDescription.

@Test
public void testDescription() {
    DBService dbsvc = Mockito.mock(DBService.class);
    PutRoleMembershipNotificationTask putMembershipNotificationTask = new PutRoleMembershipNotificationTask("testDomain", "testOrg", new Role(), new HashMap<>(), dbsvc, USER_DOMAIN_PREFIX, notificationToEmailConverterCommon);
    String description = putMembershipNotificationTask.getDescription();
    assertEquals("Membership Approval Notification", description);
}
Also used : DBService(com.yahoo.athenz.zms.DBService) Role(com.yahoo.athenz.zms.Role) Test(org.testng.annotations.Test)

Aggregations

DBService (com.yahoo.athenz.zms.DBService)13 Test (org.testng.annotations.Test)13 Role (com.yahoo.athenz.zms.Role)9 ZMSNotificationManagerTest.getNotificationManager (com.yahoo.athenz.zms.notification.ZMSNotificationManagerTest.getNotificationManager)9 MetricNotificationService (com.yahoo.athenz.common.server.notification.impl.MetricNotificationService)7 RoleMember (com.yahoo.athenz.zms.RoleMember)6 AthenzDomain (com.yahoo.athenz.zms.store.AthenzDomain)6 DomainRoleMembersFetcher (com.yahoo.athenz.common.server.notification.DomainRoleMembersFetcher)2 NotificationTask (com.yahoo.athenz.common.server.notification.NotificationTask)1 NotificationToEmailConverterCommon (com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon)1