Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 87163 invoked from network); 4 Dec 2007 22:13:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Dec 2007 22:13:53 -0000 Received: (qmail 17107 invoked by uid 500); 4 Dec 2007 22:13:41 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 17060 invoked by uid 500); 4 Dec 2007 22:13:41 -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 17048 invoked by uid 99); 4 Dec 2007 22:13:41 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Dec 2007 14:13:41 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED 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; Tue, 04 Dec 2007 22:13:28 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5EFC31A9832; Tue, 4 Dec 2007 14:13:31 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r601108 - in /directory/apacheds/branches/bigbang: core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchContextIT.java core-unit/src/test/java/org/apache/directory/server/core/jndi/SearchITest.java Date: Tue, 04 Dec 2007 22:13:30 -0000 To: commits@directory.apache.org From: akarasulu@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071204221331.5EFC31A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: akarasulu Date: Tue Dec 4 14:13:28 2007 New Revision: 601108 URL: http://svn.apache.org/viewvc?rev=601108&view=rev Log: moved all SearchITest test methods to SearchContextIT since they used the same setup data Removed: directory/apacheds/branches/bigbang/core-unit/src/test/java/org/apache/directory/server/core/jndi/SearchITest.java Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchContextIT.java Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchContextIT.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchContextIT.java?rev=601108&r1=601107&r2=601108&view=diff ============================================================================== --- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchContextIT.java (original) +++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/SearchContextIT.java Tue Dec 4 14:13:28 2007 @@ -52,8 +52,10 @@ @RunWith ( CiRunner.class ) public class SearchContextIT { - public static DirectoryService service; + private static final String RDN = "cn=Heather Nova"; + private static final String FILTER = "(objectclass=*)"; + public static DirectoryService service; /** * @todo put this into ldif and use ldif annotation to import @@ -63,8 +65,6 @@ */ protected void createData( LdapContext sysRoot ) throws NamingException { - - /* * create ou=testing00,ou=system */ @@ -161,6 +161,21 @@ assertNotNull( attribute ); assertTrue( attribute.contains( "top" ) ); assertTrue( attribute.contains( "organizationalUnit" ) ); + + + // Create entry cn=Heather Nova, ou=system + Attributes heather = new AttributesImpl(); + Attribute ocls = new AttributeImpl( "objectClass" ); + ocls.add( "top" ); + ocls.add( "person" ); + heather.put( ocls ); + heather.put( "cn", "Heather Nova" ); + heather.put( "sn", "Nova" ); + ctx = sysRoot.createSubcontext( RDN, heather ); + assertNotNull( ctx ); + + ctx = ( DirContext ) sysRoot.lookup( RDN ); + assertNotNull( ctx ); } @@ -432,7 +447,7 @@ SearchResult result = ( SearchResult ) list.next(); map.put( result.getName(), result.getAttributes() ); } - assertEquals( "size of results", 13, map.size() ); + assertEquals( "size of results", 14, map.size() ); assertTrue( "contains ou=testing00,ou=system", map.containsKey( "ou=testing00,ou=system" ) ); assertTrue( "contains ou=testing01,ou=system", map.containsKey( "ou=testing01,ou=system" ) ); assertTrue( "contains ou=testing02,ou=system", map.containsKey( "ou=testing01,ou=system" ) ); @@ -646,6 +661,273 @@ assertEquals( "cn=Kate Bush,ou=system", sr.getName() ); } + + @Test + public void testSearchOperationalAttr() throws NamingException + { + LdapContext sysRoot = getSystemContext( service ); + createData( sysRoot ); + + SearchControls controls = new SearchControls(); + controls.setSearchScope( SearchControls.ONELEVEL_SCOPE ); + controls.setDerefLinkFlag( false ); + controls.setReturningAttributes( new String[] { "+" } ); + sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, + AliasDerefMode.NEVER_DEREF_ALIASES.getJndiValue() ); + HashMap map = new HashMap(); + + NamingEnumeration list = sysRoot.search( "", "(ou=testing01)", controls ); + while ( list.hasMore() ) + { + SearchResult result = ( SearchResult ) list.next(); + map.put( result.getName(), result.getAttributes() ); + } + + assertEquals( "Expected number of results returned was incorrect!", 1, map.size() ); + + Attributes attrs = map.get( "ou=testing01,ou=system" ); + + assertNotNull( attrs.get( "createTimestamp" ) ); + assertNotNull( attrs.get( "creatorsName" ) ); + assertNull( attrs.get( "objectClass" ) ); + assertNull( attrs.get( "ou" ) ); + } + + + @Test + public void testSearchUserAttr() throws NamingException + { + LdapContext sysRoot = getSystemContext( service ); + createData( sysRoot ); + + SearchControls controls = new SearchControls(); + controls.setSearchScope( SearchControls.ONELEVEL_SCOPE ); + controls.setDerefLinkFlag( false ); + controls.setReturningAttributes( new String[] { "*" } ); + sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, + AliasDerefMode.NEVER_DEREF_ALIASES.getJndiValue() ); + HashMap map = new HashMap(); + + NamingEnumeration list = sysRoot.search( "", "(ou=testing01)", controls ); + while ( list.hasMore() ) + { + SearchResult result = ( SearchResult ) list.next(); + map.put( result.getName(), result.getAttributes() ); + } + + assertEquals( "Expected number of results returned was incorrect!", 1, map.size() ); + + Attributes attrs = map.get( "ou=testing01,ou=system" ); + + assertNotNull( attrs.get( "objectClass" ) ); + assertNotNull( attrs.get( "ou" ) ); + assertNull( attrs.get( "createTimestamp" ) ); + assertNull( attrs.get( "creatorsName" ) ); + } + + + @Test + public void testSearchUserAttrAndOpAttr() throws NamingException + { + LdapContext sysRoot = getSystemContext( service ); + createData( sysRoot ); + + SearchControls controls = new SearchControls(); + controls.setSearchScope( SearchControls.ONELEVEL_SCOPE ); + controls.setDerefLinkFlag( false ); + controls.setReturningAttributes( new String[] { "*", "creatorsName" } ); + sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, + AliasDerefMode.NEVER_DEREF_ALIASES.getJndiValue() ); + HashMap map = new HashMap(); + + NamingEnumeration list = sysRoot.search( "", "(ou=testing01)", controls ); + while ( list.hasMore() ) + { + SearchResult result = ( SearchResult ) list.next(); + map.put( result.getName(), result.getAttributes() ); + } + + assertEquals( "Expected number of results returned was incorrect!", 1, map.size() ); + + Attributes attrs = map.get( "ou=testing01,ou=system" ); + + assertNotNull( attrs.get( "objectClass" ) ); + assertNotNull( attrs.get( "ou" ) ); + assertNotNull( attrs.get( "creatorsName" ) ); + assertNull( attrs.get( "createTimestamp" ) ); + } + + + @Test + public void testSearchUserAttrAndNoAttr() throws NamingException + { + LdapContext sysRoot = getSystemContext( service ); + createData( sysRoot ); + + SearchControls controls = new SearchControls(); + controls.setSearchScope( SearchControls.ONELEVEL_SCOPE ); + controls.setDerefLinkFlag( false ); + controls.setReturningAttributes( new String[] { "1.1", "ou" } ); + sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, + AliasDerefMode.NEVER_DEREF_ALIASES.getJndiValue() ); + HashMap map = new HashMap(); + + NamingEnumeration list = sysRoot.search( "", "(ou=testing01)", controls ); + while ( list.hasMore() ) + { + SearchResult result = ( SearchResult ) list.next(); + map.put( result.getName(), result.getAttributes() ); + } + + assertEquals( "Expected number of results returned was incorrect!", 1, map.size() ); + + Attributes attrs = map.get( "ou=testing01,ou=system" ); + + assertNull( attrs.get( "objectClass" ) ); + assertNotNull( attrs.get( "ou" ) ); + assertNull( attrs.get( "creatorsName" ) ); + assertNull( attrs.get( "createTimestamp" ) ); + } + + + @Test + public void testSearchNoAttr() throws NamingException + { + LdapContext sysRoot = getSystemContext( service ); + createData( sysRoot ); + + SearchControls controls = new SearchControls(); + controls.setSearchScope( SearchControls.ONELEVEL_SCOPE ); + controls.setDerefLinkFlag( false ); + controls.setReturningAttributes( new String[] { "1.1" } ); + sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, + AliasDerefMode.NEVER_DEREF_ALIASES.getJndiValue() ); + HashMap map = new HashMap(); + + NamingEnumeration list = sysRoot.search( "", "(ou=testing01)", controls ); + while ( list.hasMore() ) + { + SearchResult result = ( SearchResult ) list.next(); + map.put( result.getName(), result.getAttributes() ); + } + + assertEquals( "Expected number of results returned was incorrect!", 1, map.size() ); + + Attributes attrs = map.get( "ou=testing01,ou=system" ); + + assertNull( attrs.get( "objectClass" ) ); + assertNull( attrs.get( "ou" ) ); + assertNull( attrs.get( "creatorsName" ) ); + assertNull( attrs.get( "createTimestamp" ) ); + } + + + @Test + public void testSearchAllAttr() throws NamingException + { + LdapContext sysRoot = getSystemContext( service ); + createData( sysRoot ); + + SearchControls controls = new SearchControls(); + controls.setSearchScope( SearchControls.ONELEVEL_SCOPE ); + controls.setDerefLinkFlag( false ); + controls.setReturningAttributes( new String[] { "+", "*" } ); + sysRoot.addToEnvironment( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES, + AliasDerefMode.NEVER_DEREF_ALIASES.getJndiValue() ); + HashMap map = new HashMap(); + + NamingEnumeration list = sysRoot.search( "", "(ou=testing01)", controls ); + + while ( list.hasMore() ) + { + SearchResult result = ( SearchResult ) list.next(); + map.put( result.getName(), result.getAttributes() ); + } + + assertEquals( "Expected number of results returned was incorrect!", 1, map.size() ); + + Attributes attrs = map.get( "ou=testing01,ou=system" ); + + assertNotNull( attrs.get( "createTimestamp" ) ); + assertNotNull( attrs.get( "creatorsName" ) ); + assertNotNull( attrs.get( "objectClass" ) ); + assertNotNull( attrs.get( "ou" ) ); + } + + + /** + * Search an entry and fetch an attribute with unknown option + * @throws NamingException if there are errors + */ + @Test + public void testSearchFetchNonExistingAttributeOption() throws NamingException + { + LdapContext sysRoot = getSystemContext( service ); + createData( sysRoot ); + + SearchControls ctls = new SearchControls(); + ctls.setSearchScope( SearchControls.OBJECT_SCOPE ); + ctls.setReturningAttributes( new String[] + { "cn", "sn;unknownOption" } ); + + NamingEnumeration result = sysRoot.search( RDN, FILTER, ctls ); + + if ( result.hasMore() ) + { + SearchResult entry = ( SearchResult ) result.next(); + Attributes attrs = entry.getAttributes(); + Attribute cn = attrs.get( "cn" ); + + assertNotNull( cn ); + assertEquals( "Heather Nova", cn.get().toString() ); + + Attribute sn = attrs.get( "sn" ); + assertNull( sn ); + } + else + { + fail( "entry " + RDN + " not found" ); + } + + result.close(); + } + + + /** + * Search an entry and fetch an attribute with twice the same attributeType + * @throws NamingException if there are errors + */ + @Test + public void testSearchFetchTwiceSameAttribute() throws NamingException + { + LdapContext sysRoot = getSystemContext( service ); + createData( sysRoot ); + + SearchControls ctls = new SearchControls(); + ctls.setSearchScope( SearchControls.OBJECT_SCOPE ); + ctls.setReturningAttributes( new String[] + { "cn", "cn" } ); + + NamingEnumeration result = sysRoot.search( RDN, FILTER, ctls ); + + if ( result.hasMore() ) + { + SearchResult entry = ( SearchResult ) result.next(); + Attributes attrs = entry.getAttributes(); + Attribute cn = attrs.get( "cn" ); + + assertNotNull( cn ); + assertEquals( "Heather Nova", cn.get().toString() ); + } + else + { + fail( "entry " + RDN + " not found" ); + } + + result.close(); + } + + // this one is failing because it returns the admin user twice: count = 15 // public void testFilterExpansion3() throws Exception // { @@ -677,6 +959,4 @@ // assertTrue( "contains uid=admin,ou=system", map.contains( "uid=admin,ou=system" ) ); // assertTrue( "contains cn=administrators,ou=groups,ou=system", map.contains( "cn=administrators,ou=groups,ou=system" ) ); // } - - }