@Test
public void testDeleteGroup() {

    final String domainName1 = "delete-group1";
    final String domainName2 = "delete-group2";
    final String groupName1 = "group1";
    final String groupName2 = "group2";
    final String roleName1 = "role1";
    final String roleName2 = "role2";
    TopLevelDomain dom1 = createTopLevelDomainObject(domainName1, "Test Domain1", "testOrg", adminUser);
    zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1);
    TopLevelDomain dom2 = createTopLevelDomainObject(domainName2, "Test Domain2", "testOrg", adminUser);
    zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom2);
    Group group1 = createGroupObject(domainName1, groupName1, "user.joe", "user.jane");
    zms.putGroup(mockDomRsrcCtx, domainName1, groupName1, auditRef, group1);
    Group group2 = createGroupObject(domainName1, groupName2, "user.joe", "user.jane");
    zms.putGroup(mockDomRsrcCtx, domainName1, groupName2, auditRef, group2);
    // add group2 as a member to roles in 2 different domains
    Role role1 = createRoleObject(domainName1, roleName1, null, "user.john",
            ZMSUtils.groupResourceName(domainName1, groupName2));
    zms.putRole(mockDomRsrcCtx, domainName1, roleName1, auditRef, role1);
    Role role2 = createRoleObject(domainName2, roleName2, null, "user.john",
            ZMSUtils.groupResourceName(domainName1, groupName2));
    zms.putRole(mockDomRsrcCtx, domainName2, roleName2, auditRef, role2);
    Groups groupList = zms.getGroups(mockDomRsrcCtx, domainName1, false);
    assertNotNull(groupList);
    assertEquals(groupList.getList().size(), 2);
    // now delete group 1 which should be good since it's not part
    // of any roles
    zms.deleteGroup(mockDomRsrcCtx, domainName1, groupName1, auditRef);
    groupList = zms.getGroups(mockDomRsrcCtx, domainName1, false);
    assertNotNull(groupList);
    assertEquals(groupList.getList().size(), 1);
    assertEquals(groupList.getList().get(0).getName(), domainName1 + ":group.group2");
    // now delete group2 which should be rejected since it's
    // included in 2 roles
    try {
        zms.deleteGroup(mockDomRsrcCtx, domainName1, groupName2, auditRef);
        fail();
    } catch (ResourceException ex) {
        assertTrue(ex.getMessage().contains(ZMSUtils.roleResourceName(domainName1, roleName1)));
        assertTrue(ex.getMessage().contains(ZMSUtils.roleResourceName(domainName2, roleName2)));
    }
    // delete one of the roles
    zms.deleteRole(mockDomRsrcCtx, domainName1, roleName1, auditRef);
    // we should still fail since it's still included in one other role
    try {
        zms.deleteGroup(mockDomRsrcCtx, domainName1, groupName2, auditRef);
        fail();
    } catch (ResourceException ex) {
        assertFalse(ex.getMessage().contains(ZMSUtils.roleResourceName(domainName1, roleName1)));
        assertTrue(ex.getMessage().contains(ZMSUtils.roleResourceName(domainName2, roleName2)));
    }
    // delete the second role and now we should be able to delete the group
    zms.deleteRole(mockDomRsrcCtx, domainName2, roleName2, auditRef);
    zms.deleteGroup(mockDomRsrcCtx, domainName1, groupName2, auditRef);
    zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName1, auditRef);
    zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName2, auditRef);
}