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());
  }
 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());
 }
 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;
 }
 /**
  * @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);
 }