Пример #1
0
 public void testAddVirtualization() throws Exception {
   Org org1 = UserTestUtils.findNewOrg("testOrg" + this.getClass().getSimpleName());
   org1.getEntitlements().add(OrgFactory.getEntitlementVirtualization());
   TestUtils.saveAndFlush(org1);
   org1 = (Org) reload(org1);
   assertTrue(org1.hasEntitlement(OrgFactory.getEntitlementVirtualization()));
 }
Пример #2
0
  /**
   * List an organization's allocation of a system entitlement.
   *
   * @param sessionKey User's session key.
   * @param label System entitlement label.
   * @param includeUnentitled If true, the result will include both organizations that have the
   *     entitlement as well as those that do not; otherwise, the result will only include
   *     organizations that have the entitlement.
   * @return a list of Maps having the system entitlements info.
   * @since 10.4
   * @xmlrpc.doc List each organization's allocation of a system entitlement.
   * @xmlrpc.param #param("string", "sessionKey")
   * @xmlrpc.param #param("string", "label")
   * @xmlrpc.param #param_desc("boolean", "includeUnentitled", "If true, the result will include
   *     both organizations that have the entitlement as well as those that do not; otherwise, the
   *     result will only include organizations that have the entitlement.")
   * @xmlrpc.returntype #array() #struct("entitlement usage") #prop("int", "org_id") #prop("string",
   *     "org_name") #prop("int", "allocated") #prop("int", "unallocated") #prop("int", "used")
   *     #prop("int", "free") #struct_end() #array_end()
   */
  public List<Map> listSystemEntitlements(
      String sessionKey, String label, Boolean includeUnentitled) {

    getSatAdmin(sessionKey);
    verifyEntitlementExists(label);

    DataList<Map> result = null;
    if (includeUnentitled) {
      result = OrgManager.allOrgsSingleEntitlementWithEmptyOrgs(label);
    } else {
      result = OrgManager.allOrgsSingleEntitlement(label);
    }

    List<Map> details = new LinkedList<Map>();
    for (Map row : result) {
      Map<String, Object> map = new HashMap<String, Object>();
      Org org = OrgFactory.lookupById((Long) row.get("orgid"));
      map.put(ORG_ID_KEY, new Integer(org.getId().intValue()));
      map.put(ORG_NAME_KEY, org.getName());
      map.put(ALLOCATED_KEY, ((Long) row.get("total")).intValue());
      map.put(USED_KEY, row.get("usage"));
      long free = (Long) row.get("total") - (Long) row.get("usage");
      map.put(FREE_KEY, free);
      long unallocated = (Long) row.get("upper") - (Long) row.get("total");
      map.put(UN_ALLOCATED_KEY, unallocated);
      details.add(map);
    }
    return details;
  }
Пример #3
0
 /**
  * Get the status of SCAP detailed result file upload settings for the given organization.
  *
  * @param sessionKey User's session key.
  * @param orgId ID of organization to query.
  * @return Returns the status of SCAP detailed result file upload settings.
  * @xmlrpc.doc Get the status of SCAP detailed result file upload settings for the given
  *     organization.
  * @xmlrpc.param #session_key()
  * @xmlrpc.param #param("int", "orgId")
  * @xmlrpc.returntype #struct("scap_upload_info") #prop_desc("boolean", "enabled", "Aggregation of
  *     detailed SCAP results is enabled.") #prop_desc("int", "size_limit", "Limit (in Bytes) for a
  *     single SCAP file upload.") #struct_end()
  */
 public Map<String, Object> getPolicyForScapFileUpload(String sessionKey, Integer orgId) {
   getSatAdmin(sessionKey);
   Org org = verifyOrgExists(orgId);
   Map<String, Object> result = new HashMap<String, Object>();
   result.put("enabled", org.getOrgConfig().isScapfileUploadEnabled());
   result.put("size_limit", org.getOrgConfig().getScapFileSizelimit());
   return result;
 }
