Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 88085 invoked from network); 4 Jan 2007 23:18:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Jan 2007 23:18:58 -0000 Received: (qmail 83394 invoked by uid 500); 4 Jan 2007 23:19:04 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 83337 invoked by uid 500); 4 Jan 2007 23:19:04 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 83326 invoked by uid 99); 4 Jan 2007 23:19:04 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Jan 2007 15:19:04 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Jan 2007 15:18:57 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 63DF51A981A; Thu, 4 Jan 2007 15:18:00 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r492813 - /directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/SearchTest.java Date: Thu, 04 Jan 2007 23:18:00 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070104231800.63DF51A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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() ); } }