@Test
public void testPutTenancy() {

    setupTenantDomainProviderService("AddTenancyDom1", "coretech", "storage",
            "http://localhost:8090/provider");
    Tenancy tenant = createTenantObject("AddTenancyDom1", "coretech.storage");
    zms.putTenancy(mockDomRsrcCtx, "AddTenancyDom1", "coretech.storage", auditRef, tenant);
    // now set up the tenant for the sub domain provider
    List<TenantRoleAction> roleActions = new ArrayList<>();
    for (Struct.Field f : TABLE_PROVIDER_ROLE_ACTIONS) {
        roleActions.add(new TenantRoleAction().setRole(f.name()).setAction(
                (String) f.value()));
    }
    ProviderResourceGroupRoles providerRoles = new ProviderResourceGroupRoles()
            .setDomain("coretech").setService("storage")
            .setTenant("AddTenancyDom1").setRoles(roleActions)
            .setResourceGroup("set1");
    zms.putProviderResourceGroupRoles(mockDomRsrcCtx, "AddTenancyDom1", "coretech",
            "storage", "set1", auditRef, providerRoles);
    // make sure our roles have been created
    
    Role role = zms.getRole(mockDomRsrcCtx, "AddTenancyDom1", "tenancy.coretech.storage.admin", false, false, false);
    assertNotNull(role);
    role = zms.getRole(mockDomRsrcCtx, "AddTenancyDom1", "coretech.storage.res_group.set1.admin", false, false, false);
    assertNotNull(role);
    role = zms.getRole(mockDomRsrcCtx, "AddTenancyDom1", "coretech.storage.res_group.set1.reader", false, false, false);
    assertNotNull(role);
    
    role = zms.getRole(mockDomRsrcCtx, "AddTenancyDom1", "coretech.storage.res_group.set1.writer", false, false, false);
    assertNotNull(role);
    
    // verify the policies have the correct roles
    
    Policy policy = zms.getPolicy(mockDomRsrcCtx, "AddTenancyDom1", "tenancy.coretech.storage.admin");
    assertNotNull(policy);
    
    List<Assertion> assertList = policy.getAssertions();
    assertEquals(3, assertList.size());
    
    boolean domainAdminRoleCheck = false;
    boolean tenantAdminRoleCheck = false;
    boolean tenantUpdateCheck = false;
    for (Assertion obj : assertList) {
        assertEquals(AssertionEffect.ALLOW, obj.getEffect());
        switch (obj.getRole()) {
            case "addtenancydom1:role.admin":
                assertEquals(obj.getAction(), "assume_role");
                domainAdminRoleCheck = true;
                break;
            case "addtenancydom1:role.tenancy.coretech.storage.admin":
                if (obj.getAction().equals("assume_role")) {
                    tenantAdminRoleCheck = true;
                } else if (obj.getAction().equals("update")) {
                    tenantUpdateCheck = true;
                }
                break;
        }
    }
    assertTrue(domainAdminRoleCheck);
    assertTrue(tenantAdminRoleCheck);
    assertTrue(tenantUpdateCheck);
    policy = zms.getPolicy(mockDomRsrcCtx, "AddTenancyDom1", "tenancy.coretech.storage.res_group.set1.reader");
    assertNotNull(policy);
    assertList = policy.getAssertions();
    assertEquals(assertList.size(), 1);
    assertEquals(assertList.get(0).getRole(), "addtenancydom1:role.coretech.storage.res_group.set1.reader");
    
    policy = zms.getPolicy(mockDomRsrcCtx, "AddTenancyDom1", "tenancy.coretech.storage.res_group.set1.writer");
    assertNotNull(policy);
    assertList = policy.getAssertions();
    assertEquals(assertList.size(), 1);
    assertEquals(assertList.get(0).getRole(), "addtenancydom1:role.coretech.storage.res_group.set1.writer");
    zms.deleteTenancy(mockDomRsrcCtx, "AddTenancyDom1", "coretech.storage", auditRef);
    
    zms.deleteTopLevelDomain(mockDomRsrcCtx, "AddTenancyDom1", auditRef);
    zms.deleteTopLevelDomain(mockDomRsrcCtx, "coretech", auditRef);
}