directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1225696 [3/5] - in /directory/apacheds/branches/apacheds-txns: core-api/src/main/java/org/apache/directory/server/core/api/ core-api/src/main/java/org/apache/directory/server/core/api/filtering/ core-api/src/main/java/org/apache/directory/...
Date Thu, 29 Dec 2011 23:54:20 GMT
Modified: directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/operations/search/SearchIT.java Thu Dec 29 23:54:19 2011
@@ -20,9 +20,7 @@
 package org.apache.directory.server.core.operations.search;
 
 
-import static org.apache.directory.server.core.integ.IntegrationUtils.getRootContext;
 import static org.apache.directory.server.core.integ.IntegrationUtils.getSchemaContext;
-import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -32,18 +30,15 @@ import static org.junit.Assert.fail;
 
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
 
-import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttribute;
 import javax.naming.directory.DirContext;
-import javax.naming.directory.InvalidSearchFilterException;
 import javax.naming.directory.ModificationItem;
-import javax.naming.directory.SearchControls;
-import javax.naming.directory.SearchResult;
 import javax.naming.ldap.LdapContext;
 
 import org.apache.directory.ldap.client.api.LdapConnection;
@@ -52,9 +47,9 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
 import org.apache.directory.server.core.integ.FrameworkRunner;
 import org.apache.directory.server.core.integ.IntegrationUtils;
-import org.apache.directory.shared.ldap.model.constants.JndiPropertyConstants;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.cursor.EntryCursor;
+import org.apache.directory.shared.ldap.model.cursor.SearchCursor;
 import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
 import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.entry.StringValue;
@@ -63,8 +58,9 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.filter.ExprNode;
 import org.apache.directory.shared.ldap.model.filter.GreaterEqNode;
 import org.apache.directory.shared.ldap.model.filter.LessEqNode;
-import org.apache.directory.shared.ldap.model.ldif.LdifUtils;
-import org.apache.directory.shared.ldap.model.message.AliasDerefMode;
+import org.apache.directory.shared.ldap.model.message.SearchRequest;
+import org.apache.directory.shared.ldap.model.message.SearchRequestImpl;
+import org.apache.directory.shared.ldap.model.message.SearchResultEntry;
 import org.apache.directory.shared.ldap.model.message.SearchScope;
 import org.apache.directory.shared.ldap.model.name.Dn;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
@@ -81,7 +77,7 @@ import org.junit.runner.RunWith;
 @RunWith(FrameworkRunner.class)
 @CreateDS(name = "SearchDS")
 @ApplyLdifs(
-    {         
+    {
         "dn: m-oid=2.2.0, ou=attributeTypes, cn=apachemeta, ou=schema",
         "objectclass: metaAttributeType",
         "objectclass: metaTop",
@@ -157,1793 +153,1609 @@ import org.junit.runner.RunWith;
         "sn: manager",
         "telephoneNumber: 1 801 555 1212 ",
         "manager: cn=Heather Nova, ou=system"
- })
+})
 public class SearchIT extends AbstractLdapTestUnit
 {
-    private static final String RDN = "cn=Heather Nova";
-    private static final String FILTER = "(objectclass=*)";
+private static final String RDN = "cn=Heather Nova,ou=system";
+private static final String FILTER = "(objectclass=*)";
 
-    public static LdapContext sysRoot;
+//public static LdapContext sysRoot;
+public LdapConnection sysRoot;
 
 
-    /**
-     * @param sysRoot the system root to add entries to
-     * @throws NamingException on errors
-     */
-    @Before
-    public void createData() throws Exception
-    {
-        getService().getSchemaManager().enable( "nis" );
+/**
+ * @param sysRoot the system root to add entries to
+ * @throws NamingException on errors
+ */
+@Before
+public void createData() throws Exception
+{
+    getService().getSchemaManager().enable( "nis" );
 
-        sysRoot = getSystemContext( getService() );
+    sysRoot = IntegrationUtils.getAdminConnection( getService() );
 
-        /*
-         * Check ou=testing00,ou=system
-         */
-        DirContext ctx = ( DirContext ) sysRoot.lookup( "ou=testing00" );
-        assertNotNull( ctx );
-        Attributes attributes = ctx.getAttributes( "" );
-        assertNotNull( attributes );
-        assertEquals( "testing00", attributes.get( "ou" ).get() );
-        Attribute attribute = attributes.get( "objectClass" );
-        assertNotNull( attribute );
-        assertTrue( attribute.contains( "top" ) );
-        assertTrue( attribute.contains( "organizationalUnit" ) );
-
-        /*
-         * check ou=testing01,ou=system
-         */
-        ctx = ( DirContext ) sysRoot.lookup( "ou=testing01" );
-        assertNotNull( ctx );
-        attributes = ctx.getAttributes( "" );
-        assertNotNull( attributes );
-        assertEquals( "testing01", attributes.get( "ou" ).get() );
-        attribute = attributes.get( "objectClass" );
-        assertNotNull( attribute );
-        assertTrue( attribute.contains( "top" ) );
-        assertTrue( attribute.contains( "organizationalUnit" ) );
-
-        /*
-         * Check ou=testing02,ou=system
-         */
-        ctx = ( DirContext ) sysRoot.lookup( "ou=testing02" );
-        assertNotNull( ctx );
-
-        attributes = ctx.getAttributes( "" );
-        assertNotNull( attributes );
-        assertEquals( "testing02", attributes.get( "ou" ).get() );
-
-        attribute = attributes.get( "objectClass" );
-        assertNotNull( attribute );
-        assertTrue( attribute.contains( "top" ) );
-        assertTrue( attribute.contains( "organizationalUnit" ) );
-
-        /*
-         * Check ou=subtest,ou=testing01,ou=system
-         */
-        ctx = ( DirContext ) sysRoot.lookup( "ou=subtest,ou=testing01" );
-        assertNotNull( ctx );
-
-        attributes = ctx.getAttributes( "" );
-        assertNotNull( attributes );
-        assertEquals( "subtest", attributes.get( "ou" ).get() );
-
-        attribute = attributes.get( "objectClass" );
-        assertNotNull( attribute );
-        assertTrue( attribute.contains( "top" ) );
-        assertTrue( attribute.contains( "organizationalUnit" ) );
-
-        /*
-         *  Check entry cn=Heather Nova, ou=system
-         */
-        ctx = ( DirContext ) sysRoot.lookup( RDN );
-        assertNotNull( ctx );
-
-        // -------------------------------------------------------------------
-        // Enable the nis schema
-        // -------------------------------------------------------------------
-
-        // check if nis is disabled
-        LdapContext schemaRoot = getSchemaContext( getService() );
-        Attributes nisAttrs = schemaRoot.getAttributes( "cn=nis" );
-        boolean isNisDisabled = false;
+    /*
+     * Check ou=testing00,ou=system
+     */
+    Entry entry = sysRoot.lookup( "ou=testing00,ou=system" );
+    assertNotNull( entry );
 
-        if ( nisAttrs.get( "m-disabled" ) != null )
-        {
-            isNisDisabled = ( ( String ) nisAttrs.get( "m-disabled" ).get() ).equalsIgnoreCase( "TRUE" );
-        }
+    assertNotNull( entry.getAttributes() );
+    assertTrue( entry.contains( "ou", "testing00" ) );
+    assertTrue( entry.contains( "objectClass", "top", "organizationalUnit" ) );
 
-        // if nis is disabled then enable it
-        if ( isNisDisabled )
-        {
-            Attribute disabled = new BasicAttribute( "m-disabled" );
-            ModificationItem[] mods = new ModificationItem[]
-                { new ModificationItem( DirContext.REMOVE_ATTRIBUTE, disabled ) };
-            schemaRoot.modifyAttributes( "cn=nis", mods );
-        }
+    /*
+     * check ou=testing01,ou=system
+     */
+    entry = sysRoot.lookup( "ou=testing01,ou=system" );
+    assertNotNull( entry );
+    assertNotNull( entry.getAttributes() );
+    assertTrue( entry.contains( "ou", "testing01" ) );
+    assertTrue( entry.contains( "objectClass", "top", "organizationalUnit" ) );
 
-        // -------------------------------------------------------------------
-        // Add a bunch of nis groups
-        // -------------------------------------------------------------------
-        addNisPosixGroup( "testGroup0", 0 );
-        addNisPosixGroup( "testGroup1", 1 );
-        addNisPosixGroup( "testGroup2", 2 );
-        addNisPosixGroup( "testGroup4", 4 );
-        addNisPosixGroup( "testGroup5", 5 );
-    }
+    /*
+     * Check ou=testing02,ou=system
+     */
+    entry = sysRoot.lookup( "ou=testing02,ou=system" );
+    assertNotNull( entry );
+    assertNotNull( entry.getAttributes() );
+    assertTrue( entry.contains( "ou", "testing02" ) );
+    assertTrue( entry.contains( "objectClass", "top", "organizationalUnit" ) );
 
+    /*
+     * Check ou=subtest,ou=testing01,ou=system
+     */
+    entry = sysRoot.lookup( "ou=subtest,ou=testing01,ou=system" );
+    assertNotNull( entry );
+    assertNotNull( entry.getAttributes() );
+    assertTrue( entry.contains( "ou", "subtest" ) );
+    assertTrue( entry.contains( "objectClass", "top", "organizationalUnit" ) );
 
-    /**
-     * Create a NIS group
+    /*
+     *  Check entry cn=Heather Nova, ou=system
      */
-    private static DirContext addNisPosixGroup( String name, int gid ) throws Exception
-    {
-        Attributes attrs = LdifUtils.createJndiAttributes("objectClass: top", "objectClass: posixGroup", "cn", name,
-                "gidNumber", String.valueOf(gid));
+    entry = sysRoot.lookup( RDN );
+    assertNotNull( entry );
 
-        return getSystemContext( getService() ).createSubcontext( "cn=" + name + ",ou=groups", attrs );
-    }
+    // -------------------------------------------------------------------
+    // Enable the nis schema
+    // -------------------------------------------------------------------
 
+    // check if nis is disabled
+    LdapContext schemaRoot = getSchemaContext( getService() );
+    Attributes nisAttrs = schemaRoot.getAttributes( "cn=nis" );
+    boolean isNisDisabled = false;
 
-    @Test
-    public void testSearchOneLevel() throws Exception
+    if ( nisAttrs.get( "m-disabled" ) != null )
     {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-        controls.setDerefLinkFlag( false );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
-
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", "(ou=*)", controls );
-
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
-
-        assertEquals( "Expected number of results returned was incorrect!", 9, map.size() );
-        assertTrue( map.containsKey( "ou=testing00,ou=system" ) );
-        assertTrue( map.containsKey( "ou=testing01,ou=system" ) );
-        assertTrue( map.containsKey( "ou=testing02,ou=system" ) );
+        isNisDisabled = ( ( String ) nisAttrs.get( "m-disabled" ).get() ).equalsIgnoreCase( "TRUE" );
     }
 
-
-    @Test
-    public void testSearchSubTreeLevel() throws Exception
+    // if nis is disabled then enable it
+    if ( isNisDisabled )
     {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        controls.setDerefLinkFlag( false );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
-
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", "(ou=*)", controls );
-
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
-
-        assertEquals( "Expected number of results returned was incorrect", 14, map.size() );
-        assertTrue( map.containsKey( "ou=system" ) );
-        assertTrue( map.containsKey( "ou=testing00,ou=system" ) );
-        assertTrue( map.containsKey( "ou=testing01,ou=system" ) );
-        assertTrue( map.containsKey( "ou=testing02,ou=system" ) );
-        assertTrue( map.containsKey( "ou=subtest,ou=testing01,ou=system" ) );
+        Attribute disabled = new BasicAttribute( "m-disabled" );
+        ModificationItem[] mods = new ModificationItem[]
+            { new ModificationItem( DirContext.REMOVE_ATTRIBUTE, disabled ) };
+        schemaRoot.modifyAttributes( "cn=nis", mods );
     }
 
+    // -------------------------------------------------------------------
+    // Add a bunch of nis groups
+    // -------------------------------------------------------------------
+    addNisPosixGroup( "testGroup0", 0 );
+    addNisPosixGroup( "testGroup1", 1 );
+    addNisPosixGroup( "testGroup2", 2 );
+    addNisPosixGroup( "testGroup4", 4 );
+    addNisPosixGroup( "testGroup5", 5 );
+}
 
-    @Test
-    public void testSearchSubTreeLevelNoAttributes() throws Exception
-    {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        controls.setDerefLinkFlag( false );
-        controls.setReturningAttributes( new String[]
-            { "1.1" } );
 
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
+/**
+ * Create a NIS group
+ */
+private void addNisPosixGroup( String name, int gid ) throws Exception
+{
+    Entry entry = new DefaultEntry(
+        "cn=" + name + ",ou=groups,ou=system",
+        "objectClass: top",
+        "objectClass: posixGroup",
+        "cn", name,
+        "gidNumber", String.valueOf( gid ) );
 
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", "(ou=testing02)", controls );
+    sysRoot.add( entry );
+}
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
 
-        assertEquals( "Expected number of results returned was incorrect", 1, map.size() );
-        assertTrue( map.containsKey( "ou=testing02,ou=system" ) );
-        Attributes attrs = map.get( "ou=testing02,ou=system" );
-        assertEquals( 0, attrs.size() );
-    }
+@Test
+public void testSearchOneLevel() throws Exception
+{
+    Set<String> set = new HashSet<String>();
 
+    EntryCursor cursor = sysRoot.search( "ou=system", "(ou=*)", SearchScope.ONELEVEL, "*" );
 
-    @Test
-    public void testSearchSubstringSubTreeLevel() throws Exception
+    while ( cursor.next() )
     {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        controls.setDerefLinkFlag( false );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
+        Entry result = cursor.get();
+        set.add( result.getDn().getName() );
+    }
 
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", "(objectClass=organ*)", controls );
+    cursor.close();
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
+    assertEquals( "Expected number of results returned was incorrect!", 9, set.size() );
+    assertTrue( set.contains( "ou=testing00,ou=system" ) );
+    assertTrue( set.contains( "ou=testing01,ou=system" ) );
+    assertTrue( set.contains( "ou=testing02,ou=system" ) );
+}
 
-        // 16 because it also matches organizationalPerson which the admin is
-        assertEquals( "Expected number of results returned was incorrect", 17, map.size() );
-        assertTrue( map.containsKey( "ou=system" ) );
-        assertTrue( map.containsKey( "ou=configuration,ou=system" ) );
-        assertTrue( map.containsKey( "ou=interceptors,ou=configuration,ou=system" ) );
-        assertTrue( map.containsKey( "ou=partitions,ou=configuration,ou=system" ) );
-        assertTrue( map.containsKey( "ou=services,ou=configuration,ou=system" ) );
-        assertTrue( map.containsKey( "ou=groups,ou=system" ) );
-        assertTrue( map.containsKey( "ou=testing00,ou=system" ) );
-        assertTrue( map.containsKey( "ou=testing01,ou=system" ) );
-        assertTrue( map.containsKey( "ou=subtest,ou=testing01,ou=system" ) );
-        assertTrue( map.containsKey( "ou=testing02,ou=system" ) );
-        assertTrue( map.containsKey( "ou=users,ou=system" ) );
-        assertTrue( map.containsKey( "prefNodeName=sysPrefRoot,ou=system" ) );
-        assertTrue( map.containsKey( "uid=admin,ou=system" ) );
-    }
 
