directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r375330 - in /directory/sandbox/akarasulu/rc1refactor/apacheds: core-unit/src/test/java/org/apache/ldap/server/core/ core-unit/src/test/java/org/apache/ldap/server/core/schema/ core-unit/src/test/resources/org/ core-unit/src/test/resources/...
Date Mon, 06 Feb 2006 18:45:57 GMT
Author: akarasulu
Date: Mon Feb  6 10:45:54 2006
New Revision: 375330

URL: http://svn.apache.org/viewcvs?rev=375330&view=rev
Log:
adding test cases and ldif file for confirming correct operation after fixes to
DIREVE-276

Added:
    directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/java/org/apache/ldap/server/core/
    directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/java/org/apache/ldap/server/core/schema/
    directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/java/org/apache/ldap/server/core/schema/SchemaServiceTest.java
  (with props)
    directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/
    directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/apache/
    directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/apache/ldap/
    directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/apache/ldap/server/
    directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/apache/ldap/server/core/
    directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/apache/ldap/server/core/schema/
    directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/apache/ldap/server/core/schema/nonspecific.ldif
  (with props)
Modified:
    directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/DefaultDirectoryService.java
    directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/jndi/AbstractContextFactory.java
    directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/schema/SchemaService.java

