@Test
public void testDeleteTenancy() {

    String tenantDomain    = "testDeleteTenancy";
    String providerDomain  = "providerTestDeleteTenancy";
    String providerService = "storage";
    String provService = providerDomain + "." + providerService;
    
    // create tenant and provider domains
    //
    setupTenantDomainProviderService(tenantDomain, providerDomain, providerService,
            "http://localhost:8090/provider");
    // modify the tenant domain to require auditing
    //
    DomainMeta meta =
        createDomainMetaObject("Tenant Domain", null, true, true, null, 0);
    zms.putDomainMeta(mockDomRsrcCtx, tenantDomain, auditRef, meta);
    String testRoleName = providerDomain + ".testrole";
    Role role = createRoleObject(tenantDomain, testRoleName, null, "user.joe", "user.jane");
    zms.putRole(mockDomRsrcCtx, tenantDomain, testRoleName, auditRef, role);
    // setup tenancy
    //
    Tenancy tenant = createTenantObject(tenantDomain, provService);
    zms.putTenancy(mockDomRsrcCtx, tenantDomain, provService, auditRef, tenant);
    try {
        zms.deleteTenancy(mockDomRsrcCtx, tenantDomain,  provService, auditRef);
        
        // verify we didn't delete a role by mistake
        
        assertNotNull(zms.getRole(mockDomRsrcCtx, tenantDomain, testRoleName, false, false, false));
        
        // verify that all roles and policies have been deleted
        
        try {
            zms.getRole(mockDomRsrcCtx, tenantDomain, provService + ".admin", false, false, false);
            fail();
        } catch (ResourceException ex) {
            assertEquals(ex.getCode(), 404);
        }
        
        try {
            zms.getRole(mockDomRsrcCtx, tenantDomain, provService + ".reader", false, false, false);
            fail();
        } catch (ResourceException ex) {
            assertEquals(ex.getCode(), 404);
        }
        try {
            zms.getRole(mockDomRsrcCtx, tenantDomain, provService + ".writer", false, false, false);
            fail();
        } catch (ResourceException ex) {
            assertEquals(ex.getCode(), 404);
        }
        try {
            zms.getPolicy(mockDomRsrcCtx, tenantDomain, "tenancy." + provService + ".admin");
            fail();
        } catch (ResourceException ex) {
            assertEquals(ex.getCode(), 404);
        }
        
        try {
            zms.getPolicy(mockDomRsrcCtx, tenantDomain, "tenancy." + provService + ".reader");
            fail();
        } catch (ResourceException ex) {
            assertEquals(ex.getCode(), 404);
        }
        
        try {
            zms.getPolicy(mockDomRsrcCtx, tenantDomain, "tenancy." + provService + ".writer");
            fail();
        } catch (ResourceException ex) {
            assertEquals(ex.getCode(), 404);
        }
        
    } finally {
        zms.deleteTopLevelDomain(mockDomRsrcCtx, tenantDomain, auditRef);
        zms.deleteTopLevelDomain(mockDomRsrcCtx, providerDomain, auditRef);
    }
}