+@Test
+public void testSearchSubTreeLevel() throws Exception
+{
+    Set<String> set = new HashSet<String>();
 
-    /**
-     * Tests to make sure undefined attributes in filter assertions are pruned and do not
-     * result in exceptions.
-     */
-    @Test
-    public void testBogusAttributeInSearchFilter() throws Exception
-    {
-        boolean oldSetAllowAnnonymousAccess = getService().isAllowAnonymousAccess();
-        getService().setAllowAnonymousAccess( true );
+    EntryCursor cursor = sysRoot.search( "ou=system", "(ou=*)", SearchScope.SUBTREE, "*" );
 
-        SearchControls cons = new SearchControls();
-        NamingEnumeration<SearchResult> e = sysRoot.search( "", "(bogusAttribute=abc123)", cons );
-        assertNotNull( e );
+    while ( cursor.next() )
+    {
+        Entry result = cursor.get();
+        set.add( result.getDn().getName() );
+    }
 
-        e = sysRoot.search( "", "(!(bogusAttribute=abc123))", cons );
-        assertNotNull( e );
-        assertFalse( e.hasMore() );
+    cursor.close();
 
-        e = sysRoot.search( "", "(|(bogusAttribute=abc123)(bogusAttribute=abc123))", cons );
-        assertNotNull( e );
-        assertFalse( e.hasMore() );
+    assertEquals( "Expected number of results returned was incorrect", 14, set.size() );
+    assertTrue( set.contains( "ou=system" ) );
+    assertTrue( set.contains( "ou=testing00,ou=system" ) );
+    assertTrue( set.contains( "ou=testing01,ou=system" ) );
+    assertTrue( set.contains( "ou=testing02,ou=system" ) );
+    assertTrue( set.contains( "ou=subtest,ou=testing01,ou=system" ) );
+}
 
-        e = sysRoot.search( "", "(|(bogusAttribute=abc123)(ou=abc123))", cons );
-        assertNotNull( e );
-        assertFalse( e.hasMore() );
 
-        e = sysRoot.search( "", "(OBJECTclass=*)", cons );
-        assertNotNull( e );
-        assertTrue( e.hasMore() );
+@Test
+public void testSearchSubTreeLevelNoAttributes() throws Exception
+{
+    Map<String, Entry> map = new HashMap<String, Entry>();
 
-        e = sysRoot.search( "", "(objectclass=*)", cons );
-        assertNotNull( e );
+    EntryCursor cursor = sysRoot.search( "ou=system", "(ou=testing02)", SearchScope.SUBTREE, "1.1" );
 
-        getService().setAllowAnonymousAccess( oldSetAllowAnnonymousAccess );
+    while ( cursor.next() )
+    {
+        Entry result = cursor.get();
+        map.put( result.getDn().getName(), result );
     }
 
+    cursor.close();
 
-    @Test
-    public void testSearchFilterArgs() throws Exception
-    {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-        controls.setDerefLinkFlag( false );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
+    assertEquals( "Expected number of results returned was incorrect", 1, map.size() );
+    assertTrue( map.containsKey( "ou=testing02,ou=system" ) );
+    Entry entry = map.get( "ou=testing02,ou=system" );
+    assertEquals( 0, entry.size() );
+}
 
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", "(|(ou={0})(ou={1}))", new Object[]
-            { "testing00", "testing01" }, controls );
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
+@Test
+public void testSearchSubstringSubTreeLevel() throws Exception
+{
+    Set<String> set = new HashSet<String>();
 
-        assertEquals( "Expected number of results returned was incorrect!", 2, map.size() );
-        assertTrue( map.containsKey( "ou=testing00,ou=system" ) );
-        assertTrue( map.containsKey( "ou=testing01,ou=system" ) );
+    EntryCursor cursor = sysRoot.search( "ou=system", "(objectClass=organ*)", SearchScope.SUBTREE, "*" );
+
+    while ( cursor.next() )
+    {
+        Entry result = cursor.get();
+        set.add( result.getDn().getName() );
     }
 
+    cursor.close();
+
+    // 17 because it also matches organizationalPerson which the admin is
+    assertEquals( "Expected number of results returned was incorrect", 17, set.size() );
+    assertTrue( set.contains( "ou=system" ) );
+    assertTrue( set.contains( "ou=configuration,ou=system" ) );
+    assertTrue( set.contains( "ou=interceptors,ou=configuration,ou=system" ) );
+    assertTrue( set.contains( "ou=partitions,ou=configuration,ou=system" ) );
+    assertTrue( set.contains( "ou=services,ou=configuration,ou=system" ) );
+    assertTrue( set.contains( "ou=groups,ou=system" ) );
+    assertTrue( set.contains( "ou=testing00,ou=system" ) );
+    assertTrue( set.contains( "ou=testing01,ou=system" ) );
+    assertTrue( set.contains( "ou=subtest,ou=testing01,ou=system" ) );
+    assertTrue( set.contains( "ou=testing02,ou=system" ) );
+    assertTrue( set.contains( "ou=users,ou=system" ) );
+    assertTrue( set.contains( "prefNodeName=sysPrefRoot,ou=system" ) );
+    assertTrue( set.contains( "uid=admin,ou=system" ) );
+}
 
-    @Test
-    public void testFilterExpansion0() throws Exception
-    {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        controls.setDerefLinkFlag( false );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
 
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", "(name=testing00)", controls );
+/**
+ * Tests to make sure undefined attributes in filter assertions are pruned and do not
+ * result in exceptions.
+ */
+@Test
+public void testBogusAttributeInSearchFilter() throws Exception
+{
+    boolean oldSetAllowAnnonymousAccess = getService().isAllowAnonymousAccess();
+    getService().setAllowAnonymousAccess( true );
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
+    EntryCursor cursor = sysRoot.search( "ou=system", "(bogusAttribute=abc123)", SearchScope.SUBTREE, "*" );
 
-        assertEquals( "size of results", 1, map.size() );
-        assertTrue( "contains ou=testing00,ou=system", map.containsKey( "ou=testing00,ou=system" ) );
-    }
+    assertNotNull( cursor );
+    cursor.close();
 
+    cursor = sysRoot.search( "ou=system", "(!(bogusAttribute=abc123))", SearchScope.SUBTREE, "*" );
+    assertNotNull( cursor );
+    assertFalse( cursor.next() );
+    cursor.close();
+
+    cursor = sysRoot
+        .search( "ou=system", "(|(bogusAttribute=abc123)(bogusAttribute=abc123))", SearchScope.SUBTREE, "*" );
+    assertNotNull( cursor );
+    assertFalse( cursor.next() );
+    cursor.close();
+
+    cursor = sysRoot.search( "ou=system", "(|(bogusAttribute=abc123)(ou=abc123))", SearchScope.SUBTREE, "*" );
+    assertNotNull( cursor );
+    assertFalse( cursor.next() );
+    cursor.close();
+
+    cursor = sysRoot.search( "ou=system", "(OBJECTclass=*)", SearchScope.SUBTREE, "*" );
+    assertNotNull( cursor );
+    assertTrue( cursor.next() );
+    cursor.close();
+
+    cursor = sysRoot.search( "ou=system", "(objectclass=*)", SearchScope.SUBTREE, "*" );
+    assertNotNull( cursor );
+    cursor.close();
 
-    @Test
-    public void testFilterExpansion1() throws Exception
-    {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        controls.setDerefLinkFlag( false );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
+    getService().setAllowAnonymousAccess( oldSetAllowAnnonymousAccess );
+}
 
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", "(name=*)", controls );
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
+@Test
+public void testSearchFilterArgs() throws Exception
+{
+    Set<String> set = new HashSet<String>();
+
+    EntryCursor cursor = sysRoot.search( "ou=system", "(|(ou=testing00)(ou=testing01))", SearchScope.ONELEVEL, "*" );
 
-        assertEquals( "size of results", 23, map.size() );
-        assertTrue( "contains ou=testing00,ou=system", map.containsKey( "ou=testing00,ou=system" ) );
-        assertTrue( "contains ou=testing01,ou=system", map.containsKey( "ou=testing01,ou=system" ) );
-        assertTrue( "contains ou=testing02,ou=system", map.containsKey( "ou=testing01,ou=system" ) );
-        assertTrue( "contains ou=configuration,ou=system", map.containsKey( "ou=configuration,ou=system" ) );
-        assertTrue( "contains ou=groups,ou=system", map.containsKey( "ou=groups,ou=system" ) );
-        assertTrue( "contains ou=interceptors,ou=configuration,ou=system", map
-            .containsKey( "ou=interceptors,ou=configuration,ou=system" ) );
-        assertTrue( "contains ou=partitions,ou=configuration,ou=system", map
-            .containsKey( "ou=partitions,ou=configuration,ou=system" ) );
-        assertTrue( "contains ou=services,ou=configuration,ou=system", map
-            .containsKey( "ou=services,ou=configuration,ou=system" ) );
-        assertTrue( "contains ou=subtest,ou=testing01,ou=system", map.containsKey( "ou=subtest,ou=testing01,ou=system" ) );
-        assertTrue( "contains ou=system", map.containsKey( "ou=system" ) );
-        assertTrue( "contains ou=users,ou=system", map.containsKey( "ou=users,ou=system" ) );
-        assertTrue( "contains uid=admin,ou=system", map.containsKey( "uid=admin,ou=system" ) );
-        assertTrue( "contains cn=administrators,ou=groups,ou=system", map
-            .containsKey( "cn=Administrators,ou=groups,ou=system" ) );
+    while ( cursor.next() )
+    {
+        Entry result = cursor.get();
+        set.add( result.getDn().getName() );
     }
 
+    cursor.close();
 
-    @Test
-    public void testFilterExpansion2() throws Exception
-    {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        controls.setDerefLinkFlag( false );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
+    assertEquals( "Expected number of results returned was incorrect!", 2, set.size() );
+    assertTrue( set.contains( "ou=testing00,ou=system" ) );
+    assertTrue( set.contains( "ou=testing01,ou=system" ) );
+}
 
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", "(|(name=testing00)(name=testing01))", controls );
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
+@Test
+public void testFilterExpansion0() throws Exception
+{
+    Map<String, Entry> map = new HashMap<String, Entry>();
+    EntryCursor cursor = sysRoot.search( "ou=system", "(name=testing00)", SearchScope.SUBTREE, "*" );
 
-        assertEquals( "size of results", 2, map.size() );
-        assertTrue( "contains ou=testing00,ou=system", map.containsKey( "ou=testing00,ou=system" ) );
-        assertTrue( "contains ou=testing01,ou=system", map.containsKey( "ou=testing01,ou=system" ) );
+    while ( cursor.next() )
+    {
+        Entry result = cursor.get();
+        map.put( result.getDn().getName(), result );
     }
 
+    cursor.close();
 
-    @Test
-    public void testFilterExpansion4() throws Exception
-    {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        controls.setDerefLinkFlag( false );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
+    assertEquals( "size of results", 1, map.size() );
+    assertTrue( "contains ou=testing00,ou=system", map.containsKey( "ou=testing00,ou=system" ) );
+}
 
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", "(name=testing*)", controls );
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
+@Test
+public void testFilterExpansion1() throws Exception
+{
+    Map<String, Entry> map = new HashMap<String, Entry>();
+    EntryCursor cursor = sysRoot.search( "ou=system", "(name=*)", SearchScope.SUBTREE, "*" );
 
-        assertEquals( "size of results", 6, map.size() );
-        assertTrue( "contains ou=testing00,ou=system", map.containsKey( "ou=testing00,ou=system" ) );
-        assertTrue( "contains ou=testing01,ou=system", map.containsKey( "ou=testing01,ou=system" ) );
-        assertTrue( "contains ou=testing02,ou=system", map.containsKey( "ou=testing02,ou=system" ) );
-        assertTrue( "contains ou=testing03,ou=system", map.containsKey( "ou=testing03,ou=system" ) );
-        assertTrue( "contains ou=testing04,ou=system", map.containsKey( "ou=testing04,ou=system" ) );
-        assertTrue( "contains ou=testing05,ou=system", map.containsKey( "ou=testing05,ou=system" ) );
+    while ( cursor.next() )
+    {
+        Entry result = cursor.get();
+        map.put( result.getDn().getName(), result );
     }
 
+    cursor.close();
+
+    assertEquals( "size of results", 23, map.size() );
+    assertTrue( "contains ou=testing00,ou=system", map.containsKey( "ou=testing00,ou=system" ) );
+    assertTrue( "contains ou=testing01,ou=system", map.containsKey( "ou=testing01,ou=system" ) );
+    assertTrue( "contains ou=testing02,ou=system", map.containsKey( "ou=testing01,ou=system" ) );
+    assertTrue( "contains ou=configuration,ou=system", map.containsKey( "ou=configuration,ou=system" ) );
+    assertTrue( "contains ou=groups,ou=system", map.containsKey( "ou=groups,ou=system" ) );
+    assertTrue( "contains ou=interceptors,ou=configuration,ou=system", map
+        .containsKey( "ou=interceptors,ou=configuration,ou=system" ) );
+    assertTrue( "contains ou=partitions,ou=configuration,ou=system", map
+        .containsKey( "ou=partitions,ou=configuration,ou=system" ) );
+    assertTrue( "contains ou=services,ou=configuration,ou=system", map
+        .containsKey( "ou=services,ou=configuration,ou=system" ) );
+    assertTrue( "contains ou=subtest,ou=testing01,ou=system", map.containsKey( "ou=subtest,ou=testing01,ou=system" ) );
+    assertTrue( "contains ou=system", map.containsKey( "ou=system" ) );
+    assertTrue( "contains ou=users,ou=system", map.containsKey( "ou=users,ou=system" ) );
+    assertTrue( "contains uid=admin,ou=system", map.containsKey( "uid=admin,ou=system" ) );
+    assertTrue( "contains cn=administrators,ou=groups,ou=system", map
+        .containsKey( "cn=Administrators,ou=groups,ou=system" ) );
+}
 
-    @Test
-    public void testFilterExpansion5() throws Exception
-    {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        controls.setDerefLinkFlag( false );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
-
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
-        String filter = "(|(2.5.4.11.1=testing*)(2.5.4.54=testing*)(2.5.4.10=testing*)"
-            + "(2.5.4.6=testing*)(2.5.4.43=testing*)(2.5.4.7.1=testing*)(2.5.4.10.1=testing*)"
-            + "(2.5.4.44=testing*)(2.5.4.11=testing*)(2.5.4.4=testing*)(2.5.4.8.1=testing*)"
-            + "(2.5.4.12=testing*)(1.3.6.1.4.1.18060.0.4.1.2.3=testing*)"
-            + "(2.5.4.7=testing*)(2.5.4.3=testing*)(2.5.4.8=testing*)(2.5.4.42=testing*))";
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", filter, controls );
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
+@Test
+public void testFilterExpansion2() throws Exception
+{
+    Map<String, Entry> map = new HashMap<String, Entry>();
+    EntryCursor cursor = sysRoot.search( "ou=system", "(|(name=testing00)(name=testing01))", SearchScope.SUBTREE, "*" );
 
-        assertEquals( "size of results", 6, map.size() );
-        assertTrue( "contains ou=testing00,ou=system", map.containsKey( "ou=testing00,ou=system" ) );
-        assertTrue( "contains ou=testing01,ou=system", map.containsKey( "ou=testing01,ou=system" ) );
-        assertTrue( "contains ou=testing02,ou=system", map.containsKey( "ou=testing02,ou=system" ) );
-        assertTrue( "contains ou=testing03,ou=system", map.containsKey( "ou=testing03,ou=system" ) );
-        assertTrue( "contains ou=testing04,ou=system", map.containsKey( "ou=testing04,ou=system" ) );
-        assertTrue( "contains ou=testing05,ou=system", map.containsKey( "ou=testing05,ou=system" ) );
+    while ( cursor.next() )
+    {
+        Entry result = cursor.get();
+        map.put( result.getDn().getName(), result );
     }
 
+    cursor.close();
 
-    @Test
-    public void testOpAttrDenormalizationOff() throws Exception
-    {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-        controls.setDerefLinkFlag( false );
-        controls.setReturningAttributes( new String[]
-            { "creatorsName" } );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
+    assertEquals( "size of results", 2, map.size() );
+    assertTrue( "contains ou=testing00,ou=system", map.containsKey( "ou=testing00,ou=system" ) );
+    assertTrue( "contains ou=testing01,ou=system", map.containsKey( "ou=testing01,ou=system" ) );
+}
 
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", "(ou=testing00)", controls );
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
+@Test
+public void testFilterExpansion4() throws Exception
+{
+    Map<String, Entry> map = new HashMap<String, Entry>();
+    EntryCursor cursor = sysRoot.search( "ou=system", "(name=testing*)", SearchScope.SUBTREE, "*" );
 
-        assertEquals( "Expected number of results returned was incorrect!", 1, map.size() );
-        assertTrue( map.containsKey( "ou=testing00,ou=system" ) );
-        Attributes attrs = map.get( "ou=testing00,ou=system" );
-        assertEquals( "normalized creator's name", "0.9.2342.19200300.100.1.1=admin,2.5.4.11=system", attrs.get(
-            "creatorsName" ).get() );
+    while ( cursor.next() )
+    {
+        Entry result = cursor.get();
+        map.put( result.getDn().getName(), result );
     }
 
+    cursor.close();
 
-    @Test
-    public void testOpAttrDenormalizationOn() throws Exception
-    {
-        getService().setDenormalizeOpAttrsEnabled( true );
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-        controls.setDerefLinkFlag( false );
-        controls.setReturningAttributes( new String[]
-            { "creatorsName" } );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
+    assertEquals( "size of results", 6, map.size() );
+    assertTrue( "contains ou=testing00,ou=system", map.containsKey( "ou=testing00,ou=system" ) );
+    assertTrue( "contains ou=testing01,ou=system", map.containsKey( "ou=testing01,ou=system" ) );
+    assertTrue( "contains ou=testing02,ou=system", map.containsKey( "ou=testing02,ou=system" ) );
+    assertTrue( "contains ou=testing03,ou=system", map.containsKey( "ou=testing03,ou=system" ) );
+    assertTrue( "contains ou=testing04,ou=system", map.containsKey( "ou=testing04,ou=system" ) );
+    assertTrue( "contains ou=testing05,ou=system", map.containsKey( "ou=testing05,ou=system" ) );
+}
 
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", "(ou=testing00)", controls );
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
+@Test
+public void testFilterExpansion5() throws Exception
+{
+    String filter = "(|(2.5.4.11.1=testing*)(2.5.4.54=testing*)(2.5.4.10=testing*)"
+        + "(2.5.4.6=testing*)(2.5.4.43=testing*)(2.5.4.7.1=testing*)(2.5.4.10.1=testing*)"
+        + "(2.5.4.44=testing*)(2.5.4.11=testing*)(2.5.4.4=testing*)(2.5.4.8.1=testing*)"
+        + "(2.5.4.12=testing*)(1.3.6.1.4.1.18060.0.4.1.2.3=testing*)"
+        + "(2.5.4.7=testing*)(2.5.4.3=testing*)(2.5.4.8=testing*)(2.5.4.42=testing*))";
+
+    Map<String, Entry> map = new HashMap<String, Entry>();
+    EntryCursor cursor = sysRoot.search( "ou=system", filter, SearchScope.SUBTREE, "*" );
+
+    while ( cursor.next() )
+    {
+        Entry result = cursor.get();
+        map.put( result.getDn().getName(), result );
+    }
+
+    cursor.close();
+
+    assertEquals( "size of results", 6, map.size() );
+    assertTrue( "contains ou=testing00,ou=system", map.containsKey( "ou=testing00,ou=system" ) );
+    assertTrue( "contains ou=testing01,ou=system", map.containsKey( "ou=testing01,ou=system" ) );
+    assertTrue( "contains ou=testing02,ou=system", map.containsKey( "ou=testing02,ou=system" ) );
+    assertTrue( "contains ou=testing03,ou=system", map.containsKey( "ou=testing03,ou=system" ) );
+    assertTrue( "contains ou=testing04,ou=system", map.containsKey( "ou=testing04,ou=system" ) );
+    assertTrue( "contains ou=testing05,ou=system", map.containsKey( "ou=testing05,ou=system" ) );
+}
 
-        assertEquals( "Expected number of results returned was incorrect!", 1, map.size() );
-        assertTrue( map.containsKey( "ou=testing00,ou=system" ) );
-        Attributes attrs = map.get( "ou=testing00,ou=system" );
-        assertEquals( "normalized creator's name", "uid=admin,ou=system", attrs.get( "creatorsName" ).get() );
-    }
 
+@Test
+public void testOpAttrDenormalizationOff() throws Exception
+{
+    Map<String, Entry> map = new HashMap<String, Entry>();
+    EntryCursor cursor = sysRoot.search( "ou=system", "(ou=testing00)", SearchScope.ONELEVEL, "creatorsName" );
 
-    /**
-     * Creation of required attributes of a person entry.
-     *
-     * @param cn the commonName of the person
-     * @param sn the surName of the person
-     * @return the attributes of a new person entry
-     */
-    protected Attributes getPersonAttributes( String sn, String cn ) throws LdapException
+    while ( cursor.next() )
     {
-        Attributes attributes = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: top",
-            "objectClass: person", "cn", cn, "sn", sn );
-
-        return attributes;
+        Entry result = cursor.get();
+        map.put( result.getDn().getName(), result );
     }
 
+    cursor.close();
 
-    @Test
-    public void testBinaryAttributesInFilter() throws Exception
-    {
-        byte[] certData = new byte[]
-            { 0x34, 0x56, 0x4e, 0x5f };
-
-        // First let's add a some binary data representing a userCertificate
-        Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" );
-        attrs.put( "userCertificate", certData );
+    assertEquals( "Expected number of results returned was incorrect!", 1, map.size() );
+    assertTrue( map.containsKey( "ou=testing00,ou=system" ) );
+    Entry entry = map.get( "ou=testing00,ou=system" );
+    assertEquals( "normalized creator's name", "0.9.2342.19200300.100.1.1=admin,2.5.4.11=system", entry.get(
+        "creatorsName" ).getString() );
+}
 
-        Attribute objectClasses = attrs.get( "objectClass" );
-        objectClasses.add( "strongAuthenticationUser" );
 
-        sysRoot.createSubcontext( "cn=Kate Bush", attrs );
+@Test
+public void testOpAttrDenormalizationOn() throws Exception
+{
+    getService().setDenormalizeOpAttrsEnabled( true );
 
-        // Search for kate by cn first
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-        NamingEnumeration<SearchResult> enm = sysRoot.search( "", "(cn=Kate Bush)", controls );
-        assertTrue( enm.hasMore() );
-        SearchResult sr = enm.next();
-        assertNotNull( sr );
-        assertFalse( enm.hasMore() );
-        assertEquals( "cn=Kate Bush,ou=system", sr.getName() );
+    Map<String, Entry> map = new HashMap<String, Entry>();
+    EntryCursor cursor = sysRoot.search( "ou=system", "(ou=testing00)", SearchScope.ONELEVEL, "creatorsName" );
 
-        enm = sysRoot.search( "", "(userCertificate=\\34\\56\\4E\\5F)", controls );
-        assertTrue( enm.hasMore() );
-        sr = enm.next();
-        assertNotNull( sr );
-        assertFalse( enm.hasMore() );
-        assertEquals( "cn=Kate Bush,ou=system", sr.getName() );
+    while ( cursor.next() )
+    {
+        Entry result = cursor.get();
+        map.put( result.getDn().getName(), result );
     }
 
+    cursor.close();
 
-    @Test
-    public void testSearchOperationalAttr() throws Exception
-    {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-        controls.setDerefLinkFlag( false );
-        controls.setReturningAttributes( new String[]
-            { "+" } );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
+    assertEquals( "Expected number of results returned was incorrect!", 1, map.size() );
+    assertTrue( map.containsKey( "ou=testing00,ou=system" ) );
+    Entry entry = map.get( "ou=testing00,ou=system" );
+    assertEquals( "normalized creator's name", "uid=admin,ou=system", entry.get( "creatorsName" ).getString() );
+}
 
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", "(ou=testing01)", controls );
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
+/**
+ * Creation of required attributes of a person entry.
+ *
+ * @param cn the commonName of the person
+ * @param sn the surName of the person
+ * @return the attributes of a new person entry
+ */
+protected Entry getPersonEntry( String dn, String sn, String cn ) throws LdapException
+{
+    Entry entry = new DefaultEntry(
+        dn,
+        "objectClass: top",
+        "objectClass: person",
+        "cn", cn,
+        "sn", sn );
 
-        assertEquals( "Expected number of results returned was incorrect!", 1, map.size() );
+    return entry;
+}
 
-        Attributes attrs = map.get( "ou=testing01,ou=system" );
 
-        assertNotNull( attrs.get( "createTimestamp" ) );
-        assertNotNull( attrs.get( "creatorsName" ) );
-        assertNull( attrs.get( "objectClass" ) );
-        assertNull( attrs.get( "ou" ) );
-    }
+@Test
+public void testBinaryAttributesInFilter() throws Exception
+{
+    byte[] certData = new byte[]
+        { 0x34, 0x56, 0x4e, 0x5f };
+
+    // First let's add a some binary data representing a userCertificate
+    Entry entry = getPersonEntry( "cn=Kate Bush,ou=system", "Bush", "Kate Bush" );
+    entry.put( "userCertificate", certData );
+    entry.add( "objectClass", "strongAuthenticationUser" );
+
+    sysRoot.add( entry );
+
+    // Search for kate by cn first
+    EntryCursor cursor = sysRoot.search( "ou=system", "(cn=Kate Bush)", SearchScope.ONELEVEL, "*" );
+    assertTrue( cursor.next() );
+    entry = cursor.get();
+    assertNotNull( entry );
+    assertFalse( cursor.next() );
+    assertEquals( "cn=Kate Bush,ou=system", entry.getDn().getName() );
+
+    cursor.close();
+
+    cursor = sysRoot.search( "ou=system", "(userCertificate=\\34\\56\\4E\\5F)", SearchScope.ONELEVEL, "*" );
+    assertTrue( cursor.next() );
+    entry = cursor.get();
+    assertNotNull( entry );
+    assertFalse( cursor.next() );
+    assertEquals( "cn=Kate Bush,ou=system", entry.getDn().getName() );
 
+    cursor.close();
+}
+
+
+@Test
+public void testSearchOperationalAttr() throws Exception
+{
+    Map<String, Entry> map = new HashMap<String, Entry>();
+    EntryCursor cursor = sysRoot.search( "ou=system", "(ou=testing01)", SearchScope.ONELEVEL, "+" );
 
-    @Test
-    public void testSearchUserAttr() throws Exception
+    while ( cursor.next() )
     {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-        controls.setDerefLinkFlag( false );
-        controls.setReturningAttributes( new String[]
-            { "*" } );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
+        Entry result = cursor.get();
+        map.put( result.getDn().getName(), result );
+    }
 
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", "(ou=testing01)", controls );
+    cursor.close();
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
+    assertEquals( "Expected number of results returned was incorrect!", 1, map.size() );
 
-        assertEquals( "Expected number of results returned was incorrect!", 1, map.size() );
+    Entry entry = map.get( "ou=testing01,ou=system" );
 
-        Attributes attrs = map.get( "ou=testing01,ou=system" );
+    assertNotNull( entry.get( "createTimestamp" ) );
+    assertNotNull( entry.get( "creatorsName" ) );
+    assertNull( entry.get( "objectClass" ) );
+    assertNull( entry.get( "ou" ) );
+}
 
-        assertNotNull( attrs.get( "objectClass" ) );
-        assertNotNull( attrs.get( "ou" ) );
-        assertNull( attrs.get( "createTimestamp" ) );
-        assertNull( attrs.get( "creatorsName" ) );
-    }
 
+@Test
+public void testSearchUserAttr() throws Exception
+{
+    Map<String, Entry> map = new HashMap<String, Entry>();
+    EntryCursor cursor = sysRoot.search( "ou=system", "(ou=testing01)", SearchScope.ONELEVEL, "*" );
 
-    @Test
-    public void testSearchUserAttrAndOpAttr() throws Exception
+    while ( cursor.next() )
     {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-        controls.setDerefLinkFlag( false );
-        controls.setReturningAttributes( new String[]
-            { "*", "creatorsName" } );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
+        Entry result = cursor.get();
+        map.put( result.getDn().getName(), result );
+    }
 
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", "(ou=testing01)", controls );
+    cursor.close();
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
+    assertEquals( "Expected number of results returned was incorrect!", 1, map.size() );
 
-        assertEquals( "Expected number of results returned was incorrect!", 1, map.size() );
+    Entry entry = map.get( "ou=testing01,ou=system" );
 
-        Attributes attrs = map.get( "ou=testing01,ou=system" );
+    assertNotNull( entry.get( "objectClass" ) );
+    assertNotNull( entry.get( "ou" ) );
+    assertNull( entry.get( "createTimestamp" ) );
+    assertNull( entry.get( "creatorsName" ) );
+}
 
-        assertNotNull( attrs.get( "objectClass" ) );
-        assertNotNull( attrs.get( "ou" ) );
-        assertNotNull( attrs.get( "creatorsName" ) );
-        assertNull( attrs.get( "createTimestamp" ) );
-    }
 
+@Test
+public void testSearchUserAttrAndOpAttr() throws Exception
+{
+    Map<String, Entry> map = new HashMap<String, Entry>();
+    EntryCursor cursor = sysRoot.search( "ou=system", "(ou=testing01)", SearchScope.ONELEVEL, "*", "creatorsName" );
 
-    @Test
-    public void testSearchUserAttrAndNoAttr() throws Exception
+    while ( cursor.next() )
     {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-        controls.setDerefLinkFlag( false );
-        controls.setReturningAttributes( new String[]
-            { "1.1", "ou" } );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
+        Entry result = cursor.get();
+        map.put( result.getDn().getName(), result );
+    }
 
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", "(ou=testing01)", controls );
+    cursor.close();
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
+    assertEquals( "Expected number of results returned was incorrect!", 1, map.size() );
 
-        assertEquals( "Expected number of results returned was incorrect!", 1, map.size() );
+    Entry entry = map.get( "ou=testing01,ou=system" );
 
-        Attributes attrs = map.get( "ou=testing01,ou=system" );
+    assertNotNull( entry.get( "objectClass" ) );
+    assertNotNull( entry.get( "ou" ) );
+    assertNotNull( entry.get( "creatorsName" ) );
+    assertNull( entry.get( "createTimestamp" ) );
+}
 
-        assertNull( attrs.get( "objectClass" ) );
-        assertNotNull( attrs.get( "ou" ) );
-        assertNull( attrs.get( "creatorsName" ) );
-        assertNull( attrs.get( "createTimestamp" ) );
-    }
 
+@Test
+public void testSearchUserAttrAndNoAttr() throws Exception
+{
+    Map<String, Entry> map = new HashMap<String, Entry>();
+    EntryCursor cursor = sysRoot.search( "ou=system", "(ou=testing01)", SearchScope.ONELEVEL, "1.1", "ou" );
 
-    @Test
-    public void testSearchNoAttr() throws Exception
+    while ( cursor.next() )
     {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-        controls.setDerefLinkFlag( false );
-        controls.setReturningAttributes( new String[]
-            { "1.1" } );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
+        Entry result = cursor.get();
+        map.put( result.getDn().getName(), result );
+    }
 
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", "(ou=testing01)", controls );
+    cursor.close();
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
+    assertEquals( "Expected number of results returned was incorrect!", 1, map.size() );
 
-        assertEquals( "Expected number of results returned was incorrect!", 1, map.size() );
+    Entry entry = map.get( "ou=testing01,ou=system" );
 
-        Attributes attrs = map.get( "ou=testing01,ou=system" );
+    assertNull( entry.get( "objectClass" ) );
+    assertNotNull( entry.get( "ou" ) );
+    assertNull( entry.get( "creatorsName" ) );
+    assertNull( entry.get( "createTimestamp" ) );
+}
 
-        assertNull( attrs.get( "objectClass" ) );
-        assertNull( attrs.get( "ou" ) );
-        assertNull( attrs.get( "creatorsName" ) );
-        assertNull( attrs.get( "createTimestamp" ) );
-    }
 
+@Test
+public void testSearchNoAttr() throws Exception
+{
+    Map<String, Entry> map = new HashMap<String, Entry>();
+    EntryCursor cursor = sysRoot.search( "ou=system", "(ou=testing01)", SearchScope.ONELEVEL, "1.1" );
 
-    @Test
-    public void testSearchAllAttr() throws Exception
+    while ( cursor.next() )
     {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
-        controls.setDerefLinkFlag( false );
-        controls.setReturningAttributes( new String[]
-            { "+", "*" } );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
+        Entry result = cursor.get();
+        map.put( result.getDn().getName(), result );
+    }
 
-        NamingEnumeration<SearchResult> list = sysRoot.search( "", "(ou=testing01)", controls );
+    cursor.close();
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
+    assertEquals( "Expected number of results returned was incorrect!", 1, map.size() );
 
-        assertEquals( "Expected number of results returned was incorrect!", 1, map.size() );
+    Entry entry = map.get( "ou=testing01,ou=system" );
 
-        Attributes attrs = map.get( "ou=testing01,ou=system" );
+    assertNull( entry.get( "objectClass" ) );
+    assertNull( entry.get( "ou" ) );
+    assertNull( entry.get( "creatorsName" ) );
+    assertNull( entry.get( "createTimestamp" ) );
+}
 
-        assertNotNull( attrs.get( "createTimestamp" ) );
-        assertNotNull( attrs.get( "creatorsName" ) );
-        assertNotNull( attrs.get( "objectClass" ) );
-        assertNotNull( attrs.get( "ou" ) );
-    }
 
+@Test
+public void testSearchAllAttr() throws Exception
+{
+    Map<String, Entry> map = new HashMap<String, Entry>();
+    EntryCursor cursor = sysRoot.search( "ou=system", "(ou=testing01)", SearchScope.ONELEVEL, "+", "*" );
 
-    /**
-     * Search an entry and fetch an attribute with unknown option
-     * @throws NamingException if there are errors
-     */
-    @Test
-    public void testSearchFetchNonExistingAttributeOption() throws Exception
+    while ( cursor.next() )
     {
-        SearchControls ctls = new SearchControls();
-        ctls.setSearchScope( SearchControls.OBJECT_SCOPE );
-        ctls.setReturningAttributes( new String[]
-            { "cn", "sn;unknownOption", "badAttr" } );
+        Entry result = cursor.get();
+        map.put( result.getDn().getName(), result );
+    }
 
-        NamingEnumeration<SearchResult> result = sysRoot.search( RDN, FILTER, ctls );
+    cursor.close();
 
-        if ( result.hasMore() )
-        {
-            SearchResult entry = result.next();
-            Attributes attrs = entry.getAttributes();
-            Attribute cn = attrs.get( "cn" );
+    assertEquals( "Expected number of results returned was incorrect!", 1, map.size() );
 
-            assertNotNull( cn );
-            assertEquals( "Heather Nova", cn.get().toString() );
+    Entry entry = map.get( "ou=testing01,ou=system" );
 
-            Attribute sn = attrs.get( "sn" );
-            assertNull( sn );
-        }
-        else
-        {
-            fail( "entry " + RDN + " not found" );
-        }
+    assertNotNull( entry.get( "createTimestamp" ) );
+    assertNotNull( entry.get( "creatorsName" ) );
+    assertNotNull( entry.get( "objectClass" ) );
+    assertNotNull( entry.get( "ou" ) );
+}
 
-        result.close();
-    }
 