Added: directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/java/org/apache/ldap/server/core/schema/SchemaServiceTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/java/org/apache/ldap/server/core/schema/SchemaServiceTest.java?rev=375330&view=auto
==============================================================================
--- directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/java/org/apache/ldap/server/core/schema/SchemaServiceTest.java
(added)
+++ directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/java/org/apache/ldap/server/core/schema/SchemaServiceTest.java
Mon Feb  6 10:45:54 2006
@@ -0,0 +1,179 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.server.core.schema;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.ldap.server.unit.AbstractAdminTestCase;
+
+
+/**
+ * Test cases for the schema service.  This is for 
+ * <a href="http://issues.apache.org/jira/browse/DIREVE-276">DIREVE-276</a>.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SchemaServiceTest extends AbstractAdminTestCase
+{
+    public void setUp() throws Exception
+    {
+        super.setLdifPath( "./nonspecific.ldif", getClass() );
+        super.setUp();
+    }
+    
+    
+    public void testFillInObjectClasses() throws NamingException
+    {
+        Attribute ocs = sysRoot.getAttributes( "cn=person0" ).get( "objectClass" );
+        assertEquals( 2, ocs.size() );
+        assertTrue( ocs.contains( "top" ) );
+        assertTrue( ocs.contains( "person" ) );
+
+        ocs = sysRoot.getAttributes( "cn=person1" ).get( "objectClass" );
+        assertEquals( 3, ocs.size() );
+        assertTrue( ocs.contains( "top" ) );
+        assertTrue( ocs.contains( "person" ) );
+        assertTrue( ocs.contains( "organizationalPerson" ) );
+
+        ocs = sysRoot.getAttributes( "cn=person2" ).get( "objectClass" );
+        assertEquals( 4, ocs.size() );
+        assertTrue( ocs.contains( "top" ) );
+        assertTrue( ocs.contains( "person" ) );
+        assertTrue( ocs.contains( "organizationalPerson" ) );
+        assertTrue( ocs.contains( "inetOrgPerson" ) );
+    }
+
+
+    public void testSearchForPerson() throws NamingException
+    {
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+        Map persons = new HashMap();
+        NamingEnumeration results = sysRoot.search( "", "(objectClass=person)", controls
);
+        while ( results.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) results.next();
+            persons.put( result.getName(), result.getAttributes() );
+        }
+
+        // admin is extra
+        assertEquals( 4, persons.size() );
+        
+        Attributes person = null;
+        Attribute ocs = null;
+        
+        person = ( Attributes ) persons.get( "cn=person0,ou=system" );
+        assertNotNull( person );
+        ocs = person.get( "objectClass" );
+        assertEquals( 2, ocs.size() );
+        assertTrue( ocs.contains( "top" ) );
+        assertTrue( ocs.contains( "person" ) );
+        
+        person = ( Attributes ) persons.get( "cn=person1,ou=system" );
+        assertNotNull( person );
+        ocs = person.get( "objectClass" );
+        assertEquals( 3, ocs.size() );
+        assertTrue( ocs.contains( "top" ) );
+        assertTrue( ocs.contains( "person" ) );
+        assertTrue( ocs.contains( "organizationalPerson" ) );
+        
+        person = ( Attributes ) persons.get( "cn=person2,ou=system" );
+        assertNotNull( person );
+        ocs = person.get( "objectClass" );
+        assertEquals( 4, ocs.size() );
+        assertTrue( ocs.contains( "top" ) );
+        assertTrue( ocs.contains( "person" ) );
+        assertTrue( ocs.contains( "organizationalPerson" ) );
+        assertTrue( ocs.contains( "inetOrgPerson" ) );
+    }
+
+
+    public void testSearchForOrgPerson() throws NamingException
+    {
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+        Map orgPersons = new HashMap();
+        NamingEnumeration results = sysRoot.search( "", "(objectClass=organizationalPerson)",
controls );
+        while ( results.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) results.next();
+            orgPersons.put( result.getName(), result.getAttributes() );
+        }
+        
+        // admin is extra
+        assertEquals( 3, orgPersons.size() );
+        
+        Attributes orgPerson = null;
+        Attribute ocs = null;
+        
+        orgPerson = ( Attributes ) orgPersons.get( "cn=person1,ou=system" );
+        assertNotNull( orgPerson );
+        ocs = orgPerson.get( "objectClass" );
+        assertEquals( 3, ocs.size() );
+        assertTrue( ocs.contains( "top" ) );
+        assertTrue( ocs.contains( "person" ) );
+        assertTrue( ocs.contains( "organizationalPerson" ) );
+        
+        orgPerson = ( Attributes ) orgPersons.get( "cn=person2,ou=system" );
+        assertNotNull( orgPerson );
+        ocs = orgPerson.get( "objectClass" );
+        assertEquals( 4, ocs.size() );
+        assertTrue( ocs.contains( "top" ) );
+        assertTrue( ocs.contains( "person" ) );
+        assertTrue( ocs.contains( "organizationalPerson" ) );
+        assertTrue( ocs.contains( "inetOrgPerson" ) );
+    }
+
+
+    public void testSearchForInetOrgPerson() throws NamingException
+    {
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+        Map inetOrgPersons = new HashMap();
+        NamingEnumeration results = sysRoot.search( "", "(objectClass=inetOrgPerson)", controls
);
+        while ( results.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) results.next();
+            inetOrgPersons.put( result.getName(), result.getAttributes() );
+        }
+        
+        // admin is extra
+        assertEquals( 2, inetOrgPersons.size() );
+        
+        Attributes inetOrgPerson = null;
+        Attribute ocs = null;
+        
+        inetOrgPerson = ( Attributes ) inetOrgPersons.get( "cn=person2,ou=system" );
+        assertNotNull( inetOrgPerson );
+        ocs = inetOrgPerson.get( "objectClass" );
+        assertEquals( 4, ocs.size() );
+        assertTrue( ocs.contains( "top" ) );
+        assertTrue( ocs.contains( "person" ) );
+        assertTrue( ocs.contains( "organizationalPerson" ) );
+        assertTrue( ocs.contains( "inetOrgPerson" ) );
+    }
+}

Propchange: directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/java/org/apache/ldap/server/core/schema/SchemaServiceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/apache/ldap/server/core/schema/nonspecific.ldif
URL: http://svn.apache.org/viewcvs/directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/apache/ldap/server/core/schema/nonspecific.ldif?rev=375330&view=auto
==============================================================================
--- directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/apache/ldap/server/core/schema/nonspecific.ldif
(added)
+++ directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/apache/ldap/server/core/schema/nonspecific.ldif
Mon Feb  6 10:45:54 2006
@@ -0,0 +1,15 @@
+
+dn: cn=person0,ou=system
+objectClass: person
+cn: cn_person0
+sn: sn_person0
+
+dn: cn=person1,ou=system
+objectClass: organizationalPerson
+cn: cn_person1
+sn: sn_person1
+
+dn: cn=person2,ou=system
+objectClass: inetOrgPerson
+cn: cn_person2
+sn: sn_person2

Propchange: directory/sandbox/akarasulu/rc1refactor/apacheds/core-unit/src/test/resources/org/apache/ldap/server/core/schema/nonspecific.ldif
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/DefaultDirectoryService.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/DefaultDirectoryService.java?rev=375330&r1=375329&r2=375330&view=diff
==============================================================================
--- directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/DefaultDirectoryService.java
(original)
+++ directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/DefaultDirectoryService.java
Mon Feb  6 10:45:54 2006
@@ -50,7 +50,9 @@
 import org.apache.ldap.server.configuration.ConfigurationException;
 import org.apache.ldap.server.configuration.StartupConfiguration;
 import org.apache.ldap.server.interceptor.InterceptorChain;
+import org.apache.ldap.server.jndi.AbstractContextFactory;
 import org.apache.ldap.server.jndi.DeadContext;
+import org.apache.ldap.server.jndi.LdapJndiProperties;
 import org.apache.ldap.server.jndi.ServerLdapContext;
 import org.apache.ldap.server.partition.DefaultDirectoryPartitionNexus;
 import org.apache.ldap.server.partition.DirectoryPartitionNexus;
@@ -223,9 +225,12 @@
         initialize();
         firstStart = createBootstrapEntries();
         showSecurityWarnings();
-        createTestEntries();
         this.serviceListener = listener;
         started = true;
+        if ( ! startupConfiguration.getTestEntries().isEmpty() )
+        {
+            createTestEntries( env );
+        }
         listener.afterStartup( this );
     }
 
@@ -640,28 +645,21 @@
         }
     }
     
-    private void createTestEntries() throws NamingException
+    private void createTestEntries( Hashtable env ) throws NamingException
     {
-        /*
-         * Unfortunately to test non-root user startup of the core and make sure
-         * all the appropriate functionality is there we need to load more user
-         * entries at startup due to a chicken and egg like problem.  The value
-         * of this property is a list of attributes to be added.
-         */
+        String principal = AbstractContextFactory.getPrincipal( env );
+        byte[] credential = AbstractContextFactory.getCredential( env );
+        String authentication = AbstractContextFactory.getAuthentication( env );
+        String providerUrl = AbstractContextFactory.getProviderUrl( env );
+        ServerLdapContext ctx = ( ServerLdapContext ) getJndiContext( principal, credential,

+            authentication, "" );
+        
         Iterator i = startupConfiguration.getTestEntries().iterator();
         while( i.hasNext() )
         {
-            Attributes entry = ( Attributes ) i.next();
-            entry.put( "creatorsName", DirectoryPartitionNexus.ADMIN_PRINCIPAL );
-            entry.put( "createTimestamp", DateUtils.getGeneralizedTime() );
-            
-            Attribute dn = ( Attribute ) entry.get( "dn" ).clone();
-            AttributeTypeRegistry registry = globalRegistries.getAttributeTypeRegistry();
-            NameComponentNormalizer ncn = new ConcreteNameComponentNormalizer( registry );
-            DnParser parser = new DnParser( ncn );
-            Name ndn = parser.parse( ( String ) dn.get() );
-            
-            partitionNexus.add( ( String ) dn.get(), ndn, entry );
+            Attributes entry = ( Attributes ) ( ( Attributes ) i.next() ).clone();
+            String dn = ( String ) entry.remove( "dn" ).get();
+            ctx.createSubcontext( dn, entry );
         }
     }
 

