directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r499740 - /directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/jndi/SearchITest.java
Date Thu, 25 Jan 2007 11:13:28 GMT
Author: elecharny
Date: Thu Jan 25 03:13:28 2007
New Revision: 499740

URL: http://svn.apache.org/viewvc?view=rev&rev=499740
Log:
Added some tests for DIRSERVER-836

Modified:
    directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/jndi/SearchITest.java

Modified: directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/jndi/SearchITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/jndi/SearchITest.java?view=diff&rev=499740&r1=499739&r2=499740
==============================================================================
--- directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/jndi/SearchITest.java
(original)
+++ directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/jndi/SearchITest.java
Thu Jan 25 03:13:28 2007
@@ -44,6 +44,9 @@
  */
 public class SearchITest extends AbstractAdminTestCase
 {
+    private static final String rdn = "cn=Heather Nova";
+    private static final String filter = "(objectclass=*)";
+
     protected void setUp() throws Exception
     {
         if ( this.getName().equals( "testOpAttrDenormalizationOn" ) )
@@ -149,6 +152,20 @@
         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 = ( DirContext ) sysRoot.createSubcontext( rdn, heather );
+        assertNotNull( ctx );
+
+        ctx = ( DirContext ) sysRoot.lookup( rdn );
+        assertNotNull( ctx );
     }
 
 
@@ -170,7 +187,7 @@
 
         assertEquals( "Expected number of results returned was incorrect!", 1, map.size()
);
 
-        Attributes attrs = (Attributes)map.get( "ou=testing01,ou=system" );
+        Attributes attrs = map.get( "ou=testing01,ou=system" );
         
         assertNotNull( attrs.get( "createTimestamp" ) );
         assertNotNull( attrs.get( "creatorsName" ) );
@@ -196,7 +213,7 @@
 
         assertEquals( "Expected number of results returned was incorrect!", 1, map.size()
);
         
-        Attributes attrs = (Attributes)map.get( "ou=testing01,ou=system" );
+        Attributes attrs = map.get( "ou=testing01,ou=system" );
         
         assertNotNull( attrs.get( "objectClass" ) );
         assertNotNull( attrs.get( "ou" ) );
@@ -224,11 +241,73 @@
 
         assertEquals( "Expected number of results returned was incorrect!", 1, map.size()
);
 
-        Attributes attrs = (Attributes)map.get( "ou=testing01,ou=system" );
+        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
+     */
+    public void testSearchFetchNonExistingAttributeOption() throws NamingException
+    {
+        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
+     */
+    public void testSearchFetchTwiceSameAttribute() throws NamingException
+    {
+        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();
+    }
 }
+



Mime
View raw message