Пример #4
0
 /** {@inheritDoc} */
 @Override
 public boolean equals(Object other) {
   if (!(other instanceof Org)) {
     return false;
   }
   Org otherOrg = (Org) other;
   return new EqualsBuilder().append(getName(), otherOrg.getName()).isEquals();
 }
Пример #5
0
 /**
  * Get the status of SCAP result deletion settings for the given organization.
  *
  * @param sessionKey User's session key.
  * @param orgId ID of organization to query.
  * @return Returns the status of SCAP result deletion settings.
  * @xmlrpc.doc Get the status of SCAP result deletion settings for the given organization.
  * @xmlrpc.param #session_key()
  * @xmlrpc.param #param("int", "orgId")
  * @xmlrpc.returntype #struct("scap_deletion_info") #prop_desc("boolean", "enabled", "Deletion of
  *     SCAP results is enabled") #prop_desc("int", "retention_period", "Period (in days) after
  *     which a scan can be deleted (if enabled).") #struct_end()
  */
 public Map<String, Object> getPolicyForScapResultDeletion(String sessionKey, Integer orgId) {
   getSatAdmin(sessionKey);
   Org org = verifyOrgExists(orgId);
   Long retentionPeriod = org.getOrgConfig().getScapRetentionPeriodDays();
   Map<String, Object> result = new HashMap<String, Object>();
   result.put("enabled", retentionPeriod != null);
   result.put("retention_period", (retentionPeriod != null) ? retentionPeriod : new Long(0));
   return result;
 }
Пример #6
0
  /**
   * Set organization wide crash file size limit.
   *
   * @param sessionKey User's session key.
   * @param orgId Organization ID to set the limit for.
   * @param limit The limit to set.
   * @return 1 on success.
   * @xmlrpc.doc Set the organization wide crash file size limit. The limit value must be
   *     non-negative, zero means no limit.
   * @xmlrpc.param #param("string", "sessionKey")
   * @xmlrpc.param #param("int", "orgId")
   * @xmlrpc.param #param_desc("int", "limit", "The limit to set (non-negative value).")
   * @xmlrpc.returntype #return_int_success()
   */
  public int setCrashFileSizeLimit(String sessionKey, Integer orgId, Integer limit) {
    getSatAdmin(sessionKey);
    Org org = verifyOrgExists(orgId);
    if (limit < 0) {
      throw new InvalidParameterException("Limit value must be non-negative.");
    }
    org.getOrgConfig().setCrashFileSizelimit(new Long(limit.longValue()));

    return 1;
  }
Пример #7
0
 public void testCommitOrg() throws Exception {
   Org org1 = UserTestUtils.findNewOrg("testOrg" + this.getClass().getSimpleName());
   String changedName = "OrgFactoryTest testCommitOrg " + TestUtils.randomString();
   org1.setName(changedName);
   org1 = OrgFactory.save(org1);
   Long id = org1.getId();
   flushAndEvict(org1);
   Org org2 = OrgFactory.lookupById(id);
   assertEquals(changedName, org2.getName());
 }
Пример #8
0
  /**
   * Set the status of crash file upload settings for the given organization.
   *
   * @param sessionKey User's session key.
   * @param orgId Organization ID to set the limit for.
   * @param enable Boolean to indicate desired settings.
   * @return Returns 1 for successfull change, 0 if the change failed.
   * @xmlrpc.doc Set the status of crash file upload settings for the given organization. Modifying
   *     the settings is possible as long as crash reporting is enabled.
   * @xmlrpc.param #param("string", "sessionKey")
   * @xmlrpc.param #param("int", "orgId")
   * @xmlrpc.param #param_desc("boolean", "enable", "Use true/false to enable/disable")
   * @xmlrpc.returntype #return_int_success()
   */
  public Integer setCrashfileUpload(String sessionKey, Integer orgId, Boolean enable) {
    getSatAdmin(sessionKey);
    Org org = verifyOrgExists(orgId);
    if (org.getOrgConfig().isCrashReportingEnabled()) {
      org.getOrgConfig().setCrashfileUploadEnabled(enable);
    } else {
      return 0;
    }

    return 1;
  }
