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:18:00 UTC
svn commit: r492813 -
/directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/SearchTest.java
Author: elecharny
Date: Thu Jan 4 15:17:59 2007
New Revision: 492813
URL: http://svn.apache.org/viewvc?view=rev&rev=492813
Log:
Applied the patch submitted by Stefan. Removed the @TODO
Modified:
directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/SearchTest.java
Modified: directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/SearchTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/SearchTest.java?view=diff&rev=492813&r1=492812&r2=492813
==============================================================================
--- directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/SearchTest.java (original)
+++ directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/SearchTest.java Thu Jan 4 15:17:59 2007
@@ -706,27 +706,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();
-
- 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 ) );
- }
- }
- }
+ // ensure that the entry "cn=Tori Amos" was found
+ assertTrue( res.hasMore() );
+
+ 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 +733,18 @@
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 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 +757,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 +784,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,27 +814,23 @@
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() );
}
}