public void testLookup() { // first lets just check on permissions... user.addPermanentRole(RoleFactory.ACTIVATION_KEY_ADMIN); final ActivationKey key = manager.createNewActivationKey(user, "Test"); ActivationKey temp; // we make newuser // unfortunately satellite is NOT multiorg aware... // So we can't check on the org clause // so... User newUser = UserTestUtils.findNewUser("testUser2", "testOrg" + this.getClass().getSimpleName()); try { manager.lookupByKey(key.getKey(), newUser); String msg = "Permission check failed :(.." + "Activation key should not have gotten found out" + " because the user does not have activation key admin role"; fail(msg); } catch (Exception e) { // great!.. Exception for permission failure always welcome } try { temp = manager.lookupByKey(key.getKey() + "FOFOFOFOFOFOF", user); String msg = "NUll lookup failed, because this object should NOT exist!"; fail(msg); } catch (Exception e) { // great!.. Exception for null lookpu is controvoersial but convenient.. } temp = manager.lookupByKey(key.getKey(), user); assertNotNull(temp); assertEquals(user.getOrg(), temp.getOrg()); }
public void testKeyGeneration() throws Exception { ActivationKey k = createTestActivationKey(user); String note = k.getNote(); String key = k.getKey(); TestUtils.saveAndFlush(k); ActivationKey k2 = ActivationKeyFactory.lookupByKey(key); assertEquals(key, k2.getKey()); assertEquals(note, k2.getNote()); ActivationKey k3 = ActivationKeyFactory.lookupByKey(TestUtils.randomString()); assertNull(k3); // Make sure we got the entitlements correct Server server = k2.getServer(); assertEquals(1, server.getEntitlements().size()); assertEquals(1, k2.getEntitlements().size()); Entitlement e = server.getEntitlements().iterator().next(); ServerGroupType t2 = k2.getEntitlements().iterator().next(); assertEquals(e.getLabel(), t2.getLabel()); // test out ActivationKeyManager.findByServer while we're here... ActivationKey k4 = ActivationKeyManager.getInstance().findByServer(server, user).iterator().next(); assertNotNull(k4); assertEquals(key, k4.getKey()); try { k3 = ActivationKeyManager.getInstance().findByServer(null, user).iterator().next(); String msg = "Permission check failed :(.." + " Activation key should not have existed" + " for a server of 'null' id. An exception " + "should have been raised for this."; fail(msg); } catch (Exception ie) { // great!.. Exception for passing in invalid keys always welcome } User user1 = UserTestUtils.findNewUser("testuser", "testorg"); Server server2 = ServerFactoryTest.createTestServer(user1); try { k3 = ActivationKeyManager.getInstance().findByServer(server2, user1).iterator().next(); String msg = "Permission check failed :(.." + " Activation key should not have existed" + " for a server of the associated id. An exception " + "should have been raised for this."; fail(msg); } catch (Exception ie) { // great!.. Exception for passing in invalid keys always welcome } }
public void testDelete() throws Exception { user.addPermanentRole(RoleFactory.ACTIVATION_KEY_ADMIN); ActivationKey key = manager.createNewActivationKey(user, "Test"); ActivationKey temp = manager.lookupByKey(key.getKey(), user); assertNotNull(temp); manager.remove(temp, user); try { temp = manager.lookupByKey(key.getKey(), user); String msg = "NUll lookup failed, because this object should exist!"; fail(msg); } catch (Exception e) { // great!.. Exception for null lookpu is controvoersial but convenient.. } }
public void testCreateNewKeys() throws Exception { ActivationKey k = createTestActivationKey(user); Server s = k.getServer(); for (int i = 0; i < 10; i++) { ActivationKey tk = createTestActivationKey(s.getCreator(), s); System.out.println("tk: " + tk.getKey()); } }
public void testKeyTrimming() throws Exception { ActivationKeyManager manager = ActivationKeyManager.getInstance(); String keyName = " Test Space "; ActivationKey k = manager.createNewActivationKey(user, keyName, "Cool Duplicate", null, null, false); assertEquals( ActivationKey.makePrefix(user.getOrg()) + keyName.trim().replace(" ", ""), k.getKey()); String newKey = keyName + " FOO "; manager.changeKey(newKey, k, user); assertNotNull(ActivationKey.makePrefix(user.getOrg()) + newKey.trim()); }
public void testCreate() throws Exception { user.addPermanentRole(RoleFactory.ACTIVATION_KEY_ADMIN); String note = "Test"; final ActivationKey key = manager.createNewActivationKey(user, note); assertEquals(user.getOrg(), key.getOrg()); assertEquals(note, key.getNote()); assertNotNull(key.getKey()); Server server = ServerFactoryTest.createTestServer(user, true); final ActivationKey key1 = manager.createNewReActivationKey(user, server, note); assertEquals(server, key1.getServer()); ActivationKey temp = manager.lookupByKey(key.getKey(), user); assertNotNull(temp); assertEquals(user.getOrg(), temp.getOrg()); assertEquals(note, temp.getNote()); String keyName = "I_RULE_THE_WORLD"; Long usageLimit = new Long(1200); Channel baseChannel = ChannelTestUtils.createBaseChannel(user); final ActivationKey key2 = manager.createNewReActivationKey( user, server, keyName, note, usageLimit, baseChannel, true, null); temp = (ActivationKey) reload(key2); assertTrue(temp.getKey().endsWith(keyName)); assertEquals(note, temp.getNote()); assertEquals(usageLimit, temp.getUsageLimit()); Set channels = new HashSet(); channels.add(baseChannel); assertEquals(channels, temp.getChannels()); // since universal default == true we have to // check if the user org has it.. Token token = user.getOrg().getToken(); assertEquals(channels, token.getChannels()); assertEquals(usageLimit, token.getUsageLimit()); }