Пример #9
0
 private void grant(DynaActionForm form, ActionErrors errors, RequestContext ctx) {
   Channel c = edit(form, errors, ctx);
   // if there was no exception during the above edit
   // add all of the orgs to the "rhnchanneltrust"
   if (c != null) {
     Org org = ctx.getCurrentUser().getOrg();
     Set<Org> trustedorgs = org.getTrustedOrgs();
     c.setTrustedOrgs(trustedorgs);
     ChannelFactory.save(c);
   }
 }
Пример #10
0
 private Org createTestOrg() throws Exception {
   Org org1 = OrgFactory.createOrg();
   org1.setName("org created by OrgFactory test: " + TestUtils.randomString());
   org1 = OrgFactory.save(org1);
   // build the channels set
   Channel channel1 = ChannelFactoryTest.createTestChannel(org1);
   flushAndEvict(channel1);
   org1.addOwnedChannel(channel1);
   assertTrue(org1.getId().longValue() > 0);
   return org1;
 }
Пример #11
0
 public void testIllegalEntitlement() throws Exception {
   try {
     Org org1 = UserTestUtils.findNewOrg("testOrg" + this.getClass().getSimpleName());
     OrgEntitlementType invalid = new OrgEntitlementType("invalid");
     invalid.setLabel("ILLEGAL ENTITLEMENT");
     invalid.setName("ILLEGAL ENTITLEMENT NAME");
     org1.hasEntitlement(invalid);
     fail("Checked for illegal entitlement, should have received an exception");
   } catch (IllegalArgumentException e) {
     // Expected exception
   }
 }
Пример #12
0
  /**
   * Migrate systems from one organization to another. If executed by a Satellite administrator, the
   * systems will be migrated from their current organization to the organization specified by the
   * toOrgId. If executed by an organization administrator, the systems must exist in the same
   * organization as that administrator and the systems will be migrated to the organization
   * specified by the toOrgId. In any scenario, the origination and destination organizations must
   * be defined in a trust.
   *
   * @param sessionKey User's session key.
   * @param toOrgId destination organization ID.
   * @param sids System IDs.
   * @return list of systems migrated.
   * @throws FaultException A FaultException is thrown if: - The user performing the request is not
   *     an organization administrator - The user performing the request is not a satellite
   *     administrator, but the from org id is different than the user's org id. - The from and to
   *     org id provided are the same. - One or more of the servers provides do not exist - The
   *     origination or destination organization does not exist - The user is not defined in the
   *     destination organization's trust
   * @xmlrpc.doc Migrate systems from one organization to another. If executed by a Satellite
   *     administrator, the systems will be migrated from their current organization to the
   *     organization specified by the toOrgId. If executed by an organization administrator, the
   *     systems must exist in the same organization as that administrator and the systems will be
   *     migrated to the organization specified by the toOrgId. In any scenario, the origination and
   *     destination organizations must be defined in a trust.
   * @xmlrpc.param #param("string", "sessionKey")
   * @xmlrpc.param #param_desc("int", "toOrgId", "ID of the organization where the system(s) will be
   *     migrated to.")
   * @xmlrpc.param #array_single("int", "systemId")
   * @xmlrpc.returntype #array_single("int", "serverIdMigrated")
   */
  public Object[] migrateSystems(String sessionKey, Integer toOrgId, List<Integer> sids)
      throws FaultException {

    // the user executing the request must at least be an org admin to perform
    // a system migration
    User admin = getOrgAdmin(sessionKey);

    Org toOrg = verifyOrgExists(toOrgId);

    List<Server> servers = new LinkedList<Server>();

    for (Integer sid : sids) {
      Long serverId = new Long(sid.longValue());
      Server server = null;
      try {
        server = ServerFactory.lookupById(serverId);

        // throw a no_such_system exception if the server was not found.
        if (server == null) {
          throw new NoSuchSystemException("No such system - sid[" + sid + "]");
        }
      } catch (LookupException e) {
        throw new NoSuchSystemException("No such system - sid[" + sid + "]");
      }
      servers.add(server);

      // As a pre-requisite to performing the actual migration, verify that each
      // server that is planned for migration passes the criteria that follows.
      // If any of the servers fails that criteria, none will be migrated.

      // unless the user is a satellite admin, they are not permitted to migrate
      // systems from an org that they do not belong to
      if ((!admin.hasRole(RoleFactory.SAT_ADMIN)) && (!admin.getOrg().equals(server.getOrg()))) {
        throw new PermissionCheckFailureException(server);
      }

      // do not allow the user to migrate systems to/from the same org.  doing so
      // would essentially remove entitlements, channels...etc from the systems
      // being migrated.
      if (toOrg.equals(server.getOrg())) {
        throw new MigrationToSameOrgException(server);
      }

      // if the originating org is not defined within the destination org's trust
      // the migration should not be permitted.
      if (!toOrg.getTrustedOrgs().contains(server.getOrg())) {
        throw new OrgNotInTrustException(server);
      }
    }

    List<Long> serversMigrated = MigrationManager.migrateServers(admin, toOrg, servers);
    return serversMigrated.toArray();
  }
