@Test
public void testExecuteDeleteUser() {

    
    String domainName = "deleteuser1";
    ZMSTestUtils.cleanupNotAdminUsers(zms, adminUser, mockDomRsrcCtx);
    TopLevelDomain dom1 = createTopLevelDomainObject(domainName,
            "Test Domain1", "testOrg", adminUser);
    zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1);
    TopLevelDomain dom2 = createTopLevelDomainObject("deleteusersports",
            "Test Domain2", "testOrg", adminUser);
    zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom2);
    
    TopLevelDomain dom3 = createTopLevelDomainObject("deleteuserweather",
            "Test Domain3", "testOrg", adminUser);
    zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom3);
    
    SubDomain subDom1 = createSubDomainObject("jack", "user",
            "Test SubDomain2", "testOrg", adminUser);
    zms.postSubDomain(mockDomRsrcCtx, "user", auditRef, subDom1);
    
    SubDomain subDom2 = createSubDomainObject("jane", "user",
            "Test SubDomain2", "testOrg", adminUser);
    zms.postSubDomain(mockDomRsrcCtx, "user", auditRef, subDom2);
    
    Role role1 = createRoleObject(domainName, "role1", null,
            "user.joe", "user.janie");
    zms.putRole(mockDomRsrcCtx, domainName, "role1", auditRef, role1);
    
    Role role2 = createRoleObject(domainName, "role2", null,
            "user.joe", "deleteusersports.jane");
    zms.putRole(mockDomRsrcCtx, domainName, "role2", auditRef, role2);
    Role role3 = createRoleObject(domainName, "role3", null,
            "user.jack", "deleteuserweather.jane");
    zms.putRole(mockDomRsrcCtx, domainName, "role3", auditRef, role3);
    
    Role role4 = createRoleObject("deleteusersports", "role4", null,
            "user.ana", "user.janie");
    zms.putRole(mockDomRsrcCtx, "deleteusersports", "role4", auditRef, role4);
    
    Role role5 = createRoleObject("deleteusersports", "role5", null,
            "user.jack.service", "user.jane.storage");
    zms.putRole(mockDomRsrcCtx, "deleteusersports", "role5", auditRef, role5);
    
    List<String> users = zms.dbService.listPrincipals("user", true);
    assertEquals(users.size(), 5);
    assertTrue(users.contains("user.testadminuser"));
    assertTrue(users.contains("user.janie"));
    assertTrue(users.contains("user.ana"));
    assertTrue(users.contains("user.jack"));
    assertTrue(users.contains("user.joe"));
    
    zms.dbService.executeDeleteUser(mockDomRsrcCtx, "user.jack", "user.jack", auditRef, "testExecuteDeleteUser");
    
    users = zms.dbService.listPrincipals("user", true);
    assertEquals(users.size(), 4);
    assertTrue(users.contains("user.testadminuser"));
    assertTrue(users.contains("user.janie"));
    assertTrue(users.contains("user.ana"));
    assertTrue(users.contains("user.joe"));
    assertFalse(users.contains("user.jack"));
    
    Role testRole = zms.dbService.getRole("deleteusersports", "role5", false, false, false);
    assertEquals(testRole.getRoleMembers().size(), 1);
    RoleMember roleMember = testRole.getRoleMembers().get(0);
    assertEquals(roleMember.getMemberName(), "user.jane.storage");
    
    try {
        zms.getDomain(mockDomRsrcCtx, "user.jack");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.NOT_FOUND);
    }
    
    zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName, auditRef);
    zms.deleteSubDomain(mockDomRsrcCtx, "user", "jane", auditRef);
    zms.deleteTopLevelDomain(mockDomRsrcCtx, "deleteusersports", auditRef);
    zms.deleteTopLevelDomain(mockDomRsrcCtx, "deleteuserweather", auditRef);
}