@Test
public void testSetupTenantAdminPolicy() {

    
    String caller = "testSetupTenantAdminPolicy";
    String tenantDomain = "tenantadminpolicy";
    String providerDomain = "coretech";
    String providerService = "storage";
    // create domain for tenant
    
    TopLevelDomain dom1 = createTopLevelDomainObject(tenantDomain,
            "Test Tenant Domain1", "testOrg", adminUser);
    zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1);
    // create domain for provider
    
    TopLevelDomain domProv = createTopLevelDomainObject(providerDomain,
            "Test Provider Domain1", "testOrg", adminUser);
    zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, domProv);
    // create service identity for providerDomain.providerService
    
    ServiceIdentity service = createServiceObject(
            providerDomain, providerService, "http://localhost:8090/tableprovider",
            "/usr/bin/java", "root", "users", "localhost");
    zms.putServiceIdentity(mockDomRsrcCtx, providerDomain, providerService, auditRef, service);
    
    // let's create the tenant admin policy
    
    zms.dbService.setupTenantAdminPolicy(tenantDomain, providerDomain,
            providerService, auditRef, caller);
    
    // the admin policy must be called
    
    String policyName = "tenancy.coretech.storage.admin";
    Policy policy = zms.dbService.getPolicy(tenantDomain, policyName);
    assertNotNull(policy);
    List<Assertion> assertList = policy.getAssertions();
    assertNotNull(assertList);
    assertEquals(3, assertList.size());
    boolean domainAdminRoleCheck = false;
    boolean tenantAdminRoleCheck = false;
    boolean tenantUpdateCheck = false;
    for (Assertion obj : assertList) {
        assertEquals(AssertionEffect.ALLOW, obj.getEffect());
        if (obj.getRole().equals("tenantadminpolicy:role.admin")) {
            assertEquals(obj.getResource(), "coretech:role.storage.tenant.tenantadminpolicy.admin");
            assertEquals(obj.getAction(), "assume_role");
            domainAdminRoleCheck = true;
        } else if (obj.getRole().equals("tenantadminpolicy:role.tenancy.coretech.storage.admin")) {
            if (obj.getAction().equals("assume_role")) {
                assertEquals(obj.getResource(), "coretech:role.storage.tenant.tenantadminpolicy.admin");
                tenantAdminRoleCheck = true;
            } else if (obj.getAction().equals("update")) {
                assertEquals("tenantadminpolicy:tenancy.coretech.storage", obj.getResource());
                tenantUpdateCheck = true;
            }
        }
    }
    assertTrue(domainAdminRoleCheck);
    assertTrue(tenantAdminRoleCheck);
    assertTrue(tenantUpdateCheck);
    zms.deleteTopLevelDomain(mockDomRsrcCtx, tenantDomain, auditRef);
    zms.deleteTopLevelDomain(mockDomRsrcCtx, providerDomain, auditRef);
}