Modified: directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/jndi/AbstractContextFactory.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/jndi/AbstractContextFactory.java?rev=375330&r1=375329&r2=375330&view=diff
==============================================================================
--- directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/jndi/AbstractContextFactory.java
(original)
+++ directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/jndi/AbstractContextFactory.java
Mon Feb  6 10:45:54 2006
@@ -121,7 +121,7 @@
         return service.getJndiContext( principal, credential, authentication, providerUrl
);
     }
 
-    private String getProviderUrl( Hashtable env )
+    public static String getProviderUrl( Hashtable env )
     {
         String providerUrl;
         Object value;
@@ -137,7 +137,7 @@
         return providerUrl;
     }
 
-    private String getAuthentication( Hashtable env )
+    public static String getAuthentication( Hashtable env )
     {
         String authentication;
         Object value = env.get( Context.SECURITY_AUTHENTICATION );
@@ -155,7 +155,7 @@
         return authentication;
     }
 
-    private byte[] getCredential( Hashtable env ) throws ConfigurationException
+    public static byte[] getCredential( Hashtable env ) throws ConfigurationException
     {
         byte[] credential;
         Object value = env.get( Context.SECURITY_CREDENTIALS );
@@ -184,7 +184,7 @@
         return credential;
     }
 
-    private String getPrincipal( Hashtable env )
+    public static String getPrincipal( Hashtable env )
     {
         String principal;
         Object value = env.get( Context.SECURITY_PRINCIPAL );

Modified: directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/schema/SchemaService.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/schema/SchemaService.java?rev=375330&r1=375329&r2=375330&view=diff
==============================================================================
--- directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/schema/SchemaService.java
(original)
+++ directory/sandbox/akarasulu/rc1refactor/apacheds/core/src/main/java/org/apache/ldap/server/schema/SchemaService.java
Mon Feb  6 10:45:54 2006
@@ -17,8 +17,10 @@
 package org.apache.ldap.server.schema;
 
 
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -89,6 +91,10 @@
      * a binary attribute tranforming filter: String -> byte[]
      */
     private BinaryAttributeFilter binaryAttributeFilter;
+    
+    private TopFilter topFilter;
+    
+    private List filters = new ArrayList();
 
     /**
      * the global schema object registries
@@ -100,7 +106,7 @@
     /**
      * subschemaSubentry attribute's value from Root DSE
      */
-    private String subentryDn;
+    private String subschemaSubentryDn;
 
     /**
      * The time when the server started up.
@@ -121,11 +127,14 @@
         this.nexus = factoryCfg.getPartitionNexus();
         this.globalRegistries = factoryCfg.getGlobalRegistries();
         binaryAttributeFilter = new BinaryAttributeFilter();
+        topFilter = new TopFilter();
+        filters.add( binaryAttributeFilter );
+        filters.add( topFilter );
         binaries = ( Set ) factoryCfg.getEnvironment().get( BINARY_KEY );
 
         // stuff for dealing with subentries (garbage for now)
         String subschemaSubentry = ( String ) nexus.getRootDSE().get( "subschemaSubentry"
).get();
-        subentryDn = new LdapName( subschemaSubentry ).toString().toLowerCase();
+        subschemaSubentryDn = new LdapName( subschemaSubentry ).toString().toLowerCase();
     }
 
 
@@ -156,9 +165,16 @@
                                      SearchControls searchCtls ) throws NamingException
     {
         // check to make sure the DN searched for is a subentry
-        if ( !subentryDn.equals( base.toString() ) )
+        if ( !subschemaSubentryDn.equals( base.toString() ) )
         {
-            return nextInterceptor.search( base, env, filter, searchCtls );
+            NamingEnumeration e = nextInterceptor.search( base, env, filter, searchCtls );
+            if ( searchCtls.getReturningAttributes() != null )
+            {
+                return e;
+            }
+
+            Invocation invocation = InvocationStack.getInstance().peek();
+            return new SearchResultFilteringEnumeration( e, searchCtls, invocation, filters
);
         }
 
         if ( searchCtls.getSearchScope() == SearchControls.OBJECT_SCOPE &&
@@ -178,7 +194,7 @@
             }
         }
         else if ( searchCtls.getSearchScope() == SearchControls.OBJECT_SCOPE &&
-                filter instanceof PresenceNode )
+                    filter instanceof PresenceNode )
         {
             PresenceNode node = ( PresenceNode ) filter;
 
@@ -192,14 +208,13 @@
         }
 
         NamingEnumeration e = nextInterceptor.search( base, env, filter, searchCtls );
-
         if ( searchCtls.getReturningAttributes() != null )
         {
             return e;
         }
 
         Invocation invocation = InvocationStack.getInstance().peek();
-        return new SearchResultFilteringEnumeration( e, searchCtls, invocation, binaryAttributeFilter
);
+        return new SearchResultFilteringEnumeration( e, searchCtls, invocation, filters );
     }
 
 
@@ -387,7 +402,8 @@
     public Attributes lookup( NextInterceptor nextInterceptor, Name name ) throws NamingException
     {
         Attributes result = nextInterceptor.lookup( name );
-        doFilter( result );
+        filterBinaryAttributes( result );
+        filterTop( result );
         return result;
     }
 
@@ -400,7 +416,8 @@
             return null;
         }
 
-        doFilter( result );
+        filterBinaryAttributes( result );
+        filterTop( result );
         return result;
     }
 
@@ -783,17 +800,9 @@
         next.modify( name, mods );
     }
 
-
-    private void doFilter( Attributes entry ) throws NamingException
+    
+    private void filterTop( Attributes entry ) throws NamingException
     {
-        long t0 = -1;
-        
-        if ( log.isDebugEnabled() )
-        {
-            t0 = System.currentTimeMillis();
-            log.debug( "Filtering entry " + AttributeUtils.toString( entry ) );  
-        }
-        
         // add top if objectClass is included and missing top
         Attribute oc = entry.get( "objectClass" );
         if ( oc != null )
@@ -803,6 +812,18 @@
                 oc.add( "top" );
             }
         }
+    }
+
+
+    private void filterBinaryAttributes( Attributes entry ) throws NamingException
+    {
+        long t0 = -1;
+        
+        if ( log.isDebugEnabled() )
+        {
+            t0 = System.currentTimeMillis();
+            log.debug( "Filtering entry " + AttributeUtils.toString( entry ) );  
+        }
         
         /*
          * start converting values of attributes to byte[]s which are not
@@ -868,7 +889,19 @@
     {
         public boolean accept( Invocation invocation, SearchResult result, SearchControls
controls ) throws NamingException
         {
-            doFilter( result.getAttributes() );
+            filterBinaryAttributes( result.getAttributes() );
+            return true;
+        }
+    }
+
+    /**
+     * Filters objectClass attribute to inject top when not present.
+     */
+    private class TopFilter implements SearchResultFilter
+    {
+        public boolean accept( Invocation invocation, SearchResult result, SearchControls
controls ) throws NamingException
+        {
+            filterTop( result.getAttributes() );
             return true;
         }
     }
@@ -885,7 +918,7 @@
             String name = (String)attrEnum.nextElement();
             if ( ! atRegistry.hasAttributeType( name ) )
             {
-                throw new LdapInvalidAttributeIdentifierException();
+                throw new LdapInvalidAttributeIdentifierException( name + " not found in
attribute registry!" );
             }
         }
         



Mime
View raw message