/**
   * Add the up2date package to a system and a channel. Version should be specified such as "2.9.0"
   *
   * @param userIn
   * @param s
   * @param version
   * @param c
   * @return
   * @throws Exception
   */
  public static Package addUp2dateToSystemAndChannel(
      User userIn, Server s, String version, Channel c) throws Exception {

    Package p = null;
    PackageName pn = PackageFactory.lookupOrCreatePackageByName("up2date");
    if (pn != null) {
      List packages = PackageFactory.listPackagesByPackageName(pn);
      Iterator i = packages.iterator();
      while (i.hasNext()) {
        Package innerp = (Package) i.next();
        PackageEvr evr = innerp.getPackageEvr();
        if (evr != null && evr.getVersion().equals(version)) {
          p = innerp;
        }
      }
    }
    if (p == null) {
      p = PackageManagerTest.addPackageToSystemAndChannel("up2date", s, c);
      PackageEvr pevr = p.getPackageEvr();
      pevr.setEpoch("0");
      pevr.setVersion(version);
      pevr.setRelease("0");
      TestUtils.saveAndFlush(p);
      TestUtils.saveAndFlush(pevr);
    } else {
      PackageManagerTest.associateSystemToPackage(s, p);
    }

    return p;
  }
 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()));
 }
  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
    }
  }
示例#4
0
  public void testIsProxy() throws Exception {
    Channel c = ChannelFactoryTest.createTestChannel(user);
    ChannelFamily cfam =
        ChannelFamilyFactoryTest.createTestChannelFamily(
            user, false, ChannelFamilyFactory.PROXY_CHANNEL_FAMILY_LABEL);

    c.setChannelFamily(cfam);

    TestUtils.saveAndFlush(c);

    Channel c2 = ChannelFactory.lookupById(c.getId());
    assertTrue(c2.isProxy());
  }
  /**
   * Create a package with the given name and add it to the given channel. If a package by that name
   * already exists, this simply returns that package.
   *
   * @param packageName The name of the package to create.
   * @param c The channel to which to add the package
   * @return The package with that name in the channel.
   * @throws Exception
   */
  public static Package addPackageToChannel(String packageName, Channel c) throws Exception {

    PackageName pn = PackageFactory.lookupOrCreatePackageByName(packageName);
    if (pn == null) {
      pn = PackageNameTest.createTestPackageName();
      pn.setName(packageName);
    }

    Long existingId = ChannelManager.getLatestPackageEqual(c.getId(), packageName);

    if (existingId != null) {
      return PackageFactory.lookupByIdAndOrg(existingId, c.getOrg());
    }

    // existingId =
    Session session = HibernateFactory.getSession();
    Query query =
        session.createQuery(
            "from Package as "
                + "package where package.org.id = "
                + c.getOrg().getId()
                + " and package.packageName.id = "
                + pn.getId());
    List packages = query.list();
    Package retval = null;
    if (packages != null && packages.size() > 0) {
      retval = (Package) packages.get(0);
    } else {
      retval = PackageTest.createTestPackage(c.getOrg());
    }

    retval.setPackageName(pn);
    TestUtils.saveAndFlush(retval);
    PackageTest.addPackageToChannelNewestPackage(retval, c);

    return retval;
  }