You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2007/01/05 00:50:08 UTC
svn commit: r492817 - in /directory/branches/apacheds/1.0:
core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreeSearchResultEnumeration.java
server-unit/src/test/java/org/apache/directory/server/SearchTest.java
Author: elecharny
Date: Thu Jan 4 15:50:07 2007
New Revision: 492817
URL: http://svn.apache.org/viewvc?view=rev&rev=492817
Log:
The search for an attribute which has some descendant wasn't returning all of them, but only the first one. Fixed.
Modified:
directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreeSearchResultEnumeration.java
directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/SearchTest.java
Modified: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreeSearchResultEnumeration.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreeSearchResultEnumeration.java?view=diff&rev=492817&r1=492816&r2=492817
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreeSearchResultEnumeration.java (original)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreeSearchResultEnumeration.java Thu Jan 4 15:50:07 2007
@@ -211,7 +211,6 @@
{
// May be it's because the attributeType is a inherited one?
Iterator descendants = registry.descendants( attrIds[ii] );
- boolean found = false;
while ( descendants.hasNext() )
{
@@ -221,15 +220,10 @@
if ( attr != null )
{
- found = true;
- break;
+ // we may have more than one descendant, like sn and cn
+ // for name, so add all of them
+ entry.put( (Attribute)attr.clone() );
}
- }
-
- if ( found )
- {
- // clone attribute to stuff into the new resultant entry
- entry.put( (Attribute)attr.clone() );
}
}
else
Modified: directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/SearchTest.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/SearchTest.java?view=diff&rev=492817&r1=492816&r2=492817
==============================================================================
--- directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/SearchTest.java (original)
+++ directory/branches/apacheds/1.0/server-unit/src/test/java/org/apache/directory/server/SearchTest.java Thu Jan 4 15:50:07 2007
@@ -23,7 +23,6 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.Hashtable;
-import java.util.Iterator;
import java.util.Set;
import javax.naming.NamingEnumeration;
@@ -706,27 +705,21 @@
controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
NamingEnumeration res = ctx.search( "", "(2.5.4.3=Tori*)", controls );
- // collect all results
- while ( res.hasMore() )
- {
- SearchResult result = ( SearchResult ) res.next();
+ // ensure that the entry "cn=Tori Amos" was found
+ assertTrue( res.hasMore() );
- Attributes attrs = result.getAttributes();
-
- NamingEnumeration all = attrs.getAll();
-
- while ( all.hasMoreElements() )
- {
- Attribute attr = (Attribute)all.next();
-
- if ( "jpegPhoto".equalsIgnoreCase( attr.getID() ) )
- {
- byte[] jpegVal = (byte[])attr.get();
-
- assertTrue( Arrays.equals( jpegVal, jpeg ) );
- }
- }
- }
+ SearchResult result = ( SearchResult ) res.next();
+
+ // ensure that result is not null
+ assertNotNull( result );
+
+ String rdn = result.getName();
+
+ // ensure that the entry "cn=Tori Amos" was found
+ assertEquals( "cn=Tori Amos", rdn );
+
+ // ensure that no other value was found
+ assertFalse( res.hasMore() );
}
public void testSearchAttrCN() throws NamingException
@@ -739,27 +732,18 @@
assertTrue( res.hasMore() );
- // collect all results
- while ( res.hasMore() )
- {
- SearchResult result = ( SearchResult ) res.next();
+ SearchResult result = ( SearchResult ) res.next();
- Attributes attrs = result.getAttributes();
-
- NamingEnumeration all = attrs.getAll();
-
- assertTrue( all.hasMoreElements() );
-
- while ( all.hasMoreElements() )
- {
- Attribute attr = (Attribute)all.next();
-
- if ( "commonName".equalsIgnoreCase( attr.getID() ) )
- {
- assertEquals( "Tori Amos", (String)attr.get() );
- }
- }
- }
+ // ensure that result is not null
+ assertNotNull( result );
+
+ Attributes attrs = result.getAttributes();
+
+ // ensure the one and only attribute is "cn"
+ assertEquals( 1, attrs.size() );
+ assertNotNull( attrs.get("cn") );
+ assertEquals( 1, attrs.get("cn").size() );
+ assertEquals( "Tori Amos", (String)attrs.get("cn").get() );
}
public void testSearchAttrName() throws NamingException
@@ -772,27 +756,21 @@
assertTrue( res.hasMore() );
- // collect all results
- while ( res.hasMore() )
- {
- SearchResult result = ( SearchResult ) res.next();
-
- Attributes attrs = result.getAttributes();
-
- NamingEnumeration all = attrs.getAll();
-
- assertTrue( all.hasMoreElements() );
-
- while ( all.hasMoreElements() )
- {
- Attribute attr = (Attribute)all.next();
-
- if ( "commonName".equalsIgnoreCase( attr.getID() ) )
- {
- assertEquals( "Tori Amos", (String)attr.get() );
- }
- }
- }
+ SearchResult result = ( SearchResult ) res.next();
+
+ // ensure that result is not null
+ assertNotNull( result );
+
+ Attributes attrs = result.getAttributes();
+
+ // ensure that "cn" and "sn" are returned
+ assertEquals( 2, attrs.size() );
+ assertNotNull( attrs.get("cn") );
+ assertEquals( 1, attrs.get("cn").size() );
+ assertEquals( "Tori Amos", (String)attrs.get("cn").get() );
+ assertNotNull( attrs.get("sn") );
+ assertEquals( 1, attrs.get("sn").size() );
+ assertEquals( "Amos", (String)attrs.get("sn").get() );
}
public void testSearchAttrCommonName() throws NamingException
@@ -805,27 +783,24 @@
assertTrue( res.hasMore() );
- // collect all results
- while ( res.hasMore() )
- {
- SearchResult result = ( SearchResult ) res.next();
- Attributes attrs = result.getAttributes();
-
- NamingEnumeration all = attrs.getAll();
-
- assertTrue( all.hasMoreElements() );
-
- while ( all.hasMoreElements() )
- {
- Attribute attr = (Attribute)all.next();
-
- if ( "commonName".equalsIgnoreCase( attr.getID() ) )
- {
- assertEquals( "Tori Amos", (String)attr.get() );
- }
- }
- }
+ SearchResult result = ( SearchResult ) res.next();
+
+ // ensure that result is not null
+ assertNotNull( result );
+
+ Attributes attrs = result.getAttributes();
+
+ // requested attribute was "commonName", but ADS returns "cn".
+ // Other servers do the following:
+ // - OpenLDAP: also return "cn"
+ // - Siemens DirX: return "commonName"
+ // - Sun Directory 5.2: return "commonName"
+ // ensure the one and only attribute is "cn"
+ assertEquals( 1, attrs.size() );
+ assertNotNull( attrs.get("cn") );
+ assertEquals( 1, attrs.get("cn").size() );
+ assertEquals( "Tori Amos", (String)attrs.get("cn").get() );
}
public void testSearchAttrOID() throws NamingException
@@ -838,26 +813,22 @@
assertTrue( res.hasMore() );
- // collect all results
- while ( res.hasMore() )
- {
- SearchResult result = ( SearchResult ) res.next();
-
- Attributes attrs = result.getAttributes();
-
- NamingEnumeration all = attrs.getAll();
-
- assertTrue( all.hasMoreElements() );
-
- while ( all.hasMoreElements() )
- {
- Attribute attr = (Attribute)all.next();
-
- if ( "2.5.4.3".equalsIgnoreCase( attr.getID() ) )
- {
- assertEquals( "Tori Amos", (String)attr.get() );
- }
- }
- }
+ SearchResult result = ( SearchResult ) res.next();
+
+ // ensure that result is not null
+ assertNotNull( result );
+
+ Attributes attrs = result.getAttributes();
+
+ // requested attribute was "2.5.4.3", but ADS returns "cn".
+ // Other servers do the following:
+ // - OpenLDAP: also return "cn"
+ // - Siemens DirX: also return "cn"
+ // - Sun Directory 5.2: return "2.5.4.3"
+ // ensure the one and only attribute is "cn"
+ assertEquals( 1, attrs.size() );
+ assertNotNull( attrs.get("cn") );
+ assertEquals( 1, attrs.get("cn").size() );
+ assertEquals( "Tori Amos", (String)attrs.get("cn").get() );
}
}