@Test
public void testGetPendingDomainRoleMembersList() {

    TopLevelDomain dom1 = createTopLevelDomainObject("testdomain1", "Approval Test Domain1",
            "testOrg", "user.user1");
    zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1);
    setupPrincipalAuditedRoleApprovalByOrg(zms, "user.fury", "testorg");
    DomainMeta meta = createDomainMetaObject("Domain Meta for approval test", "testorg",
            true, true, "12345", 1001);
    zms.putDomainMeta(mockDomRsrcCtx, "testdomain1", auditRef, meta);
    zms.putDomainSystemMeta(mockDomRsrcCtx, "testdomain1", "auditenabled", auditRef, meta);
    setupPrincipalSystemMetaDelete(zms, mockDomRsrcCtx.principal().getFullName(), "testdomain1", "org");
    zms.putDomainSystemMeta(mockDomRsrcCtx, "testdomain1", "org", auditRef, meta);
    Role auditedRole = createRoleObject("testdomain1", "testrole1", null, "user.john", "user.jane");
    zms.putRole(mockDomRsrcCtx, "testdomain1", "testrole1", auditRef, auditedRole);
    RoleSystemMeta rsm = createRoleSystemMetaObject(true);
    zms.putRoleSystemMeta(mockDomRsrcCtx, "testdomain1", "testrole1", "auditenabled", auditRef, rsm);
    Membership mbr = new Membership();
    mbr.setMemberName("user.bob");
    mbr.setActive(false);
    mbr.setApproved(false);
    zms.putMembership(mockDomRsrcCtx, "testdomain1", "testrole1", "user.bob", auditRef, mbr);
    mbr = new Membership();
    mbr.setMemberName("user.bob");
    mbr.setActive(true);
    mbr.setApproved(true);
    try {
        zms.putMembershipDecision(mockDomRsrcCtx, "testdomain1", "testrole1", "user.bob", auditRef, mbr);
        fail();
    } catch (ResourceException r) {
        assertEquals(r.code, 403);
    }
    // first request using specific principal
    DomainRoleMembership domainRoleMembership = zms.getPendingDomainRoleMembersList(mockDomRsrcCtx, "user.fury");
    assertNotNull(domainRoleMembership);
    assertNotNull(domainRoleMembership.getDomainRoleMembersList());
    assertEquals(domainRoleMembership.getDomainRoleMembersList().size(), 1);
    for (DomainRoleMembers drm : domainRoleMembership.getDomainRoleMembersList()) {
        assertEquals(drm.getDomainName(), "testdomain1");
        assertNotNull(drm.getMembers());
        for (DomainRoleMember mem : drm.getMembers()) {
            assertNotNull(mem);
            assertEquals(mem.getMemberName(), "user.bob");
            for (MemberRole mr : mem.getMemberRoles()) {
                assertNotNull(mr);
                assertEquals(mr.getRoleName(), "testrole1");
            }
        }
    }
    // repeat the request using context principal
    Principal mockPrincipal = Mockito.mock(Principal.class);
    Mockito.when(mockDomRsrcCtx.principal()).thenReturn(mockPrincipal);
    Mockito.when(mockPrincipal.getDomain()).thenReturn("user");
    Mockito.when(mockPrincipal.getFullName()).thenReturn("user.fury");
    domainRoleMembership = zms.getPendingDomainRoleMembersList(mockDomRsrcCtx, null);
    assertNotNull(domainRoleMembership);
    assertNotNull(domainRoleMembership.getDomainRoleMembersList());
    assertEquals(domainRoleMembership.getDomainRoleMembersList().size(), 1);
    for (DomainRoleMembers drm : domainRoleMembership.getDomainRoleMembersList()) {
        assertEquals(drm.getDomainName(), "testdomain1");
        assertNotNull(drm.getMembers());
        for (DomainRoleMember mem : drm.getMembers()) {
            assertNotNull(mem);
            assertEquals(mem.getMemberName(), "user.bob");
            for (MemberRole mr : mem.getMemberRoles()) {
                assertNotNull(mr);
                assertEquals(mr.getRoleName(), "testrole1");
            }
        }
    }
    cleanupPrincipalSystemMetaDelete(zms);
    cleanupPrincipalAuditedRoleApprovalByOrg(zms, "testOrg");
    zms.deleteTopLevelDomain(mockDomRsrcCtx, "testdomain1", auditRef);
}