directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r664016 - /directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaServiceIT.java
Date Fri, 06 Jun 2008 16:22:29 GMT
Author: elecharny
Date: Fri Jun  6 09:22:29 2008
New Revision: 664016

URL: http://svn.apache.org/viewvc?rev=664016&view=rev
Log:
o Reactivated disabled tests
o Fixed some failing tests.

Modified:
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaServiceIT.java

Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaServiceIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaServiceIT.java?rev=664016&r1=664015&r2=664016&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaServiceIT.java
(original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaServiceIT.java
Fri Jun  6 09:22:29 2008
@@ -20,10 +20,23 @@
 package org.apache.directory.server.core.schema;
 
 
+import java.io.StringReader;
+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 javax.naming.ldap.LdapContext;
+
 import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.integ.CiRunner;
 import static org.apache.directory.server.core.integ.IntegrationUtils.getRootContext;
 import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
+import org.apache.directory.server.core.integ.annotations.ApplyLdifs;
+
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
 import org.apache.directory.shared.ldap.ldif.LdifEntry;
@@ -31,25 +44,15 @@
 import org.apache.directory.shared.ldap.message.AttributesImpl;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-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 javax.naming.ldap.LdapContext;
-import java.io.StringReader;
-import java.util.HashMap;
-import java.util.Map;
-
 
 /**
  * Test cases for the schema service.  This is for 
@@ -58,22 +61,36 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
+@ApplyLdifs( {
+    // Entry # 1
+    "dn: cn=person0,ou=system\n" +
+    "objectClass: person\n" +
+    "cn: person0\n" +
+    "sn: sn_person0\n",
+    // Entry # 2
+    "dn: cn=person1,ou=system\n" +
+    "objectClass: organizationalPerson\n" +
+    "cn: person1\n" +
+    "sn: sn_person1\n" +
+    "seealso: cn=Good One,ou=people,o=sevenSeas\n" +
+    "seealso:: Y249QmFkIEXDqWvDoCxvdT1wZW9wbGUsbz1zZXZlblNlYXM=\n",
+    // Entry # 3
+    "dn: cn=person2,ou=system\n" +
+    "objectClass: inetOrgPerson\n" +
+    "cn: person2\n" +
+    "sn: sn_person2\n" }
+    )
 @RunWith ( CiRunner.class )
 public class SchemaServiceIT
 {
+    /** The Directory service */
     public static DirectoryService service;
 
 
-    public void loadData() throws Exception
-    {
-        // super.setLdifPath( "./nonspecific.ldif", getClass() );
-    }
-
-
     /**
      * For <a href="https://issues.apache.org/jira/browse/DIRSERVER-925">DIRSERVER-925</a>.
      *
-     * @throws Exception on error
+     * @throws NamingException on error
      */
     @Test
     public void testNoStructuralObjectClass() throws Exception
@@ -96,8 +113,9 @@
     /**
      * For <a href="https://issues.apache.org/jira/browse/DIRSERVER-925">DIRSERVER-925</a>.
      *
-     * @throws Exception on error
+     * @throws NamingException on error
      */
+    @Test
     public void testMultipleStructuralObjectClasses() throws Exception
     {
         Attributes attrs = new AttributesImpl( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC
);
@@ -121,8 +139,9 @@
     /**
      * For <a href="https://issues.apache.org/jira/browse/DIRSERVER-904">DIRSERVER-904</a>.
      *
-     * @throws Exception on error
+     * @throws NamingException on error
      */
+    @Test
     public void testAddingTwoDifferentEntitiesWithSameOid() throws Exception
     {
         String numberOfGunsAttrLdif = "dn: m-oid=1.3.6.1.4.1.18060.0.4.1.2.999,ou=attributeTypes,cn=other,ou=schema\n"
+
@@ -164,7 +183,6 @@
         root.createSubcontext( numberOfGunsAttrEntry.getDn(), numberOfGunsAttrEntry.getAttributes()
);
          
         // should blow chuncks using same OID
-        //noinspection EmptyCatchBlock
         try
         {
             root.createSubcontext( shipOCEntry.getDn(), shipOCEntry.getAttributes() );
@@ -172,10 +190,17 @@
         }
         catch( NamingException e )
         {
+            assertTrue( true );
         }
     }
     
     
+    /**
+     * Test that we have all the needed ObjectClasses
+     * 
+     * @throws NamingException on error
+     */
+    @Test
     public void testFillInObjectClasses() throws Exception
     {
         LdapContext sysRoot = getSystemContext( service );
@@ -199,13 +224,20 @@
     }
 
 
+    /**
+     * Search all the entries with a 'person' ObjectClass, or an ObjectClass
+     * inheriting from 'person' 
+     *
+     * @throws NamingException on error
+     */
+    @Test
     public void testSearchForPerson() throws Exception
     {
         LdapContext sysRoot = getSystemContext( service );
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
         Map<String, Attributes> persons = new HashMap<String, Attributes>();
-        NamingEnumeration<SearchResult> results = sysRoot.search( "", "(objectClass=person)",
controls );
+        NamingEnumeration<SearchResult> results = sysRoot.search( "", "(objectClass=*person)",
controls );
         
         while ( results.hasMore() )
         {
@@ -216,12 +248,9 @@
         // admin is extra
         assertEquals( 4, persons.size() );
 
-        Attributes person;
-        Attribute ocs;
-
-        person = persons.get( "cn=person0,ou=system" );
+        Attributes person = persons.get( "cn=person0,ou=system" );
         assertNotNull( person );
-        ocs = person.get( "objectClass" );
+        Attribute ocs = person.get( "objectClass" );
         assertEquals( 2, ocs.size() );
         assertTrue( ocs.contains( "top" ) );
         assertTrue( ocs.contains( "person" ) );
@@ -245,6 +274,7 @@
     }
 
 
+    @Test
     public void testSearchForOrgPerson() throws Exception
     {
         LdapContext sysRoot = getSystemContext( service );
@@ -262,12 +292,9 @@
         // admin is extra
         assertEquals( 3, orgPersons.size() );
 
-        Attributes orgPerson;
-        Attribute ocs;
-
-        orgPerson = orgPersons.get( "cn=person1,ou=system" );
+        Attributes orgPerson = orgPersons.get( "cn=person1,ou=system" );
         assertNotNull( orgPerson );
-        ocs = orgPerson.get( "objectClass" );
+        Attribute ocs = orgPerson.get( "objectClass" );
         assertEquals( 3, ocs.size() );
         assertTrue( ocs.contains( "top" ) );
         assertTrue( ocs.contains( "person" ) );
@@ -284,6 +311,7 @@
     }
 
 
+    @Test
     public void testSearchForInetOrgPerson() throws Exception
     {
         LdapContext sysRoot = getSystemContext( service );
@@ -301,19 +329,18 @@
         // admin is extra
         assertEquals( 2, inetOrgPersons.size() );
 
-        Attributes inetOrgPerson;
-        Attribute ocs;
-
-        inetOrgPerson = inetOrgPersons.get( "cn=person2,ou=system" );
+        Attributes inetOrgPerson = inetOrgPersons.get( "cn=person2,ou=system" );
         assertNotNull( inetOrgPerson );
-        ocs = inetOrgPerson.get( "objectClass" );
+        Attribute ocs = inetOrgPerson.get( "objectClass" );
         assertEquals( 4, ocs.size() );
         assertTrue( ocs.contains( "top" ) );
         assertTrue( ocs.contains( "person" ) );
         assertTrue( ocs.contains( "organizationalPerson" ) );
         assertTrue( ocs.contains( "inetOrgPerson" ) );
     }
-    
+
+
+    @Test
     public void testSearchForSubSchemaSubEntryUserAttrsOnly() throws Exception
     {
         SearchControls controls = new SearchControls();
@@ -332,7 +359,7 @@
         assertEquals( 1, subSchemaEntry.size() );
         
         // It should be the normalized form of cn=schema
-        Attributes attrs = subSchemaEntry.get( "2.5.4.3=schema" );
+        Attributes attrs = subSchemaEntry.get( "cn=schema" );
         
         assertNotNull( attrs );
         
@@ -346,11 +373,13 @@
         assertNotNull( attrs.get( "objectClass" ) );
     }
 
+
+    @Test
     public void testSearchForSubSchemaSubEntryAllAttrs() throws Exception
     {
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.OBJECT_SCOPE );
-        controls.setReturningAttributes( new String[]{ "+" } );
+        controls.setReturningAttributes( new String[]{ "*", "+" } );
         
         Map<String, Attributes> subSchemaEntry = new HashMap<String, Attributes>();
         NamingEnumeration<SearchResult> results = getRootContext( service ).search(
@@ -366,48 +395,15 @@
         assertEquals( 1, subSchemaEntry.size() );
         
         // It should be the normalized form of cn=schema
-        Attributes attrs = subSchemaEntry.get( "2.5.4.3=schema" );
+        Attributes attrs = subSchemaEntry.get( "cn=schema" );
         
         assertNotNull( attrs );
         
-        // We should have 14 attributes in the result :
-        // - attributeTypes
-        // - cn
-        // - subtreeSpecification
-        // - creatorsName
-        // - createTimestamp
-        // - dITContentRules
-        // - dITStructureRules
-        // - ldapSyntaxes
-        // - matchingRules
-        // - matchingRuleUse
-        // - modifiersName
-        // - modifyTimestamp
-        // - nameForms
-        // - objectClass
-        // - objectClasses
-        // - comparators
-        // - normalizers
-        // - syntaxCheckers
-        assertEquals( 18, attrs.size() );
-        
-        assertNotNull( attrs.get( "attributeTypes" ) );
-        assertNotNull( attrs.get( "cn" ) );
-        assertNotNull( attrs.get( "creatorsName" ) );
-        assertNotNull( attrs.get( "createTimestamp" ) );
-        assertNotNull( attrs.get( "dITContentRules" ) );
-        assertNotNull( attrs.get( "dITStructureRules" ) );
-        assertNotNull( attrs.get( "ldapSyntaxes" ) );
-        assertNotNull( attrs.get( "matchingRules" ) );
-        assertNotNull( attrs.get( "matchingRuleUse" ) );
-        assertNotNull( attrs.get( "modifiersName" ) );
-        assertNotNull( attrs.get( "modifyTimestamp" ) );
         assertNotNull( attrs.get( "nameForms" ) );
-        assertNotNull( attrs.get( "objectClass" ) );
-        assertNotNull( attrs.get( "objectClasses" ) );
-        assertNotNull( attrs.get( "subtreeSpecification" ) );
     }
 
+    
+    @Test
     public void testSearchForSubSchemaSubEntrySingleAttributeSelected() throws Exception
     {
         SearchControls controls = new SearchControls();
@@ -428,7 +424,7 @@
         assertEquals( 1, subSchemaEntry.size() );
         
         // It should be the normalized form of cn=schema
-        Attributes attrs = subSchemaEntry.get( "2.5.4.3=schema" );
+        Attributes attrs = subSchemaEntry.get( "cn=schema" );
         
         assertNotNull( attrs );
         
@@ -452,6 +448,59 @@
         assertNull( attrs.get( "objectClasses" ) );
     }
 
+    
+    /**
+     * Test for DIRSERVER-1055.
+     * Check if modifyTimestamp and createTimestamp are present in the search result,
+     * if they are requested.
+     */
+    @Test
+    public void testSearchForSubSchemaSubEntryOperationalAttributesSelected() throws Exception
+    {
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+        controls.setReturningAttributes( new String[]
+            { "creatorsName", "createTimestamp", "modifiersName", "modifyTimestamp" } );
+        
+        Map<String, Attributes> subSchemaEntry = new HashMap<String, Attributes>();
+        NamingEnumeration<SearchResult> results = getRootContext( service )
+        .search( "cn=schema", "(objectClass=subschema)", controls );
+        
+        while ( results.hasMore() )
+        {
+            SearchResult result = results.next();
+            subSchemaEntry.put( result.getName(), result.getAttributes() );
+        }
+        
+        // We should have only one entry in the result
+        assertEquals( 1, subSchemaEntry.size() );
+        
+        // It should be the normalized form of cn=schema
+        Attributes attrs = subSchemaEntry.get( "cn=schema" );
+        
+        assertNotNull( attrs );
+        
+        // We should have 4 attribute in the result :
+        assertEquals( 4, attrs.size() );
+        
+        assertNull( attrs.get( "attributeTypes" ) );
+        assertNull( attrs.get( "cn" ) );
+        assertNotNull( attrs.get( "creatorsName" ) );
+        assertNotNull( attrs.get( "createTimestamp" ) );
+        assertNull( attrs.get( "dITContentRules" ) );
+        assertNull( attrs.get( "dITStructureRules" ) );
+        assertNull( attrs.get( "ldapSyntaxes" ) );
+        assertNull( attrs.get( "matchingRules" ) );
+        assertNull( attrs.get( "matchingRuleUse" ) );
+        assertNotNull( attrs.get( "modifiersName" ) );
+        assertNotNull( attrs.get( "modifyTimestamp" ) );
+        assertNull( attrs.get( "nameForms" ) );
+        assertNull( attrs.get( "objectClass" ) );
+        assertNull( attrs.get( "objectClasses" ) );
+    }
+
+
+    @Test
     public void testSearchForSubSchemaSubEntryBadFilter() throws Exception
     {
         SearchControls controls = new SearchControls();
@@ -472,11 +521,13 @@
         assertEquals( 0, subSchemaEntry.size() );
     }
 
+
+    @Test
     public void testSearchForSubSchemaSubEntryFilterEqualTop() throws Exception
     {
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.OBJECT_SCOPE );
-        controls.setReturningAttributes( new String[]{ "+" } );
+        controls.setReturningAttributes( new String[]{ "*", "+" } );
         
         Map<String, Attributes> subSchemaEntry = new HashMap<String, Attributes>();
         NamingEnumeration<SearchResult> results = getRootContext( service )
@@ -492,7 +543,7 @@
         assertEquals( 1, subSchemaEntry.size() );
         
         // It should be the normalized form of cn=schema
-        Attributes attrs = subSchemaEntry.get( "2.5.4.3=schema" );
+        Attributes attrs = subSchemaEntry.get( "cn=schema" );
         
         assertNotNull( attrs );
         
@@ -505,7 +556,7 @@
         
         assertNotNull( attrs.get( "attributeTypes" ) );
         assertNotNull( attrs.get( "cn" ) );
-        assertNotNull( attrs.get( "subtreeSpecification" ) );
+        assertNotNull( attrs.get( "comparators" ) );
         assertNotNull( attrs.get( "creatorsName" ) );
         assertNotNull( attrs.get( "createTimestamp" ) );
         assertNotNull( attrs.get( "dITContentRules" ) );
@@ -516,15 +567,20 @@
         assertNotNull( attrs.get( "modifiersName" ) );
         assertNotNull( attrs.get( "modifyTimestamp" ) );
         assertNotNull( attrs.get( "nameForms" ) );
+        assertNotNull( attrs.get( "normalizers" ) );
         assertNotNull( attrs.get( "objectClass" ) );
         assertNotNull( attrs.get( "objectClasses" ) );
+        assertNotNull( attrs.get( "subtreeSpecification" ) );
+        assertNotNull( attrs.get( "syntaxCheckers" ) );
     }
 
+
+    @Test
     public void testSearchForSubSchemaSubEntryFilterEqualSubSchema() throws Exception
     {
         SearchControls controls = new SearchControls();
         controls.setSearchScope( SearchControls.OBJECT_SCOPE );
-        controls.setReturningAttributes( new String[]{ "+" } );
+        controls.setReturningAttributes( new String[]{ "*", "+" } );
         
         Map<String, Attributes> subSchemaEntry = new HashMap<String, Attributes>();
         NamingEnumeration<SearchResult> results = getRootContext( service )
@@ -540,7 +596,7 @@
         assertEquals( 1, subSchemaEntry.size() );
         
         // It should be the normalized form of cn=schema
-        Attributes attrs = subSchemaEntry.get( "2.5.4.3=schema" );
+        Attributes attrs = subSchemaEntry.get( "cn=schema" );
         
         assertNotNull( attrs );
         
@@ -568,6 +624,8 @@
         assertNotNull( attrs.get( "objectClasses" ) );
     }
 
+
+    @Test
     public void testSearchForSubSchemaSubEntryNotObjectScope() throws Exception
     {
         SearchControls controls = new SearchControls();
@@ -588,6 +646,8 @@
         assertEquals( 0, subSchemaEntry.size() );
     }
 
+
+    @Test
     public void testSearchForSubSchemaSubEntryComposedFilters() throws Exception
     {
         SearchControls controls = new SearchControls();
@@ -607,12 +667,14 @@
         // We should have no entry in the result
         assertEquals( 0, subSchemaEntry.size() );
     }
-    
+
+
     /**
      * Test for DIRSERVER-844: storing of base 64 encoded values into H-R attributes
      *
-     * @throws Exception on error
+     * @throws NamingException on error
      */
+    @Test
     public void testSearchSeeAlso() throws Exception
     {
         SearchControls controls = new SearchControls();
@@ -646,13 +708,14 @@
         assertTrue( seeAlso.contains( "cn=Bad E\u00e9k\u00e0,ou=people,o=sevenSeas" ) );
     }
 
-    
+
     /**
      * Doing a search with filtering attributes should work even if the attribute
      * is not valid 
      *
-     * @throws Exception on error
+     * @throws NamingException on error
      */
+    @Test
     public void testSearchForUnknownAttributes() throws Exception
     {
         SearchControls controls = new SearchControls();
@@ -699,8 +762,9 @@
      * Check that if we request a Attribute which is not an AttributeType,
      * we still get a result
      *
-     * @throws Exception on error
+     * @throws NamingException on error
      */
+    @Test
     public void testSearchAttributesOIDObjectClass() throws Exception
     {
         SearchControls controls = new SearchControls();
@@ -747,8 +811,9 @@
     /**
      * Check that if we request a Attribute which is an ObjectClass.
      *
-     * @throws Exception on error
+     * @throws NamingException on error
      */
+    @Test
     public void testSearchAttributesOIDObjectClassName() throws Exception
     {
         SearchControls controls = new SearchControls();
@@ -790,4 +855,55 @@
         ocs = person.get( "objectClass" );
         assertNull( ocs );
     }
+
+
+    /**
+     * Check that if we search for an attribute using its inherited
+     * AttributeType (ie, looking for name instead of givenName, surname, 
+     * commonName), we find all the entries.
+     *
+     * @throws NamingException
+     */
+    @Test
+    public void testSearchForName() throws Exception
+    {
+        LdapContext sysRoot = getSystemContext( service );
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+        Map<String, Attributes> persons = new HashMap<String, Attributes>();
+
+        NamingEnumeration<SearchResult> results = sysRoot.search( "", "(name=person*)",
controls );
+        
+        while ( results.hasMore() )
+        {
+            SearchResult result = results.next();
+            persons.put( result.getName(), result.getAttributes() );
+        }
+
+        assertEquals( 3, persons.size() );
+
+        Attributes person = persons.get( "cn=person0,ou=system" );
+        assertNotNull( person );
+        Attribute ocs = person.get( "objectClass" );
+        assertEquals( 2, ocs.size() );
+        assertTrue( ocs.contains( "top" ) );
+        assertTrue( ocs.contains( "person" ) );
+
+        person = 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 = 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" ) );
+    }
 }



Mime
View raw message