Пример #13
0
 /**
  * @param sessionKey Caller's session key.
  * @param orgId the orgId of the organization to set name on
  * @param name the new name for the org.
  * @return the updated org.
  * @xmlrpc.doc Updates the name of an organization
  * @xmlrpc.param #param("string", "sessionKey")
  * @xmlrpc.param #param("int", "orgId")
  * @xmlrpc.param #param_desc("string", "name", "Organization name. Must meet same criteria as in
  *     the web UI.")
  * @xmlrpc.returntype $OrgDtoSerializer
  */
 public OrgDto updateName(String sessionKey, Integer orgId, String name) {
   getSatAdmin(sessionKey);
   Org org = verifyOrgExists(orgId);
   if (!org.getName().equals(name)) {
     try {
       OrgManager.checkOrgName(name);
       org.setName(name);
     } catch (ValidatorException ve) {
       throw new ValidationException(ve.getMessage());
     }
   }
   return OrgManager.toDetailsDto(org);
 }
Пример #14
0
  public void testCustomDataKeys() {
    User user = UserTestUtils.findNewUser("testuser", "testorg");
    Org org = user.getOrg();

    Set keys = org.getCustomDataKeys();
    int sizeBefore = keys.size();

    CustomDataKey key = CustomDataKeyTest.createTestCustomDataKey(user);
    assertFalse(keys.contains(key));
    assertFalse(org.hasCustomDataKey(key.getLabel()));
    assertFalse(org.hasCustomDataKey("foo" + System.currentTimeMillis()));
    assertFalse(org.hasCustomDataKey(null));

    org.addCustomDataKey(key);

    keys = org.getCustomDataKeys();
    int sizeAfter = keys.size();

    assertTrue(keys.contains(key));
    assertTrue(sizeBefore < sizeAfter);
    assertTrue(org.hasCustomDataKey(key.getLabel()));

    CustomDataKey key2 = OrgFactory.lookupKeyByLabelAndOrg(key.getLabel(), org);
    assertNotNull(key2);

    key2 = OrgFactory.lookupKeyByLabelAndOrg(null, org);
    assertNull(key2);
  }
Пример #15
0
  /**
   * Delete an organization.
   *
   * @param sessionKey User's session key.
   * @param orgId ID of organization to delete.
   * @return 1 on success, exception thrown otherwise.
   * @xmlrpc.doc Delete an organization. The default organization (i.e. orgId=1) cannot be deleted.
   * @xmlrpc.param #param("string", "sessionKey")
   * @xmlrpc.param #param("int", "orgId")
   * @xmlrpc.returntype #return_int_success()
   */
  public int delete(String sessionKey, Integer orgId) {
    User user = getSatAdmin(sessionKey);
    Org org = verifyOrgExists(orgId);

    // Verify we're not trying to delete the default org (id 1):
    Org defaultOrg = OrgFactory.getSatelliteOrg();
    if (orgId.longValue() == defaultOrg.getId().longValue()) {
      throw new SatelliteOrgException();
    }

    OrgFactory.deleteOrg(org.getId(), user);

    return 1;
  }
