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