private void checkVirtEnt(ServerGroupType sgt, Channel virt, Channel tools) throws Exception {
   ActivationKey key = createActivationKey();
   key.addEntitlement(sgt);
   assertTrue(key.getChannels().contains(tools));
   assertTrue(key.getChannels().contains(virt));
   assertTrue(!key.getPackages().isEmpty());
   TokenPackage pkg = key.getPackages().iterator().next();
   assertEquals(ChannelManager.RHN_VIRT_HOST_PACKAGE_NAME, pkg.getPackageName().getName());
 }
Ejemplo n.º 2
0
  public void testAddGetKeys() throws Exception {

    ActivationKey k = createTestActivationKey(user);

    for (int i = 0; i < 5; i++) {
      Channel c = ChannelFactoryTest.createTestChannel(user);
      k.addChannel(c);
    }
    assertTrue(k.getChannels().size() == 5);
  }
  public void testDeployConfig() throws Exception {
    UserTestUtils.addUserRole(user, RoleFactory.ACTIVATION_KEY_ADMIN);

    // need a tools channel for config deploy
    Channel base = ChannelTestUtils.createBaseChannel(user);
    ChannelTestUtils.setupBaseChannelForVirtualization(user, base);

    ActivationKey key = createActivationKey();
    // Create a config channel
    ConfigChannel cc = ConfigTestUtils.createConfigChannel(user.getOrg());
    ConfigChannelListProcessor proc = new ConfigChannelListProcessor();
    proc.add(key.getConfigChannelsFor(user), cc);
    key.setDeployConfigs(true);
    ActivationKeyFactory.save(key);
    assertTrue(key.getDeployConfigs());
    assertFalse(key.getChannels().isEmpty());
    assertFalse(key.getPackages().isEmpty());
  }
  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());
  }