directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r602630 - in /directory/apacheds/branches/bigbang: core-integ/src/test/java/org/apache/directory/server/core/ core-integ/src/test/java/org/apache/directory/server/core/jndi/ core-unit/src/test/java/org/apache/directory/server/core/
Date Sun, 09 Dec 2007 04:36:59 GMT
Author: akarasulu
Date: Sat Dec  8 20:36:58 2007
New Revision: 602630

URL: http://svn.apache.org/viewvc?rev=602630&view=rev
Log:
added more tests and renamed some: also moved them around a little bit for efficiently using
existing up and running servers

Added:
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchIT.java
  (contents, props changed)
      - copied, changed from r602604, directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchContextIT.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchWithIndicesITest.java
  (contents, props changed)
      - copied, changed from r602604, directory/apacheds/branches/bigbang/core-unit/src/test/java/org/apache/directory/server/core/SearchOpsITest.java
Removed:
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchContextIT.java
    directory/apacheds/branches/bigbang/core-unit/src/test/java/org/apache/directory/server/core/SearchOpsITest.java
Modified:
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/StockCoreISuite.java

Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/StockCoreISuite.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/StockCoreISuite.java?rev=602630&r1=602629&r2=602630&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/StockCoreISuite.java
(original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/StockCoreISuite.java
Sat Dec  8 20:36:58 2007
@@ -68,7 +68,7 @@
         ModifyContextIT.class,
         RFC2713IT.class,
         RootDSEIT.class,
-        SearchContextIT.class,
+        SearchIT.class,
         UniqueMemberIT.class,
         OperationalAttributeServiceIT.class,
         PreferencesIT.class,

Copied: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchIT.java
(from r602604, directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchContextIT.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchIT.java?p2=directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchIT.java&p1=directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchContextIT.java&r1=602604&r2=602630&rev=602630&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchContextIT.java
(original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchIT.java
Sat Dec  8 20:36:58 2007
@@ -25,6 +25,7 @@
 import org.apache.directory.server.core.enumeration.SearchResultFilteringEnumeration;
 import org.apache.directory.server.core.integ.CiRunner;
 import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
+import static org.apache.directory.server.core.integ.IntegrationUtils.getSchemaContext;
 import org.apache.directory.server.core.invocation.Invocation;
 import org.apache.directory.shared.ldap.constants.JndiPropertyConstants;
 import org.apache.directory.shared.ldap.exception.LdapSizeLimitExceededException;
@@ -32,6 +33,7 @@
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
 import static org.junit.Assert.*;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -41,6 +43,8 @@
 import javax.naming.directory.*;
 import javax.naming.ldap.LdapContext;
 import java.util.HashMap;
+import java.util.Set;
+import java.util.HashSet;
 
 
 /**
@@ -50,7 +54,7 @@
  * @version $Rev$
  */
 @RunWith ( CiRunner.class )
-public class SearchContextIT
+public class SearchIT
 {
     private static final String RDN = "cn=Heather Nova";
     private static final String FILTER = "(objectclass=*)";
@@ -162,7 +166,6 @@
         assertTrue( attribute.contains( "top" ) );
         assertTrue( attribute.contains( "organizationalUnit" ) );
 
-
         // Create entry cn=Heather Nova, ou=system
         Attributes heather = new AttributesImpl();
         Attribute ocls = new AttributeImpl( "objectClass" );
@@ -176,6 +179,49 @@
 
         ctx = ( DirContext ) sysRoot.lookup( RDN );
         assertNotNull( ctx );
+
+
+        // -------------------------------------------------------------------
+        // Enable the nis schema
+        // -------------------------------------------------------------------
+
+        // check if nis is disabled
+        LdapContext schemaRoot = getSchemaContext( service );
+        Attributes nisAttrs = schemaRoot.getAttributes( "cn=nis" );
+        boolean isNisDisabled = false;
+        if ( nisAttrs.get( "m-disabled" ) != null )
+        {
+            isNisDisabled = ( ( String ) nisAttrs.get( "m-disabled" ).get() ).equalsIgnoreCase(
"TRUE" );
+        }
+
+        // if nis is disabled then enable it
+        if ( isNisDisabled )
+        {
+            Attribute disabled = new AttributeImpl( "m-disabled" );
+            ModificationItemImpl[] mods = new ModificationItemImpl[] {
+                new ModificationItemImpl( 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 );
+    }
+
+
+    private DirContext addNisPosixGroup( String name, int gid ) throws NamingException
+    {
+        Attributes attrs = new AttributesImpl( "objectClass", "top", true );
+        attrs.get( "objectClass" ).add( "posixGroup" );
+        attrs.put( "cn", name );
+        attrs.put( "gidNumber", String.valueOf( gid ) );
+        return getSystemContext( service ).createSubcontext( "cn="+name+",ou=groups", attrs
);
     }
 
 
@@ -447,7 +493,7 @@
             SearchResult result = ( SearchResult ) list.next();
             map.put( result.getName(), result.getAttributes() );
         }
-        assertEquals( "size of results", 14, map.size() );
+        assertEquals( "size of results", 19, 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"
) ); 
@@ -959,4 +1005,187 @@
 //        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
NamingException
+    {
+        if ( controls == null )
+        {
+            controls = new SearchControls();
+        }
+
+        Set<String> results = new HashSet<String>();
+        NamingEnumeration list = getSystemContext( service ).search( "ou=groups", filter,
controls );
+
+        while( list.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) 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 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 NamingException
+    {
+        return searchGroups( filter, null );
+    }
+
+
+    @Test
+    public void testSetup() throws Exception
+    {
+        LdapContext sysRoot = getSystemContext( service );
+        createData( sysRoot );
+
+        Set 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
+    {
+        LdapContext sysRoot = getSystemContext( service );
+        createData( sysRoot );
+
+        Set 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
+    {
+        LdapContext sysRoot = getSystemContext( service );
+        createData( sysRoot );
+
+        Set 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 NamingException
+    {
+        LdapContext sysRoot = getSystemContext( service );
+        createData( sysRoot );
+
+        Set 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 NamingException
+    {
+        LdapContext sysRoot = getSystemContext( service );
+        createData( sysRoot );
+
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+
+        Set 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" ) );
+    }
 }

Propchange: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchIT.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchIT.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Sat Dec  8 20:36:58 2007
@@ -0,0 +1,4 @@
+Rev
+Revision
+Date
+Id

Copied: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchWithIndicesITest.java
(from r602604, directory/apacheds/branches/bigbang/core-unit/src/test/java/org/apache/directory/server/core/SearchOpsITest.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchWithIndicesITest.java?p2=directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchWithIndicesITest.java&p1=directory/apacheds/branches/bigbang/core-unit/src/test/java/org/apache/directory/server/core/SearchOpsITest.java&r1=602604&r2=602630&rev=602630&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-unit/src/test/java/org/apache/directory/server/core/SearchOpsITest.java
(original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchWithIndicesITest.java
Sat Dec  8 20:36:58 2007
@@ -17,20 +17,33 @@
  *  under the License. 
  *  
  */
-package org.apache.directory.server.core;
+package org.apache.directory.server.core.jndi;
 
 
+import org.apache.directory.server.core.DefaultDirectoryService;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.integ.CiRunner;
+import org.apache.directory.server.core.integ.DirectoryServiceFactory;
+import static org.apache.directory.server.core.integ.IntegrationUtils.getSchemaContext;
+import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
+import org.apache.directory.server.core.integ.ServiceScope;
+import org.apache.directory.server.core.integ.annotations.Factory;
+import org.apache.directory.server.core.integ.annotations.Scope;
 import org.apache.directory.server.core.partition.impl.btree.Index;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
-import org.apache.directory.server.core.unit.AbstractAdminTestCase;
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.message.AttributesImpl;
 import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.*;
+import javax.naming.ldap.LdapContext;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -41,79 +54,93 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class SearchOpsITest extends AbstractAdminTestCase
+@RunWith ( CiRunner.class )
+@Scope ( ServiceScope.TESTCLASS )
+@Factory ( SearchWithIndicesITest.MyFactory.class )
+public class SearchWithIndicesITest
 {
-    private DirContext addNisPosixGroup( String name, int gid ) throws NamingException
-    {
-        Attributes attrs = new AttributesImpl( "objectClass", "top", true );
-        attrs.get( "objectClass" ).add( "posixGroup" );
-        attrs.put( "cn", name );
-        attrs.put( "gidNumber", String.valueOf( gid ) );
-        return sysRoot.createSubcontext( "cn="+name+",ou=groups", attrs );
-    }
-    
-    
-    @SuppressWarnings("unchecked")
-    public void setUp() throws Exception
-    {
-        // -------------------------------------------------------------------
-        // Alter the partition configuration to index gidNumber
-        // -------------------------------------------------------------------
+    public static DirectoryService service;
 
-        if ( getName().indexOf( "WithIndices" ) != -1 )
-        {
-            JdbmPartition partition = new JdbmPartition();
-            partition.setId( "system" );
-            Attributes attrs = new AttributesImpl( "objectClass", "top", true );
-            attrs.get( "objectClass" ).add( "organizationalUnit" );
-            attrs.put( "ou", "system" );
-            partition.setContextEntry( attrs );
-            partition.setSuffix( "ou=system" );
-            
-            Set<Index> indices = new HashSet<Index>();
-            indices.addAll( partition.getIndexedAttributes() );
-            indices.add( new JdbmIndex( "gidNumber" ) );
-            partition.setIndexedAttributes( indices );
-            service.setSystemPartition( partition );
-        }
-        
-        super.setUp();
 
+
+    private void createData() throws NamingException
+    {
         // -------------------------------------------------------------------
         // Enable the nis schema
         // -------------------------------------------------------------------
 
         // check if nis is disabled
+        LdapContext schemaRoot = getSchemaContext( service );
         Attributes nisAttrs = schemaRoot.getAttributes( "cn=nis" );
         boolean isNisDisabled = false;
         if ( nisAttrs.get( "m-disabled" ) != null )
         {
             isNisDisabled = ( ( String ) nisAttrs.get( "m-disabled" ).get() ).equalsIgnoreCase(
"TRUE" );
         }
-        
+
         // if nis is disabled then enable it
         if ( isNisDisabled )
         {
             Attribute disabled = new AttributeImpl( "m-disabled" );
-            ModificationItemImpl[] mods = new ModificationItemImpl[] { 
+            ModificationItemImpl[] mods = new ModificationItemImpl[] {
                 new ModificationItemImpl( 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 );
     }
+
+
+    private DirContext addNisPosixGroup( String name, int gid ) throws NamingException
+    {
+        Attributes attrs = new AttributesImpl( "objectClass", "top", true );
+        attrs.get( "objectClass" ).add( "posixGroup" );
+        attrs.put( "cn", name );
+        attrs.put( "gidNumber", String.valueOf( gid ) );
+        return getSystemContext( service ).createSubcontext( "cn="+name+",ou=groups", attrs
);
+    }
+    
+    
+    public static class MyFactory implements DirectoryServiceFactory
+    {
+        public DirectoryService newInstance()
+        {
+            DirectoryService service = new DefaultDirectoryService();
+            service.getChangeLog().setEnabled( true );
+
+            // -------------------------------------------------------------------
+            // Alter the partition configuration to index gidNumber
+            // -------------------------------------------------------------------
+
+            JdbmPartition partition = new JdbmPartition();
+            partition.setId( "system" );
+            Attributes attrs = new AttributesImpl( "objectClass", "top", true );
+            attrs.get( "objectClass" ).add( "organizationalUnit" );
+            attrs.put( "ou", "system" );
+            partition.setContextEntry( attrs );
+            partition.setSuffix( "ou=system" );
+
+            Set<Index> indices = new HashSet<Index>();
+            indices.addAll( partition.getIndexedAttributes() );
+            indices.add( new JdbmIndex( "gidNumber" ) );
+            partition.setIndexedAttributes( indices );
+            service.setSystemPartition( partition );
+
+            return service;
+        }
+    }
     
     
     /**
-     *  Convenience method that performs a one level search using the 
+     *  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
@@ -127,22 +154,22 @@
         {
             controls = new SearchControls();
         }
-        
+
         Set<String> results = new HashSet<String>();
-        NamingEnumeration list = sysRoot.search( "ou=groups", filter, controls );
-        
+        NamingEnumeration list = getSystemContext( service ).search( "ou=groups", filter,
controls );
+
         while( list.hasMore() )
         {
             SearchResult result = ( SearchResult ) list.next();
             results.add( result.getName() );
         }
-        
+
         return results;
     }
-    
-    
+
+
     /**
-     *  Convenience method that performs a one level search using the 
+     *  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
@@ -153,102 +180,12 @@
     {
         return searchGroups( filter, null );
     }
-    
-    
-    public void testSetup() throws Exception
-    {
-        Set 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" ) );
-    }
 
-    
-    public void testLessThanSearch() throws Exception
-    {
-        Set 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" ) );
-    }
-
-    
-    public void testGreaterThanSearch() throws Exception
-    {
-        Set 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 testLessThanSearchWithIndices() throws Exception
     {
+        createData();
         Set results = searchGroups( "(gidNumber<=5)" );
         assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
         assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
@@ -291,8 +228,10 @@
     }
 
     
+    @Test
     public void testGreaterThanSearchWithIndices() throws Exception
     {
+        createData();
         Set results = searchGroups( "(gidNumber>=0)" );
         assertTrue( results.contains( "cn=testGroup0,ou=groups,ou=system" ) );
         assertTrue( results.contains( "cn=testGroup1,ou=groups,ou=system" ) );
@@ -324,32 +263,5 @@
         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" ) );
-    }
-
-    
-    public void testNotOperator() throws NamingException
-    {
-        Set 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" ) );
-    }
-    
-    
-    public void testNotOperatorSubtree() throws NamingException
-    {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-        
-        Set 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" ) );
     }
 }

Propchange: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchWithIndicesITest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message