@BeforeTest
  public void setup() throws Exception {
    OrganizationConfigManager orgMgr = new OrganizationConfigManager(adminToken, "/");
    orgMgr.createSubOrganization(SUB_REALM.substring(1), Collections.EMPTY_MAP);
    delegatedUser = IdRepoUtils.createUser(SUB_REALM, DELEGATED_USER);
    delegatedUser1 = IdRepoUtils.createUser(SUB_REALM, DELEGATED_USER1);

    orgMgr = new OrganizationConfigManager(adminToken, SUB_REALM);
    orgMgr.createSubOrganization(SUB_SUB_REALM, Collections.EMPTY_MAP);

    createReferral();

    Application appl =
        ApplicationManager.newApplication(
            SUB_REALM,
            APPLICATION_NAME,
            ApplicationTypeManager.getAppplicationType(
                PrivilegeManager.superAdminSubject,
                ApplicationTypeManager.URL_APPLICATION_TYPE_NAME));
    // Test disabled, unable to make model change.
    // Set<String> resources = new HashSet<String>();
    // resources.add(DELEGATED_RESOURCE);
    // appl.setResources(resources);
    appl.setEntitlementCombiner(DenyOverride.class);
    ApplicationManager.saveApplication(SubjectUtils.createSuperAdminSubject(), SUB_REALM, appl);
  }
 private void createAppl(Subject adminSubject)
     throws EntitlementException, InstantiationException, IllegalAccessException {
   Application appl =
       new Application(
           "/",
           APPL_NAME,
           ApplicationTypeManager.getAppplicationType(
               adminSubject, ApplicationTypeManager.URL_APPLICATION_TYPE_NAME));
   Set<String> appResources = new HashSet<String>();
   appResources.add("http://www.ReferredResourcesTest.com/*");
   appl.addResources(appResources);
   appl.setEntitlementCombiner(DenyOverride.class);
   ApplicationManager.saveApplication(adminSubject, "/", appl);
 }