@Test
public void testDeleteUser() {

    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);
    
    SubDomain subDom1 = createSubDomainObject("jack", "user",
            "Test SubDomain2", "testOrg", adminUser);
    zms.postSubDomain(mockDomRsrcCtx, "user", auditRef, subDom1);
    
    SubDomain subDom2 = createSubDomainObject("sub1", "user.jack",
            "Test SubDomain21", "testOrg", adminUser);
    zms.postSubDomain(mockDomRsrcCtx, "user.jack", auditRef, subDom2);
    
    Role role1 = createRoleObject(domainName, "role1", null,
            "user.joe", "user.jack.sub1.service");
    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", "user.jack.sub1.api");
    zms.putRole(mockDomRsrcCtx, domainName, "role3", auditRef, role3);
    
    UserList userList = zms.getUserList(mockDomRsrcCtx);
    List<String> users = userList.getNames();
    int userSize = users.size();
    assertTrue(users.contains("user.testadminuser"));
    assertTrue(users.contains("user.jack"));
    assertTrue(users.contains("user.joe"));
    
    zms.deleteUser(mockDomRsrcCtx, "jack", auditRef);
    
    userList = zms.getUserList(mockDomRsrcCtx);
    users = userList.getNames();
    assertEquals(users.size(), userSize - 1);
    assertTrue(users.contains("user.testadminuser"));
    assertTrue(users.contains("user.joe"));
    assertFalse(users.contains("user.jack"));
    try {
        zms.getDomain(mockDomRsrcCtx, "user.jack");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.NOT_FOUND);
    }
    
    try {
        zms.getDomain(mockDomRsrcCtx, "user.jack.sub1");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.NOT_FOUND);
    }
    
    zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName, auditRef);
    zms.deleteTopLevelDomain(mockDomRsrcCtx, "deleteusersports", auditRef);
}