public void testSystemPackageList() throws Exception {
    // need a system
    // need to add packages to that system
    // then need to query those values
    PageControl pc = new PageControl();
    pc.setIndexData(false);
    pc.setStart(1);

    user.addRole(RoleFactory.ORG_ADMIN);

    Server server = ServerFactoryTest.createTestServer(user, true);
    PackageManagerTest.addPackageToSystemAndChannel(
        "test-package-name" + TestUtils.randomString(),
        server,
        ChannelFactoryTest.createTestChannel(user));

    DataResult dr = PackageManager.systemPackageList(server.getId(), pc);
    assertNotNull(dr);
    assertEquals(1, dr.size());

    for (Iterator itr = dr.iterator(); itr.hasNext(); ) {
      Object o = itr.next();
      assertTrue(o instanceof PackageListItem);
    }
  }
  public static ActivationKey createTestActivationKey(User user) throws Exception {
    Server server =
        ServerFactoryTest.createTestServer(
            user, true, ServerConstants.getServerGroupTypeEnterpriseEntitled());

    return createTestActivationKey(user, server);
  }
 public void testGetServerNeededUpdatePackageByName() throws Exception {
   user.addRole(RoleFactory.ORG_ADMIN);
   Server s = ServerFactoryTest.createTestServer(user);
   Channel c = ChannelFactoryTest.createTestChannel(user);
   addPackageToSystemAndChannel("some-test-package", s, c);
   // Not enough time actually test the results of this query for now
   // Just testing that it runs without SQL error. -mmccune
   assertNull(PackageManager.getServerNeededUpdatePackageByName(s.getId(), "some-test-package"));
 }
  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
    }
  }
  // See BZ: 191007
  public void testCreateWithCustomGroups() throws Exception {
    Server s =
        ServerFactoryTest.createTestServer(
            user, true, ServerConstants.getServerGroupTypeEnterpriseEntitled());
    ServerGroup testGroup = ServerGroupTestUtils.createManaged(user);
    s.getManagedGroups().add((ManagedServerGroup) testGroup);

    // Three, one for the server entitlement, one for the user permission to the
    // server, one as the testGroup.
    assertEquals(1, s.getManagedGroups().size());
    ActivationKey key = createTestActivationKey(user, s);
    assertNotNull(key);
    key = (ActivationKey) reload(key);
    assertNotNull(key.getId());
  }
  public void testExecute() throws Exception {
    // Create a config channel and a server
    ConfigChannel channel = ConfigTestUtils.createConfigChannel(user.getOrg());
    Server server =
        ServerFactoryTest.createTestServer(
            user, true, ServerConstants.getServerGroupTypeProvisioningEntitled());
    // associate the two.
    server.subscribe(channel);
    SystemManager.storeServer(server);

    setRequestPathInfo("/systems/details/configuration/ConfigChannelList");
    addRequestParameter("sid", server.getId().toString());
    actionPerform();
    verifyPageList(ConfigChannelDto.class);
  }
Esempio n. 7
0
  /**
   * Test fetching a PackageAction
   *
   * @throws Exception
   */
  public void testLookupPackageAction() throws Exception {

    Action newA =
        ActionFactoryTest.createAction(
            UserTestUtils.createUser(
                "testUser", UserTestUtils.createOrg("testOrg" + this.getClass().getSimpleName())),
            ActionFactory.TYPE_PACKAGES_VERIFY);
    assertNotNull(newA.getId());
    assertTrue(newA instanceof PackageAction);
    PackageAction p = (PackageAction) newA;
    assertNotNull(p.getDetails());
    assertEquals(p.getDetails().size(), 1);
    PackageActionDetails firstDetail = (PackageActionDetails) p.getDetails().toArray()[0];

    /** Make sure PackageEvr was set & committed correctly */
    Set details = p.getDetails();
    Iterator ditr = details.iterator();
    while (ditr.hasNext()) {
      PackageActionDetails detail = (PackageActionDetails) ditr.next();
      assertNotNull(detail.getEvr().getId());
    }

    User user = UserTestUtils.findNewUser("TEST USER", "TEST ORG");
    Server testserver = ServerFactoryTest.createTestServer(user);

    PackageActionResult result = new PackageActionResult();
    result.setServer(testserver);
    result.setDetails(firstDetail);
    result.setResultCode(new Long(42));
    result.setCreated(new Date());
    result.setModified(new Date());

    firstDetail.addResult(result);

    ActionFactory.save(p);

    PackageAction p2 = (PackageAction) ActionFactory.lookupById(p.getId());

    assertNotNull(p2.getDetails());
    assertEquals(p2.getDetails().size(), 1);
    assertNotNull(p2.getDetails().toArray()[0]);
    firstDetail = (PackageActionDetails) p2.getDetails().toArray()[0];
    assertNotNull(firstDetail.getResults());
    assertEquals(firstDetail.getResults().size(), 1);
  }
