@Test
public void testGetPendingDomainGroupMembersList() {

    final String domainName = "pend-dom-grp-mbr-list";
    final String groupName = "group1";
    TopLevelDomain dom1 = createTopLevelDomainObject(domainName, "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, domainName, auditRef, meta);
    zms.putDomainSystemMeta(mockDomRsrcCtx, domainName, "auditenabled", auditRef, meta);
    setupPrincipalSystemMetaDelete(zms, mockDomRsrcCtx.principal().getFullName(), domainName, "org");
    zms.putDomainSystemMeta(mockDomRsrcCtx, domainName, "org", auditRef, meta);
    Group auditedGroup = createGroupObject(domainName, groupName, "user.john", "user.jane");
    zms.putGroup(mockDomRsrcCtx, domainName, groupName, auditRef, auditedGroup);
    GroupSystemMeta rsm = createGroupSystemMetaObject(true);
    zms.putGroupSystemMeta(mockDomRsrcCtx, domainName, groupName, "auditenabled", auditRef, rsm);
    GroupMeta rm = new GroupMeta().setSelfServe(true);
    zms.putGroupMeta(mockDomRsrcCtx, domainName, groupName, auditRef, rm);
    GroupMembership mbr = new GroupMembership();
    mbr.setMemberName("user.bob");
    mbr.setActive(false);
    mbr.setApproved(false);
    zms.putGroupMembership(mockDomRsrcCtx, domainName, groupName, "user.bob", auditRef, mbr);
    mbr = new GroupMembership();
    mbr.setMemberName("user.bob");
    mbr.setActive(true);
    mbr.setApproved(true);
    try {
        zms.putGroupMembershipDecision(mockDomRsrcCtx, domainName, groupName, "user.bob", auditRef, mbr);
        fail();
    } catch (ResourceException r) {
        assertEquals(r.code, 403);
    }
    // first request using specific principal
    DomainGroupMembership domainGroupMembership = zms.getPendingDomainGroupMembersList(mockDomRsrcCtx, "user.fury");
    assertNotNull(domainGroupMembership);
    assertNotNull(domainGroupMembership.getDomainGroupMembersList());
    assertEquals(domainGroupMembership.getDomainGroupMembersList().size(), 1);
    for (DomainGroupMembers drm : domainGroupMembership.getDomainGroupMembersList()) {
        assertEquals(drm.getDomainName(), domainName);
        assertNotNull(drm.getMembers());
        for (DomainGroupMember mem : drm.getMembers()) {
            assertNotNull(mem);
            assertEquals(mem.getMemberName(), "user.bob");
            for (GroupMember mr : mem.getMemberGroups()) {
                assertNotNull(mr);
                assertEquals(mr.getGroupName(), groupName);
            }
        }
    }
    // 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");
    domainGroupMembership = zms.getPendingDomainGroupMembersList(mockDomRsrcCtx, null);
    assertNotNull(domainGroupMembership);
    assertNotNull(domainGroupMembership.getDomainGroupMembersList());
    assertEquals(domainGroupMembership.getDomainGroupMembersList().size(), 1);
    for (DomainGroupMembers drm : domainGroupMembership.getDomainGroupMembersList()) {
        assertEquals(drm.getDomainName(), domainName);
        assertNotNull(drm.getMembers());
        for (DomainGroupMember mem : drm.getMembers()) {
            assertNotNull(mem);
            assertEquals(mem.getMemberName(), "user.bob");
            for (GroupMember mr : mem.getMemberGroups()) {
                assertNotNull(mr);
                assertEquals(mr.getGroupName(), groupName);
            }
        }
    }
    cleanupPrincipalSystemMetaDelete(zms);
    cleanupPrincipalAuditedRoleApprovalByOrg(zms, "testOrg");
    zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName, auditRef);
}