+/**
+ * Search an entry and fetch an attribute with unknown option
+ * @throws NamingException if there are errors
+ */
+@Test
+public void testSearchFetchNonExistingAttributeOption() throws Exception
+{
+    EntryCursor cursor = sysRoot.search( RDN, FILTER, SearchScope.OBJECT, "cn", "sn;unknownOption", "badAttr" );
 
-    /**
-     * Search an entry and fetch an attribute and all its subtypes
-     * @throws NamingException if there are errors
-     */
-    @Test
-    public void testSearchFetchAttributeAndSubTypes() throws Exception
+    if ( cursor.next() )
     {
-        SearchControls ctls = new SearchControls();
-        ctls.setSearchScope( SearchControls.OBJECT_SCOPE );
-        ctls.setReturningAttributes( new String[]
-            { "name" } );
+        Entry entry = cursor.get();
 
-        NamingEnumeration<SearchResult> result = sysRoot.search( RDN, FILTER, ctls );
+        assertTrue( entry.contains( "cn", "Heather Nova" ) );
+        assertFalse( entry.containsAttribute( "sn" ) );
+    }
+    else
+    {
+        fail( "entry " + RDN + " not found" );
+    }
 
-        if ( result.hasMore() )
-        {
-            SearchResult entry = result.next();
-            Attributes attrs = entry.getAttributes();
+    cursor.close();
+}
 
-            // We should have get cn and sn only
-            assertEquals( 2, attrs.size() );
 
-            // Check CN
-            Attribute cn = attrs.get( "cn" );
+/**
+ * Search an entry and fetch an attribute and all its subtypes
+ * @throws NamingException if there are errors
+ */
+@Test
+public void testSearchFetchAttributeAndSubTypes() throws Exception
+{
+    EntryCursor cursor = sysRoot.search( RDN, FILTER, SearchScope.OBJECT, "name" );
 
-            assertNotNull( cn );
-            assertEquals( "Heather Nova", cn.get().toString() );
-
-            // Assert SN
-            Attribute sn = attrs.get( "sn" );
-            assertNotNull( sn );
-            assertEquals( "Nova", sn.get().toString() );
-        }
-        else
-        {
-            fail( "entry " + RDN + " not found" );
-        }
+    if ( cursor.next() )
+    {
+        Entry entry = cursor.get();
 
-        result.close();
-    }
+        // We should have get cn and sn only
+        assertEquals( 2, entry.size() );
 
+        // Check CN
+        assertTrue( entry.contains( "cn", "Heather Nova" ) );
 
-    /**
-     * Search an entry and fetch an attribute with twice the same attributeType
-     * @throws NamingException if there are errors
-     */
-    @Test
-    public void testSearchFetchTwiceSameAttribute() throws Exception
+        // Assert SN
+        assertTrue( entry.contains( "sn", "Nova" ) );
+    }
+    else
     {
-        SearchControls ctls = new SearchControls();
-        ctls.setSearchScope( SearchControls.OBJECT_SCOPE );
-        ctls.setReturningAttributes( new String[]
-            { "cn", "cn" } );
+        fail( "entry " + RDN + " not found" );
+    }
 
