@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).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();
    notification.setNotificationToEmailConverter(converter);
    notification.setType("role_membership_approval");
    Mockito.verify(mockNotificationService, atLeastOnce()).notify(captor.capture());
    Notification actualNotification = captor.getValue();
    assertEquals(actualNotification, notification);
}