Пример #16
0
 /** {@inheritDoc} */
 public List<OrgTrust> getResult(RequestContext ctx) {
   Org org = ctx.getCurrentUser().getOrg();
   Set<Org> trustedorgs = org.getTrustedOrgs();
   List<OrgTrust> trusts = new ArrayList<OrgTrust>();
   for (Org o : trustedorgs) {
     DataResult<Map<String, Object>> dr = SystemManager.sidsInOrgTrust(org.getId(), o.getId());
     OrgTrust trust = new OrgTrust(o);
     if (!dr.isEmpty()) {
       for (Map<String, Object> m : dr) {
         Long sid = (Long) m.get("id");
         trust.getSubscribed().add(sid);
       }
     }
     trusts.add(trust);
   }
   return trusts;
 }
Пример #17
0
  public void testAddServerGroup() throws Exception {
    Org org1 = UserTestUtils.findNewOrg("testOrg" + this.getClass().getSimpleName());
    assertTrue(org1.getEntitledServerGroups().size() > 0);
    boolean contains = false;
    for (Iterator itr = org1.getEntitledServerGroups().iterator(); itr.hasNext(); ) {
      ServerGroup group = (ServerGroup) itr.next();
      assertNotNull(group);
      if (ServerConstants.getServerGroupTypeUpdateEntitled().equals(group.getGroupType())) {
        contains = true;
      }
    }
    assertTrue(contains);

    // in hosted, the hibernate mapping files were broken so that adding a
    // second
    // server group would break a database constraint. This line ensures
    // that that
    // problem will not exist again.
    ServerGroupTest.createTestServerGroup(
        org1, ServerConstants.getServerGroupTypeEnterpriseEntitled());
  }
Пример #18
0
  /**
   * List the organizations associated with the given channel that may be trusted.
   *
   * @param loggedInUser The current user
   * @param channelLabel The label for the channel
   * @return List of map entries indicating the orgs available and if access is enabled.
   * @throws FaultException A FaultException is thrown if: - The sessionKey is invalid - The
   *     channelLabel is invalid - The user doesn't have channel admin permissions
   * @xmlrpc.doc List the organizations associated with the given channel that may be trusted.
   * @xmlrpc.param #session_key()
   * @xmlrpc.param #param_desc("string", "channelLabel", "label of the channel")
   * @xmlrpc.returntype #array() #struct("org") #prop("int", "org_id") #prop("string", "org_name")
   *     #prop("boolean", "access_enabled") #struct_end() #array_end()
   */
  public List list(User loggedInUser, String channelLabel) throws FaultException {

    Channel channel = lookupChannelByLabel(loggedInUser, channelLabel);
    verifyChannelAdmin(loggedInUser, channel);

    if (!loggedInUser.getOrg().equals(channel.getOrg())) {
      // users are not allowed to access properties for a channel that is in a
      // different org
      throw new NotPermittedByOrgException(
          loggedInUser.getOrg().getId().toString(),
          channel.getLabel(),
          channel.getOrg().getId().toString());
    }

    // retrieve the orgs available to be "trusted" for this channel
    List<OrgChannelDto> orgs = OrgManager.orgChannelTrusts(channel.getId(), loggedInUser.getOrg());
    // retrieve the orgs that are trusted for this channel
    Set<Org> trustedOrgs = channel.getTrustedOrgs();

    // populate a result that includes all orgs that could be trusted with a boolean
    // that indicates if the orgs is indeed trusted.
    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
    for (OrgChannelDto orgDto : orgs) {
      Org org = OrgFactory.lookupById(orgDto.getId());

      if (org != null) {
        Map<String, Object> entry = new HashMap<String, Object>();

        entry.put("org_id", org.getId().intValue());
        entry.put("org_name", org.getName());
        if (trustedOrgs.contains(org)) {
          entry.put("access_enabled", Boolean.TRUE);
        } else {
          entry.put("access_enabled", Boolean.FALSE);
        }
        result.add(entry);
      }
    }
    return result;
  }