-        NamingEnumeration<SearchResult> result = sysRoot.search( RDN, FILTER, ctls );
+    cursor.close();
+}
 
-        if ( result.hasMore() )
-        {
-            SearchResult entry = result.next();
-            Attributes attrs = entry.getAttributes();
-            Attribute cn = attrs.get( "cn" );
 
-            assertNotNull( cn );
-            assertEquals( "Heather Nova", cn.get().toString() );
-        }
-        else
-        {
-            fail( "entry " + RDN + " not found" );
-        }
+/**
+ * Search an entry and fetch an attribute with twice the same attributeType
+ * @throws NamingException if there are errors
+ */
+@Test
+public void testSearchFetchTwiceSameAttribute() throws Exception
+{
+    EntryCursor cursor = sysRoot.search( RDN, FILTER, SearchScope.OBJECT, "cn", "cn" );
 
-        result.close();
+    if ( cursor.next() )
+    {
+        Entry entry = cursor.get();
+        assertTrue( entry.contains( "cn", "Heather Nova" ) );
+    }
+    else
+    {
+        fail( "entry " + RDN + " not found" );
     }
 
+    cursor.close();
+}
+
 
-    // this one is failing because it returns the admin user twice: count = 15
-    //    public void testFilterExpansion3() throws Exception
-    //    {
-    //        SearchControls controls = new SearchControls();
-    //        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-    //        controls.setDerefLinkFlag( false );
-    //        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES );
-    //
-    //        List map = new ArrayList();
-    //        NamingEnumeration list = sysRoot.search( "", "(name=*)", controls );
-    //        while ( list.hasMore() )
-    //        {
-    //            SearchResult result = ( SearchResult ) list.next();
-    //            map.add( result.getName() );
-    //        }
-    //        assertEquals( "size of results", 14, map.size() );
-    //        assertTrue( "contains ou=testing00,ou=system", map.contains( "ou=testing00,ou=system" ) );
-    //        assertTrue( "contains ou=testing01,ou=system", map.contains( "ou=testing01,ou=system" ) );
-    //        assertTrue( "contains ou=testing02,ou=system", map.contains( "ou=testing01,ou=system" ) );
-    //        assertTrue( "contains uid=akarasulu,ou=users,ou=system", map.contains( "uid=akarasulu,ou=users,ou=system" ) );
-    //        assertTrue( "contains ou=configuration,ou=system", map.contains( "ou=configuration,ou=system" ) );
-    //        assertTrue( "contains ou=groups,ou=system", map.contains( "ou=groups,ou=system" ) );
-    //        assertTrue( "contains ou=interceptors,ou=configuration,ou=system", map.contains( "ou=interceptors,ou=configuration,ou=system" ) );
-    //        assertTrue( "contains ou=partitions,ou=configuration,ou=system", map.contains( "ou=partitions,ou=configuration,ou=system" ) );
-    //        assertTrue( "contains ou=services,ou=configuration,ou=system", map.contains( "ou=services,ou=configuration,ou=system" ) );
-    //        assertTrue( "contains ou=subtest,ou=testing01,ou=system", map.contains( "ou=subtest,ou=testing01,ou=system" ) );
-    //        assertTrue( "contains ou=system", map.contains( "ou=system" ) );
-    //        assertTrue( "contains ou=users,ou=system", map.contains( "ou=users,ou=system" ) );
-    //        assertTrue( "contains uid=admin,ou=system", map.contains( "uid=admin,ou=system" ) );
-    //        assertTrue( "contains cn=administrators,ou=groups,ou=system", map.contains( "cn=administrators,ou=groups,ou=system" ) );
-    //    }
-
-    /**
-     *  Convenience method that performs a one level search using the
-     *  specified filter returning their DNs as Strings in a set.
-     *
-     * @param controls the search controls
-     * @param filter the filter expression
-     * @return the set of groups
-     * @throws NamingException if there are problems conducting the search
-     */
-    public Set<String> searchGroups( String filter, SearchControls controls ) throws Exception
+// this one is failing because it returns the admin user twice: count = 15
+@Test
+public void testFilterExpansion3() throws Exception
+{
+    EntryCursor cursor = sysRoot.search( "ou=system", "(name=*)", SearchScope.SUBTREE, "*" );
+    Set<String> set = new HashSet<String>();
+
+    while ( cursor.next() )
     {
-        if ( controls == null )
-        {
-            controls = new SearchControls();
-        }
+        Entry result = cursor.get();
+        set.add( result.getDn().getName() );
+    }
 
-        Set<String> results = new HashSet<String>();
-        NamingEnumeration<SearchResult> list = getSystemContext( getService() ).search( "ou=groups", filter, controls );
+    cursor.close();
+
+    assertEquals( "size of results", 23, set.size() );
+    assertTrue( set.contains( "ou=system" ) );
+    assertTrue( set.contains( "ou=groups,ou=system" ) );
+    assertTrue( set.contains( "cn=Administrators,ou=groups,ou=system" ) );
+    assertTrue( set.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+    assertTrue( set.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+    assertTrue( set.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+    assertTrue( set.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+    assertTrue( set.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+    assertTrue( set.contains( "ou=users,ou=system" ) );
+    assertTrue( set.contains( "uid=admin,ou=system" ) );
+    assertTrue( set.contains( "cn=Heather Nova,ou=system" ) );
+    assertTrue( set.contains( "ou=configuration,ou=system" ) );
+    assertTrue( set.contains( "ou=interceptors,ou=configuration,ou=system" ) );
+    assertTrue( set.contains( "ou=partitions,ou=configuration,ou=system" ) );
+    assertTrue( set.contains( "ou=services,ou=configuration,ou=system" ) );
+    assertTrue( set.contains( "ou=testing00,ou=system" ) );
+    assertTrue( set.contains( "ou=testing01,ou=system" ) );
+    assertTrue( set.contains( "ou=subtest,ou=testing01,ou=system" ) );
+    assertTrue( set.contains( "ou=testing02,ou=system" ) );
+    assertTrue( set.contains( "ou=testing03,ou=system" ) );
+    assertTrue( set.contains( "ou=testing04,ou=system" ) );
+    assertTrue( set.contains( "ou=testing05,ou=system" ) );
+    assertTrue( set.contains( "cn=with-dn,ou=system" ) );
+}
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            results.add( result.getName() );
-        }
 
-        return results;
-    }
+/**
+ *  Convenience method that performs a one level search using the
+ *  specified filter returning their DNs as Strings in a set.
+ *
+ * @param controls the search controls
+ * @param filter the filter expression
+ * @return the set of groups
+ * @throws NamingException if there are problems conducting the search
+ */
+public Set<String> searchGroups( String filter, SearchScope scope ) throws Exception
+{
+    Set<String> results = new HashSet<String>();
 
+    EntryCursor cursor = sysRoot.search( "ou=groups,ou=system", filter, scope, "*" );
 
-    /**
-     *  Convenience method that performs a one level search using the
-     *  specified filter returning their DNs as Strings in a set.
-     *
-     * @param filter the filter expression
-     * @return the set of group names
-     * @throws NamingException if there are problems conducting the search
-     */
-    public Set<String> searchGroups( String filter ) throws Exception
+    while ( cursor.next() )
     {
-        return searchGroups( filter, null );
+        Entry result = cursor.get();
+        results.add( result.getDn().getName() );
     }
 
+    cursor.close();
 
-    /**
-     *  Convenience method that performs a one level search using the
-     *  specified filter returning their DNs as Strings in a set.
-     *
-     * @param controls the search controls
-     * @return the set of groups
-     * @throws NamingException if there are problems conducting the search
-     */
-    public Set<String> searchRevisions( String filter ) throws Exception
-    {
-        SearchControls controls = new SearchControls();
+    return results;
+}
 
-        Set<String> results = new HashSet<String>();
-        NamingEnumeration<SearchResult> list = getSystemContext( getService() ).search( "", filter, controls );
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            results.add( result.getName() );
-        }
+/**
+ *  Convenience method that performs a one level search using the
+ *  specified filter returning their DNs as Strings in a set.
+ *
+ * @param controls the search controls
+ * @param filter the filter expression
+ * @return the set of groups
+ * @throws NamingException if there are problems conducting the search
+ */
+private Set<String> searchUnits( String filter, SearchScope scope ) throws Exception
+{
+    Set<String> results = new HashSet<String>();
+    EntryCursor cursor = sysRoot.search( "ou=system", filter, scope, "*" );
 
-        return results;
+    while ( cursor.next() )
+    {
+        Entry result = cursor.get();
+        results.add( result.getDn().getName() );
     }
 
+    cursor.close();
 
-    /**
-     *  Convenience method that performs a one level search using the
-     *  specified filter returning their DNs as Strings in a set.
-     *
-     * @param controls the search controls
-     * @param filter the filter expression
-     * @return the set of groups
-     * @throws NamingException if there are problems conducting the search
-     */
-    private Set<String> searchUnits( String filter, SearchControls controls ) throws Exception
-    {
-        if ( controls == null )
-        {
-            controls = new SearchControls();
-        }
+    return results;
+}
 
-        Set<String> results = new HashSet<String>();
-        NamingEnumeration<SearchResult> list = getSystemContext( getService() ).search( "", filter, controls );
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            results.add( result.getName() );
-        }
+@Test
+public void testSetup() throws Exception
+{
+    Set<String> results = searchGroups( "(objectClass=posixGroup)", SearchScope.ONELEVEL );
+    assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+}
 
-        return results;
-    }
 
+@Test
+public void testLessThanSearch() throws Exception
+{
+    Set<String> results = searchGroups( "(gidNumber<=5)", SearchScope.ONELEVEL );
+    assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+
+    results = searchGroups( "(gidNumber<=4)", SearchScope.ONELEVEL );
+    assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+
+    results = searchGroups( "(gidNumber<=3)", SearchScope.ONELEVEL );
+    assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+
+    results = searchGroups( "(gidNumber<=0)", SearchScope.ONELEVEL );
+    assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+
+    results = searchGroups( "(gidNumber<=-1)", SearchScope.ONELEVEL );
+    assertFalse( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+}
 
-    @Test
-    public void testSetup() throws Exception
-    {
-        Set<String> results = searchGroups( "(objectClass=posixGroup)" );
-        assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
-    }
-
-
-    @Test
-    public void testLessThanSearch() throws Exception
-    {
-        Set<String> results = searchGroups( "(gidNumber<=5)" );
-        assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
-
-        results = searchGroups( "(gidNumber<=4)" );
-        assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
-
-        results = searchGroups( "(gidNumber<=3)" );
-        assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
-
-        results = searchGroups( "(gidNumber<=0)" );
-        assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
-
-        results = searchGroups( "(gidNumber<=-1)" );
-        assertFalse( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
-    }
-
-
-    @Test
-    public void testGreaterThanSearch() throws Exception
-    {
-        Set<String> results = searchGroups( "(gidNumber>=0)" );
-        assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
-
-        results = searchGroups( "(gidNumber>=1)" );
-        assertFalse( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
-
-        results = searchGroups( "(gidNumber>=3)" );
-        assertFalse( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
-
-        results = searchGroups( "(gidNumber>=6)" );
-        assertFalse( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
-    }
-
-
-    @Test
-    public void testNotOperator() throws Exception
-    {
-        Set<String> results = searchGroups( "(!(gidNumber=4))" );
-        assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
-    }
-
-
-    @Test
-    public void testNotOperatorSubtree() throws Exception
-    {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-
-        Set<String> results = searchGroups( "(!(gidNumber=4))", controls );
-        assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
-        assertFalse( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
-        assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
-    }
-
-
-    @Test
-    public void testSearchWithEscapedCharsInFilter() throws Exception
-    {
-        // Create entry cn=Sid Vicious, ou=system
-        Attributes vicious = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: person", "cn: Sid Vicious",
-            "sn: Vicious", "description: (sex*pis\\tols)" );
-
-        DirContext ctx = sysRoot.createSubcontext( "cn=Sid Vicious", vicious );
-        assertNotNull( ctx );
-
-        ctx = ( DirContext ) sysRoot.lookup( "cn=Sid Vicious" );
-        assertNotNull( ctx );
-
-        Attributes attributes = ctx.getAttributes( "" );
-
-        assertEquals( "(sex*pis\\tols)", attributes.get( "description" ).get() );
-
-        // Now, search for the description
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        controls.setDerefLinkFlag( false );
-
-        controls.setReturningAttributes( new String[]
-            { "*" } );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
-        HashMap<String, Attributes> map = new HashMap<String, Attributes>();
 
-        NamingEnumeration<SearchResult> list = sysRoot
-            .search( "", "(description=\\28sex\\2Apis\\5Ctols\\29)", controls );
+@Test
+public void testGreaterThanSearch() throws Exception
+{
+    Set<String> results = searchGroups( "(gidNumber>=0)", SearchScope.ONELEVEL );
+    assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+
+    results = searchGroups( "(gidNumber>=1)", SearchScope.ONELEVEL );
+    assertFalse( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+
+    results = searchGroups( "(gidNumber>=3)", SearchScope.ONELEVEL );
+    assertFalse( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+
+    results = searchGroups( "(gidNumber>=6)", SearchScope.ONELEVEL );
+    assertFalse( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+}
 
-        while ( list.hasMore() )
-        {
-            SearchResult result = list.next();
-            map.put( result.getName(), result.getAttributes() );
-        }
 
-        assertEquals( "Expected number of results returned was incorrect!", 1, map.size() );
+@Test
+public void testNotOperator() throws Exception
+{
+    Set<String> results = searchGroups( "(!(gidNumber=4))", SearchScope.ONELEVEL );
+    assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+}
 
-        Attributes attrs = map.get( "cn=Sid Vicious,ou=system" );
 
-        assertNotNull( attrs.get( "objectClass" ) );
-        assertNotNull( attrs.get( "cn" ) );
-    }
+@Test
+public void testNotOperatorSubtree() throws Exception
+{
+    Set<String> results = searchGroups( "(!(gidNumber=4))", SearchScope.SUBTREE );
+    assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup2,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup3,ou=groups,ou=system" ) );
+    assertFalse( results.contains( "cn=testGroup4,ou=groups,ou=system" ) );
+    assertTrue( results.contains( "cn=testGroup5,ou=groups,ou=system" ) );
+}
 
 
-    @Test
-    public void testSubstringSearchWithEscapedCharsInFilter() throws Exception
-    {
-        // Create entry cn=Sid Vicious, ou=system
-        Attributes vicious = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: person", "cn: Sid Vicious",
-            "sn: Vicious", "description: (sex*pis\\tols)" );
+@Test
+public void testSearchWithEscapedCharsInFilter() throws Exception
+{
+    // Create entry cn=Sid Vicious, ou=system
+    Entry vicious = new DefaultEntry(
+        "cn=Sid Vicious,ou=system",
+        "objectClass: top",
+        "objectClass: person",
+        "cn: Sid Vicious",
+        "sn: Vicious",
+        "description: (sex*pis\\tols)" );
 
-        DirContext ctx = sysRoot.createSubcontext( "cn=Sid Vicious", vicious );
-        assertNotNull( ctx );
+    sysRoot.add( vicious );
 
-        ctx = ( DirContext ) sysRoot.lookup( "cn=Sid Vicious" );
-        assertNotNull( ctx );
+    assertTrue( sysRoot.exists( "cn=Sid Vicious,ou=system" ) );
 
-        Attributes attributes = ctx.getAttributes( "" );
+    Entry entry = sysRoot.lookup( "cn=Sid Vicious,ou=system" );
 
-        assertEquals( "(sex*pis\\tols)", attributes.get( "description" ).get() );
+    assertNotNull( entry );
 
-        // Now, search for the description
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        controls.setDerefLinkFlag( false );
-        controls.setReturningAttributes( new String[]
-            { "*" } );
-        sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, AliasDerefMode.NEVER_DEREF_ALIASES
-            .getJndiValue() );
+    assertTrue( entry.contains( "description", "(sex*pis\\tols)" ) );
 
-        String[] filters = new String[]
-            { "(description=*\\28*)", "(description=*\\29*)", "(description=*\\2A*)", "(description=*\\5C*)" };
-        for ( String filter : filters )
-        {
-            HashMap<String, Attributes> map = new HashMap<String, Attributes>();
-            NamingEnumeration<SearchResult> list = sysRoot.search( "", filter, controls );
+    // Now, search for the description
+    EntryCursor cursor = sysRoot.search( "ou=system", "(description=\\28sex\\2Apis\\5Ctols\\29)", SearchScope.SUBTREE,
+        "*" );
+    Map<String, Entry> map = new HashMap<String, Entry>();
+
+    while ( cursor.next() )
+    {
+        Entry result = cursor.get();
+        map.put( result.getDn().getName(), result );
+    }
 
-            while ( list.hasMore() )
-            {
-                SearchResult result = list.next();
-                map.put( result.getName(), result.getAttributes() );
-            }

[... 1076 lines stripped ...]


Mime
View raw message