public void testHasAcl() {

    MockHttpServletRequest request = TestUtils.getRequestWithSessionAndUser();
    String singleTrue = "true_test()";
    String multipleTrue = "first_true_acl(); second_true_acl()";
    String singleFalse = "false_test()";
    String multipleFalse = "first_false_acl(); second_false_acl()";
    String lastFalse = "first_true_acl(); second_true_acl(); first_false_acl()";
    String oneFalse = "first_true_acl(); first_false_acl(); second_true_acl()";
    String singleFoo = "is_foo(foo)";
    String doubleFoo = "is_foo(foo); is_foo(foo)";
    String fooPlus = "true_test(); is_foo(foo)";
    String notFoo = "is_foo(notfoo)";
    String invalid = "flkas";
    String mixinFoo = MockFooAclHandler.class.getName();
    String mixinMultiple = MockMultipleAclHandler.class.getName();
    String mixinBoolean = BooleanAclHandler.class.getName();

    assertTrue(AclManager.hasAcl(singleTrue, request, mixinBoolean));
    assertTrue(AclManager.hasAcl(multipleTrue, request, mixinMultiple));
    assertFalse(AclManager.hasAcl(singleFalse, request, mixinBoolean));
    assertFalse(AclManager.hasAcl(multipleFalse, request, mixinMultiple));
    assertFalse(AclManager.hasAcl(lastFalse, request, mixinMultiple));
    assertFalse(AclManager.hasAcl(oneFalse, request, mixinMultiple));
    assertTrue(AclManager.hasAcl(singleFoo, request, mixinFoo));
    assertTrue(AclManager.hasAcl(doubleFoo, request, mixinFoo));
    assertTrue(AclManager.hasAcl(fooPlus, request, mixinFoo + "," + mixinBoolean));
    assertFalse(AclManager.hasAcl(notFoo, request, mixinFoo));

    try {
      AclManager.hasAcl(invalid, request, mixinBoolean);
      fail(); // should never get here
    } catch (Exception e) {
      // no op
    }

    try {
      AclManager.hasAcl(oneFalse, request, invalid);
      fail(); // should never get here
    } catch (Exception e) {
      // no op
    }
  }
  /**
   * 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());
    }
  }