Пример #19
0
 public void testStagingContent() throws Exception {
   Org org1 = createTestOrg();
   boolean staging = org1.getOrgConfig().isStagingContentEnabled();
   Long id = org1.getId();
   org1.getOrgConfig().setStagingContentEnabled(!staging);
   OrgFactory.save(org1);
   assertEquals(!staging, org1.getOrgConfig().isStagingContentEnabled());
   flushAndEvict(org1);
   Org org2 = OrgFactory.lookupById(id);
   assertEquals(!staging, org2.getOrgConfig().isStagingContentEnabled());
 }
 /**
  * Constructor
  *
  * @param channelFamilyLabel label of entitlement to update
  * @param orgIn to update totals for
  * @param newTotalIn This is the *proposed* new total for the org you are passing in.
  * @param newFlexTotalIn This is the *proposed* new flex total for the org you are passing in.
  */
 public UpdateOrgSoftwareEntitlementsCommand(
     String channelFamilyLabel, Org orgIn, Long newTotalIn, Long newFlexTotalIn) {
   if (orgIn.getId().equals(OrgFactory.getSatelliteOrg().getId())) {
     throw new IllegalArgumentException("Cant update the default org");
   }
   this.org = orgIn;
   this.newTotal = newTotalIn;
   this.newFlexTotal = newFlexTotalIn;
   this.channelFamily =
       ChannelFamilyFactory.lookupByLabel(channelFamilyLabel, OrgFactory.getSatelliteOrg());
   if (this.channelFamily == null) {
     throw new IllegalArgumentException("ChannelFamily not found: [" + channelFamilyLabel + "]");
   }
 }
Пример #21
0
  /**
   * @param user User that owns parent channel
   * @param channelIn base channel to unsubscribe from.
   */
  private void unsubscribeOrgsFromChannel(User user, Channel channelIn, String accessIn) {
    Org org = channelIn.getOrg();

    // find trusted orgs
    Set<Org> trustedOrgs = org.getTrustedOrgs();
    for (Org o : trustedOrgs) {
      // find systems subscribed in org Trust
      DataResult<Map<String, Object>> dr = SystemManager.sidsInOrgTrust(org.getId(), o.getId());

      for (Map<String, Object> item : dr) {
        Long sid = (Long) item.get("id");
        Server s = ServerFactory.lookupById(sid);
        if (s.isSubscribed(channelIn)) {
          // check if this is a base custom channel
          if (channelIn.getParentChannel() == null) {
            // unsubscribe children first if subscribed
            List<Channel> children = channelIn.getAccessibleChildrenFor(user);
            Iterator<Channel> i = children.iterator();
            while (i.hasNext()) {
              Channel child = i.next();
              if (s.isSubscribed(child)) {
                // unsubscribe server from child channel

                child.getTrustedOrgs().remove(o);
                child.setAccess(accessIn);
                ChannelFactory.save(child);
                s = SystemManager.unsubscribeServerFromChannel(s, child);
              }
            }
          }
          // unsubscribe server from channel
          ChannelFactory.save(channelIn);
          s = SystemManager.unsubscribeServerFromChannel(s, channelIn);
        }
      }
    }
  }
Пример #22
0
  /** @param orgIn */
  private void publishUpdateErrataCacheEvent(Org orgIn) {
    StopWatch sw = new StopWatch();
    if (log.isDebugEnabled()) {
      log.debug("Updating errata cache");
      sw.start();
    }

    UpdateErrataCacheEvent uece = new UpdateErrataCacheEvent(UpdateErrataCacheEvent.TYPE_ORG);
    uece.setOrgId(orgIn.getId());
    MessageQueue.publish(uece);

    if (log.isDebugEnabled()) {
      sw.stop();
      log.debug("Finished Updating errata cache. Took [" + sw.getTime() + "]");
    }
  }
