@Test
public void testExecuteDeleteDomainRoleMember() {

    String domainName = "deletedomainrolemember1";
    TopLevelDomain dom1 = createTopLevelDomainObject(domainName,
            "Test Domain1", "testOrg", adminUser);
    zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1);
    Role role1 = createRoleObject(domainName, "role1", null,
            "user.jack", "user.janie");
    zms.putRole(mockDomRsrcCtx, domainName, "role1", auditRef, role1);
    Role role2 = createRoleObject(domainName, "role2", null,
            "user.janie", "user.jane");
    zms.putRole(mockDomRsrcCtx, domainName, "role2", auditRef, role2);
    Role role3 = createRoleObject(domainName, "role3", null,
            "user.jack", "user.jane");
    zms.putRole(mockDomRsrcCtx, domainName, "role3", auditRef, role3);
    Role role4 = createRoleObject(domainName, "role4", null,
            "user.jack", null);
    zms.putRole(mockDomRsrcCtx, domainName, "role4", auditRef, role4);
    Role role5 = createRoleObject(domainName, "role5", null,
            "user.jack-service", "user.jane");
    zms.putRole(mockDomRsrcCtx, domainName, "role5", auditRef, role5);
    DomainRoleMembers domainRoleMembers = zms.getDomainRoleMembers(mockDomRsrcCtx, domainName);
    assertEquals(domainName, domainRoleMembers.getDomainName());
    List<DomainRoleMember> members = domainRoleMembers.getMembers();
    assertNotNull(members);
    assertEquals(5, members.size());
    ZMSTestUtils.verifyDomainRoleMember(members, "user.jack", "role1", "role3", "role4");
    ZMSTestUtils.verifyDomainRoleMember(members, "user.janie", "role1", "role2");
    ZMSTestUtils.verifyDomainRoleMember(members, "user.jane", "role2", "role3", "role5");
    ZMSTestUtils.verifyDomainRoleMember(members, "user.jack-service", "role5");
    ZMSTestUtils.verifyDomainRoleMember(members, adminUser, "admin");
    // this should exception with not-found user
    try {
        zms.dbService.executeDeleteDomainRoleMember(mockDomRsrcCtx, domainName, "user.unknown", auditRef,
                "testExecuteDeleteDomainRoleMember");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.NOT_FOUND);
    }
    domainRoleMembers = zms.getDomainRoleMembers(mockDomRsrcCtx, domainName);
    members = domainRoleMembers.getMembers();
    assertNotNull(members);
    assertEquals(5, members.size());
    ZMSTestUtils.verifyDomainRoleMember(members, "user.jack", "role1", "role3", "role4");
    ZMSTestUtils.verifyDomainRoleMember(members, "user.janie", "role1", "role2");
    ZMSTestUtils.verifyDomainRoleMember(members, "user.jane", "role2", "role3", "role5");
    ZMSTestUtils.verifyDomainRoleMember(members, "user.jack-service", "role5");
    ZMSTestUtils.verifyDomainRoleMember(members, adminUser, "admin");
    // now remove a known user
    zms.dbService.executeDeleteDomainRoleMember(mockDomRsrcCtx, domainName, "user.jack", auditRef,
            "testExecuteDeleteDomainRoleMember");
    domainRoleMembers = zms.getDomainRoleMembers(mockDomRsrcCtx, domainName);
    assertEquals(domainName, domainRoleMembers.getDomainName());
    members = domainRoleMembers.getMembers();
    assertNotNull(members);
    assertEquals(4, members.size());
    ZMSTestUtils.verifyDomainRoleMember(members, "user.janie", "role1", "role2");
    ZMSTestUtils.verifyDomainRoleMember(members, "user.jane", "role2", "role3", "role5");
    ZMSTestUtils.verifyDomainRoleMember(members, "user.jack-service", "role5");
    ZMSTestUtils.verifyDomainRoleMember(members, adminUser, "admin");
    zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName, auditRef);
}