private void runNonLdapSearchControlsActions(DirContext context) throws NamingException {
    OperationCollectionAspectSupport aspectInstance = getAspect();

    for (final SearchControlsActions action : SearchControlsActions.values()) {
      aspectInstance.setCollector(
          new OperationCollector() {
            public void enter(Operation operation) {
              fail(action + ": Unexpected enter call");
            }

            public void exitNormal() {
              fail(action + ": Unexpected exitNormal call");
            }

            public void exitNormal(Object returnValue) {
              fail(action + ": Unexpected exitNormal call with value");
            }

            public void exitAbnormal(Throwable throwable) {
              fail(action + ": Unexpected exitAbnormal call");
            }

            public void exitAndDiscard() {
              fail(action + ": Unexpected exitAndDiscard call");
            }

            public void exitAndDiscard(Object returnValue) {
              fail(action + ": Unexpected exitAndDiscard call with value");
            }
          });
      NamingEnumeration<SearchResult> result =
          action.search(context, "type=test", "blah blah", action);
      try {
        assertNotNull(action + ": no result", result);
        assertFalse(action + ": unexpected result", result.hasMore());
      } finally {
        result.close();
      }
    }
  }
  private void runLiveSearchControlsActions(DirContextCreator creator)
      throws NamingException, URISyntaxException {
    final String DN_PROPNAME = "objectclass", DN_PROPVAL = "person", BASE_DN = "ou=people";
    final String ARGS_FILTER = "(&(" + DN_PROPNAME + "=" + DN_PROPVAL + ")(uid={0})(sn={1}))";
    final Format userSearchFilter = new MessageFormat(ARGS_FILTER);

    for (Map<String, Set<String>> ldifEntry : LDIF_ENTRIES) {
      Set<String> classValues = ldifEntry.get(DN_PROPNAME);
      if (!classValues.contains(DN_PROPVAL)) {
        continue;
      }
      Set<String> values = ldifEntry.get("cn");
      assertNotNull("No CN for " + ldifEntry, values);
      assertEquals("Multiple CB(s) for " + ldifEntry, 1, values.size());

      /*
       * The LDIF is set up in such a way that for person(s), the
       * 'uid' value is same as the 1st name in lowercase, and the
       * 'sn' value is same as the 2nd name
       */
      String cnValue = values.iterator().next().trim();
      int spacePos = cnValue.indexOf(' ');
      String uidValue = cnValue.substring(0, spacePos).toLowerCase();
      String snValue = cnValue.substring(spacePos + 1);
      Object[] filterArgs = {uidValue, snValue};
      String noArgsFilter = userSearchFilter.format(filterArgs);
      for (SearchControlsActions action : SearchControlsActions.values()) {
        final String TEST_NAME = cnValue + "[" + action + "]";
        final String TEST_FILTER = action.isRequiredFilterArgs() ? ARGS_FILTER : noArgsFilter;
        final Object[] SEARCH_ARGS = action.isRequiredFilterArgs() ? filterArgs : null;
        logger.info("Running test: " + TEST_NAME);
        DirContext context = creator.createDirContext();
        Hashtable<?, ?> environment;
        try {
          // save a copy just in case it changes on context close
          environment = new Hashtable<Object, Object>(context.getEnvironment());

          NamingEnumeration<SearchResult> result =
              action.search(context, BASE_DN, TEST_FILTER, SEARCH_ARGS);
          assertNotNull(TEST_NAME + ": No result", result);
          try {
            if (!checkMatchingSearchResult(result, "cn", cnValue)) {
              fail(TEST_NAME + ": No match found");
            }
          } finally {
            result.close();
          }
        } catch (NamingException e) {
          logger.warn(
              "search("
                  + TEST_NAME
                  + ")"
                  + " "
                  + e.getClass().getSimpleName()
                  + ": "
                  + e.getMessage(),
              e);
          throw e;
        } finally {
          context.close();
        }

        Operation op = assertContextOperation(TEST_NAME, BASE_DN, environment);
        assertEquals(
            TEST_NAME + ": Mismatched filter",
            TEST_FILTER,
            op.get(LdapDefinitions.LOOKUP_FILTER_ATTR, String.class));
        assertExternalResourceAnalysis(
            TEST_NAME, op, (String) environment.get(Context.PROVIDER_URL));
        Mockito.reset(spiedOperationCollector); // prepare for next iteration
      }
    }
  }