Пример #23
0
 /**
  * Test the addition of an entitlement to an org This code should be refactored into a business
  * method of some sort if it becomes necessary to actually add entitlements progmatically from
  * within the Java code. For now we need this test because new Orgs don't have any entitlements.
  */
 public void testAddEntitlement() throws Exception {
   // Create a new Org and add an Entitlement
   Org org1 = UserTestUtils.findNewOrg("testOrg" + this.getClass().getSimpleName());
   Set entitlements = org1.getEntitlements();
   OrgEntitlementType oet = OrgFactory.lookupEntitlementByLabel("sw_mgr_enterprise");
   entitlements.add(oet);
   org1.setEntitlements(entitlements);
   org1 = OrgFactory.save(org1);
   Long orgId = org1.getId();
   // Re-lookup the object and test it
   flushAndEvict(org1);
   Org org2 = OrgFactory.lookupById(orgId);
   assertTrue(org2.hasEntitlement(oet));
 }
Пример #24
0
 public void testImpliedEntitlement() throws Exception {
   Org org1 = createTestOrg();
   assertTrue(org1.hasEntitlement(OrgFactory.getEntitlementSwMgrPersonal()));
 }
Пример #25
0
 public void testCreateOrg() throws Exception {
   Org org1 = createTestOrg();
   Org org2 = OrgFactory.lookupById(org1.getId());
   assertEquals(org2.getName(), org1.getName());
   assertNotNull(org2.getOwnedChannels());
 }
Пример #26
0
  public void testOrgDefautRegistrationToken() throws Exception {
    User user = UserTestUtils.findNewUser("testUser", "testOrg", true);
    Org orig = user.getOrg();
    orig.setName("org created by OrgFactory test: " + TestUtils.randomString());
    // build the channels set
    Channel channel1 = ChannelFactoryTest.createTestChannel(orig);
    flushAndEvict(channel1);
    orig.addOwnedChannel(channel1);
    orig = OrgFactory.save(orig);
    assertTrue(orig.getId().longValue() > 0);

    assertNull(orig.getToken());
    ActivationKey key = ActivationKeyTest.createTestActivationKey(user);
    // Token is hidden behind activation key so we have to look it up
    // manually:
    Token token = TokenFactory.lookupById(key.getId());
    orig.setToken(token);
    orig = OrgFactory.save(orig);
    Long origId = orig.getId();
    flushAndEvict(orig);

    Org lookup = OrgFactory.lookupById(origId);
    assertEquals(token.getId(), lookup.getToken().getId());
    lookup.setToken(null);
    flushAndEvict(lookup);

    lookup = OrgFactory.lookupById(origId);
    assertNull(lookup.getToken());
  }
Пример #27
0
 public void testHasEntitlementFalse() throws Exception {
   Org org1 = createTestOrg();
   OrgEntitlementType oet = OrgFactory.lookupEntitlementByLabel("sw_mgr_enterprise");
   assertFalse(org1.hasEntitlement(oet));
 }
Пример #28
0
 public void testLookupById() throws Exception {
   Org org1 = UserTestUtils.findNewOrg("testOrg" + this.getClass().getSimpleName());
   assertNotNull(org1);
   assertTrue(org1.getId().longValue() > 0);
 }
Пример #29
0
 public void testOrgTrust() throws Exception {
   Org org = createTestOrg();
   Org trusted = createTestOrg();
   org.getTrustedOrgs().add(trusted);
   OrgFactory.save(org);
   flushAndEvict(org);
   org = OrgFactory.lookupById(org.getId());
   trusted = OrgFactory.lookupById(trusted.getId());
   assertContains(org.getTrustedOrgs(), trusted);
   assertContains(trusted.getTrustedOrgs(), org);
   org.getTrustedOrgs().remove(trusted);
   OrgFactory.save(org);
   flushAndEvict(org);
   org = OrgFactory.lookupById(org.getId());
   trusted = OrgFactory.lookupById(trusted.getId());
   assertFalse(org.getTrustedOrgs().contains(trusted));
   assertFalse(trusted.getTrustedOrgs().contains(org));
 }
Пример #30
0
 /** Test to see if the Org returns list of UserGroup IDs */
 public void testGetRoles() throws Exception {
   Org org1 = UserTestUtils.findNewOrg("testOrg" + this.getClass().getSimpleName());
   assertNotNull(org1.getRoles());
   assertTrue(org1.hasRole(RoleFactory.ORG_ADMIN));
 }