Esempio n. 8
0
  public void testCreatePackageRemoveAction() throws Exception {
    User user = UserTestUtils.findNewUser("testUser", "testOrg" + this.getClass().getSimpleName());
    Server srvr = ServerFactoryTest.createTestServer(user);

    ServerAction sa = new ServerAction();
    sa.setStatus(ActionFactory.STATUS_QUEUED);
    sa.setRemainingTries(new Long(10));
    sa.setServer(srvr);
    log.debug("Creating PackageRemoveAction.");
    PackageAction pra =
        (PackageAction) ActionFactory.createAction(ActionFactory.TYPE_PACKAGES_REMOVE);
    pra.setOrg(user.getOrg());
    pra.setName("Package Removal");
    pra.addServerAction(sa);
    sa.setParentAction(pra);
    log.debug("Committing PackageRemoveAction.");
    ActionFactory.save(pra);

    PackageAction result = (PackageAction) ActionFactory.lookupById(pra.getId());

    assertEquals(pra, result);
  }
  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());
  }
  public void testAddOne() throws Exception {
    BaseSystemListAction action = createAction();
    ActionHelper ah = new ActionHelper();
    ah.setUpAction(action);
    ah.setupProcessPagination();

    User user = ah.getUser();
    user.addPermanentRole(RoleFactory.ORG_ADMIN);
    // Create a server that can be put in the set. Note that the
    // server is not set up entirely right for subclasses, which would
    // only display servers with certain attributes, e.g. a satellite.
    // But this test is only concerned with keeping a server in the set
    // w/o having it cleaned up by the set cleaner
    Server server =
        ServerFactoryTest.createTestServer(
            user, true, ServerConstants.getServerGroupTypeEnterpriseEntitled());
    UserManager.storeUser(user);
    String sid = server.getId().toString();
    ah.getRequest().setupAddParameter("items_on_page", (String[]) null);
    ah.getRequest().setupAddParameter("items_selected", new String[] {sid});
    ah.executeAction("updatelist");

    RhnSetActionTest.verifyRhnSetData(ah.getUser(), RhnSetDecl.SYSTEMS, 1);
  }
  /**
   * Tests save().
   *
   * @throws Exception if something bad happens
   */
  @SuppressWarnings("unchecked")
  public void testSave() throws Exception {
    RhnMockHttpServletRequest request = TestUtils.getRequestWithSessionAndUser();
    user = new RequestContext(request).getCurrentUser();

    ActionChainSaveAction saveAction = new ActionChainSaveAction();
    String label = TestUtils.randomString();
    ActionChain actionChain = ActionChainFactory.createActionChain(label, user);
    for (int i = 0; i < 6; i++) {
      Action action = ActionFactory.createAction(ActionFactory.TYPE_ERRATA);
      action.setOrg(user.getOrg());
      ActionFactory.save(action);
      ActionChainFactory.queueActionChainEntry(
          action, actionChain, ServerFactoryTest.createTestServer(user), i / 2);
    }
    Action lastAction = ActionFactory.createAction(ActionFactory.TYPE_ERRATA);
    lastAction.setOrg(user.getOrg());
    ActionFactory.save(lastAction);
    ActionChainFactory.queueActionChainEntry(
        lastAction, actionChain, ServerFactoryTest.createTestServer(user), 3);

    String newLabel = TestUtils.randomString();
    List<Long> deletedEntries = new LinkedList<Long>();
    deletedEntries.add(lastAction.getId());
    List<Integer> deletedSortOrders = new LinkedList<Integer>();
    deletedSortOrders.add(0);
    deletedSortOrders.add(3);
    List<Integer> reorderedSortOrders = new LinkedList<Integer>();
    reorderedSortOrders.add(2);
    reorderedSortOrders.add(1);

    String resultString =
        saveAction.save(
            actionChain.getId(),
            newLabel,
            deletedEntries,
            deletedSortOrders,
            reorderedSortOrders,
            request);

    Map<String, Object> result = (Map<String, Object>) new JSONReader().read(resultString);
    assertEquals(true, result.get(ActionChainSaveAction.SUCCESS_FIELD));
    assertEquals(
        LocalizationService.getInstance().getMessage("actionchain.jsp.saved"),
        result.get(ActionChainSaveAction.TEXT_FIELD));
    assertEquals(newLabel, actionChain.getLabel());

    Set<ActionChainEntry> entries = actionChain.getEntries();
    assertEquals(4, entries.size());

    List<ActionChainEntry> sortedEntries = new LinkedList<ActionChainEntry>();
    sortedEntries.addAll(entries);
    Collections.sort(
        sortedEntries,
        new Comparator<ActionChainEntry>() {
          public int compare(ActionChainEntry entry1, ActionChainEntry entry2) {
            return entry1.getId().compareTo(entry2.getId());
          }
        });
    for (int i = 0; i < sortedEntries.size(); i++) {
      assertEquals((Integer) (1 - i / 2), sortedEntries.get(i).getSortOrder());
    }
  }