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 2010/04/23 19:08:33 UTC

svn commit: r937388 [2/2] - in /directory/apacheds/trunk/ldap-client-test: ./ src/ src/main/ src/main/java/ src/main/resources/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/directory/ src/test/java/org/...

Added: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/bind/SimpleBindRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/bind/SimpleBindRequestTest.java?rev=937388&view=auto
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/bind/SimpleBindRequestTest.java (added)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/bind/SimpleBindRequestTest.java Fri Apr 23 17:08:32 2010
@@ -0,0 +1,452 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.client.api.operations.bind;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import org.apache.directory.ldap.client.api.LdapAsyncConnection;
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.apache.directory.ldap.client.api.future.BindFuture;
+import org.apache.directory.ldap.client.api.message.BindRequest;
+import org.apache.directory.ldap.client.api.message.BindResponse;
+import org.apache.directory.ldap.client.api.message.LdapResult;
+import org.apache.directory.server.annotations.CreateLdapServer;
+import org.apache.directory.server.annotations.CreateTransport;
+import org.apache.directory.server.core.annotations.ApplyLdifs;
+import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
+import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.server.core.interceptor.BaseInterceptor;
+import org.apache.directory.server.core.interceptor.NextInterceptor;
+import org.apache.directory.server.core.interceptor.context.BindOperationContext;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Test the Simple BindRequest operation
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+@RunWith ( FrameworkRunner.class ) 
+@CreateLdapServer ( 
+    transports = 
+    {
+        @CreateTransport( protocol = "LDAP" ),
+        @CreateTransport( protocol = "LDAPS" ) 
+    })
+@ApplyLdifs( {
+    // Entry # 1
+    "dn: uid=superuser,ou=system",
+    "objectClass: person",
+    "objectClass: organizationalPerson",
+    "objectClass: inetOrgPerson",
+    "objectClass: top",
+    "cn: superuser",
+    "sn: administrator",
+    "displayName: Directory Superuser",
+    "uid: superuser",
+    "userPassword: test"
+})
+public class SimpleBindRequestTest extends AbstractLdapTestUnit
+{
+    private LdapAsyncConnection connection;
+
+    
+    /**
+     * Create the LdapConnection
+     */
+    @Before
+    public void setup() throws Exception
+    {
+        connection = new LdapNetworkConnection( "localhost", ldapServer.getPort() );
+    }
+
+    
+    /**
+     * Close the LdapConnection
+     */
+    @After
+    public void shutdown()
+    {
+        try
+        {
+            if ( connection != null )
+            {
+                connection.close();
+            }
+        }
+        catch( Exception ioe )
+        {
+            fail();
+        }
+    }
+
+    
+    /**
+     * Test a successful synchronous bind request. the server allows it.
+     */
+    @Test
+    public void testSyncBindRequest() throws Exception
+    {
+        BindResponse bindResponse = connection.bind( "uid=admin,ou=system", "secret" );
+        
+        assertNotNull( bindResponse );
+        assertNotNull( bindResponse.getLdapResult() );
+        assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode() );
+        assertEquals( 1, bindResponse.getMessageId() );
+        assertTrue( connection.isAuthenticated() );
+    }
+
+    
+    /**
+     * Test a successful asynchronous bind request, 10 times.
+     */
+    @Test
+    public void testAsyncBindRequest() throws Exception
+    {
+        int i = 0;
+        int nbLoop = 10;
+
+        for ( ; i < nbLoop; i++)
+        {
+            BindRequest bindRequest = new BindRequest();
+            bindRequest.setName( "uid=admin,ou=system" );
+            bindRequest.setCredentials( "secret" );
+            
+            BindFuture bindFuture = connection.bindAsync( bindRequest );
+            
+            try
+            {
+                BindResponse bindResponse = bindFuture.get( 1000, TimeUnit.MILLISECONDS );
+                
+                assertNotNull( bindResponse );
+                assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode() );
+                assertTrue( connection.isAuthenticated() );
+            }
+            catch ( TimeoutException toe )
+            {
+                fail();
+            }
+        }
+    }
+    
+    
+    /**
+     * Test an Anonymous BindRequest
+     */
+    @Test
+    public void testSimpleBindAnonymous() throws Exception
+    {
+        for ( int i = 0; i < 5; i++)
+        {
+            //System.out.println( "------------------Create connection" + i + "-------------" );
+            LdapConnection connection = new LdapNetworkConnection( "localhost", ldapServer.getPort() );
+            //System.out.println( "------------------Bind" + i + "-------------" );
+            
+            // Try with no parameters
+            BindResponse bindResponse = connection.bind();
+            
+            assertNotNull( bindResponse );
+            assertNotNull( bindResponse.getLdapResult() );
+            assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode() );
+            assertEquals( 1, bindResponse.getMessageId() );
+            assertTrue( connection.isAuthenticated() );
+    
+            //System.out.println( "----------------Unbind" + i + "-------------" );
+            connection.unBind();
+            assertFalse( connection.isConnected() );
+    
+            // Try with empty strings
+            connection = new LdapNetworkConnection( "localhost", ldapServer.getPort() );
+            bindResponse = connection.bind( "", "" );
+            
+            assertNotNull( bindResponse );
+            assertNotNull( bindResponse.getLdapResult() );
+            assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode() );
+            assertEquals( 1, bindResponse.getMessageId() );
+            assertTrue( connection.isAuthenticated() );
+    
+            connection.unBind();
+            assertFalse( connection.isConnected() );
+    
+            // Try with null parameters
+            connection = new LdapNetworkConnection( "localhost", ldapServer.getPort() );
+            bindResponse = connection.bind( (String)null, (String)null );
+            
+            assertNotNull( bindResponse );
+            assertNotNull( bindResponse.getLdapResult() );
+            assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode() );
+            assertEquals( 1, bindResponse.getMessageId() );
+            assertTrue( connection.isAuthenticated() );
+            assertTrue( connection.isConnected() );
+
+            connection.unBind();
+            assertFalse( connection.isConnected() );
+
+            connection = new LdapNetworkConnection( "localhost", ldapServer.getPort() );
+            
+            
+            //System.out.println( "----------------Unbind done" + i + "-------------" );
+            assertFalse( connection.isConnected() );
+            //System.out.println( "----------------Unconnected" + i + "-------------" );
+            
+        }
+    }
+
+    
+    /**
+     * A bind with no name and a password is invalid
+     */
+    @Test
+    public void testSimpleBindNoNamePassword() throws Exception
+    {
+        BindResponse response = connection.bind((String)null, "abc" );
+        LdapResult ldapResult = response.getLdapResult();
+        assertEquals( ResultCodeEnum.INVALID_CREDENTIALS, ldapResult.getResultCode() );
+        assertEquals( 1, response.getMessageId() );
+        assertFalse( connection.isAuthenticated() );
+        assertTrue( connection.isConnected() );
+    }
+
+    
+    /**
+     * Test an unauthenticated bind (name, no password)
+     */
+    @Test
+    public void testSimpleBindUnauthenticated() throws Exception
+    {
+        BindResponse response = connection.bind( "uid=admin,ou=system", (String)null );
+        LdapResult ldapResult = response.getLdapResult();
+        assertEquals( ResultCodeEnum.UNWILLING_TO_PERFORM, ldapResult.getResultCode() );
+        assertEquals( 1, response.getMessageId() );
+        assertFalse( connection.isAuthenticated() );
+        assertTrue( connection.isConnected() );
+    }
+
+    
+    /**
+     * Test a valid bind
+     */
+    @Test
+    public void testSimpleBindValid() throws Exception
+    {
+        BindResponse response = connection.bind( "uid=admin,ou=system", "secret" );
+        LdapResult ldapResult = response.getLdapResult();
+        assertEquals( ResultCodeEnum.SUCCESS, ldapResult.getResultCode() );
+        assertEquals( 1, response.getMessageId() );
+        assertTrue( connection.isAuthenticated() );
+    }
+
+    
+    /**
+     * Test a bind with a valid user but a wrong password
+     */
+    @Test
+    public void testSimpleBindValidUserWrongPassword() throws Exception
+    {
+        BindResponse response = connection.bind( "uid=admin,ou=system", "badpassword" );
+        LdapResult ldapResult = response.getLdapResult();
+        assertEquals( ResultCodeEnum.INVALID_CREDENTIALS, ldapResult.getResultCode() );
+        assertEquals( 1, response.getMessageId() );
+        assertFalse( connection.isAuthenticated() );
+        assertTrue( connection.isConnected() );
+    }
+
+    
+    /**
+     * Test a bind with an invalid user
+     */
+    @Test
+    public void testSimpleBindInvalidUser() throws Exception
+    {
+        BindResponse response = connection.bind( "uid=wrong,ou=system", "secret" );
+        LdapResult ldapResult = response.getLdapResult();
+        assertEquals( ResultCodeEnum.INVALID_CREDENTIALS, ldapResult.getResultCode() );
+        assertEquals( 1, response.getMessageId() );
+        assertFalse( connection.isAuthenticated() );
+        assertTrue( connection.isConnected() );
+    }
+
+    
+    /**
+     * Test a valid bind followed by another valid bind
+     */
+    @Test
+    public void testDoubleSimpleBindValid() throws Exception
+    {
+        BindResponse response1 = connection.bind( "uid=admin,ou=system", "secret" );
+        LdapResult ldapResult1 = response1.getLdapResult();
+        assertEquals( ResultCodeEnum.SUCCESS, ldapResult1.getResultCode() );
+        assertEquals( 1, response1.getMessageId() );
+        assertTrue( connection.isAuthenticated() );
+        
+        // The messageId must have been incremented
+        BindResponse response2 = connection.bind( "uid=admin,ou=system", "secret" );
+        LdapResult ldapResult2 = response2.getLdapResult();
+        assertEquals( ResultCodeEnum.SUCCESS, ldapResult2.getResultCode() );
+        assertEquals( 2, response2.getMessageId() );
+        assertTrue( connection.isAuthenticated() );
+        
+        // Now, unbind
+        connection.unBind();
+        assertFalse( connection.isAuthenticated() );
+        assertFalse( connection.isConnected() );
+        
+        // And Bind again. The messageId should be 1 
+        BindResponse response3 = connection.bind( "uid=admin,ou=system", "secret" );
+        LdapResult ldapResult3 = response3.getLdapResult();
+        assertEquals( ResultCodeEnum.SUCCESS, ldapResult3.getResultCode() );
+        assertEquals( 1, response3.getMessageId() );
+        assertTrue( connection.isAuthenticated() );
+    }
+
+    
+    /**
+     * Test that we can't send another request until the BindResponse arrives
+     */
+    @Test
+    public void testRequestWhileBinding() throws Exception
+    {
+        try
+        {
+            // Inject the interceptor that waits 1 second when binding 
+            // in order to be able to send a request before we get the response
+            service.getInterceptorChain().addFirst( new BaseInterceptor()
+                {
+                /**
+                 * Wait 1 second before going any further
+                 */
+                public void bind( NextInterceptor next, BindOperationContext opContext ) throws Exception
+                {
+                    // Wait 1 second
+                    Thread.sleep( 1000 );
+                    
+                    next.bind( opContext );
+                }
+            } );
+            
+            // Send another BindRequest
+            BindRequest bindRequest = new BindRequest();
+            bindRequest.setName( "uid=admin,ou=system" );
+            bindRequest.setCredentials( "secret" );
+            
+            BindFuture bindFuture = connection.bindAsync( bindRequest );
+            
+            // Wait a bit to be sure the server is processing the bind request
+            Thread.sleep( 200 );
+            
+            // It will take 1 seconds to bind, let's send another bind request : it should fail
+            BindResponse response = connection.bind( "uid=admin,ou=system", "secret" );
+            
+            assertFalse( connection.isAuthenticated() );
+            assertEquals( ResultCodeEnum.UNWILLING_TO_PERFORM, response.getLdapResult().getResultCode() );
+            
+            // Now get back the BindResponse
+            try
+            {
+                BindResponse bindResponse = bindFuture.get( 2000, TimeUnit.MILLISECONDS );
+                
+                assertNotNull( bindResponse );
+                assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode() );
+                assertTrue( connection.isAuthenticated() );
+            }
+            catch ( TimeoutException toe )
+            {
+                fail();
+            }
+        }
+        finally
+        {
+            service.getInterceptorChain().remove( this.getClass().getName() + "$1" );
+        }
+    }
+    
+    
+    /**
+     * Bind with a new user when the connection is establish with an anonymous authent.
+     */
+    @Test
+    public void testBindUserWhenAnonymous() throws Exception
+    {
+        // Bind anonymous
+        BindResponse bindResponse = connection.bind();
+        
+        assertNotNull( bindResponse );
+        assertNotNull( bindResponse.getLdapResult() );
+        assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode() );
+        assertEquals( 1, bindResponse.getMessageId() );
+        assertTrue( connection.isAuthenticated() );
+        
+        // Now bind with some credentials
+        bindResponse = connection.bind( "uid=admin, ou=system", "secret" );
+        
+        assertNotNull( bindResponse );
+        assertNotNull( bindResponse.getLdapResult() );
+        assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode() );
+        assertEquals( 2, bindResponse.getMessageId() );
+        assertTrue( connection.isAuthenticated() );
+        
+        //And back to anonymous
+        bindResponse = connection.bind();
+        
+        assertNotNull( bindResponse );
+        assertNotNull( bindResponse.getLdapResult() );
+        assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode() );
+        assertEquals( 3, bindResponse.getMessageId() );
+        assertTrue( connection.isAuthenticated() );
+    }
+    
+    
+    /**
+     * Bind with a new user when the connection is establish with an anonymous authent.
+     */
+    @Test
+    public void testBindUserWhenAlreadyBound() throws Exception
+    {
+        // Bind with some credentials
+        BindResponse bindResponse = connection.bind( "uid=admin, ou=system", "secret" );
+        
+        assertNotNull( bindResponse );
+        assertNotNull( bindResponse.getLdapResult() );
+        assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode() );
+        assertEquals( 1, bindResponse.getMessageId() );
+        assertTrue( connection.isAuthenticated() );
+        
+        // Bind with another user
+        bindResponse = connection.bind( "uid=superuser,ou=system", "test");
+        
+        assertNotNull( bindResponse );
+        assertNotNull( bindResponse.getLdapResult() );
+        assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode() );
+        assertEquals( 2, bindResponse.getMessageId() );
+        assertTrue( connection.isAuthenticated() );
+    }
+}

Added: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java?rev=937388&view=auto
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java (added)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java Fri Apr 23 17:08:32 2010
@@ -0,0 +1,198 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.shared.client.api.operations.search;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.directory.ldap.client.api.LdapAsyncConnection;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.apache.directory.ldap.client.api.future.SearchFuture;
+import org.apache.directory.ldap.client.api.message.SearchRequest;
+import org.apache.directory.ldap.client.api.message.SearchResponse;
+import org.apache.directory.ldap.client.api.message.SearchResultDone;
+import org.apache.directory.ldap.client.api.message.SearchResultEntry;
+import org.apache.directory.server.annotations.CreateLdapServer;
+import org.apache.directory.server.annotations.CreateTransport;
+import org.apache.directory.server.core.annotations.ApplyLdifs;
+import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
+import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.shared.ldap.cursor.Cursor;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.filter.SearchScope;
+import org.apache.directory.shared.ldap.message.AliasDerefMode;
+import org.apache.directory.shared.ldap.name.DN;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * TODO ClientSearchRequestTest.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+@RunWith(FrameworkRunner.class)
+@CreateLdapServer(
+    transports = 
+        {
+          @CreateTransport(protocol = "LDAP"), 
+          @CreateTransport(protocol = "LDAPS") 
+        })
+@ApplyLdifs({
+    "dn: cn=user1,ou=users,ou=system",
+    "objectClass: person",
+    "objectClass: top",
+    "sn: user1 sn",
+    "cn: user1",
+    
+    // alias to the above entry
+    "dn: cn=user1-alias,ou=users,ou=system",
+    "objectClass: alias",
+    "objectClass: top",
+    "objectClass: extensibleObject",
+    "aliasedObjectName: cn=user1,ou=users,ou=system",
+    "cn: user1-alias"
+})
+public class ClientSearchRequestTest extends AbstractLdapTestUnit
+{
+    private LdapAsyncConnection connection;
+
+    @Before
+    public void setup() throws Exception
+    {
+        connection = new LdapNetworkConnection( "localhost", ldapServer.getPort() );
+        DN bindDn = new DN( "uid=admin,ou=system" );
+        connection.bind( bindDn.getName(), "secret" );
+    }
+
+
+    /**
+     * Close the LdapConnection
+     */
+    @After
+    public void shutdown()
+    {
+        try
+        {
+            if ( connection != null )
+            {
+                connection.close();
+            }
+        }
+        catch ( Exception ioe )
+        {
+            fail();
+        }
+    }
+
+
+    @Test
+    public void testSearch() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "ou=system", "(objectclass=*)", SearchScope.ONELEVEL, "*",
+            "+" );
+        int count = 0;
+        while ( cursor.next() )
+        {
+            assertNotNull( cursor.get() );
+            count++;
+        }
+
+        assertEquals( 5, count );
+    }
+    
+
+    @Test
+    public void testSearchEquality() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "ou=system", "(objectclass=organizationalUnit)", SearchScope.ONELEVEL, "*",
+            "+" );
+        int count = 0;
+        while ( cursor.next() )
+        {
+            Entry entry = ( ( SearchResultEntry ) cursor.get() ).getEntry();
+            assertNotNull(  entry );
+            count++;
+        }
+        
+        assertEquals( 4, count );
+    }
+    
+    
+    @Test
+    public void testAsyncSearch() throws Exception
+    {
+        SearchFuture searchFuture = connection.searchAsync( "ou=system", "(objectclass=*)", SearchScope.ONELEVEL, "*",
+            "+" );
+        int count = 0;
+        SearchResponse searchResponse = null;
+        do
+        {
+            searchResponse = ( SearchResponse ) searchFuture.get( 1000, TimeUnit.MILLISECONDS );
+            assertNotNull( searchResponse );
+            if( !( searchResponse instanceof SearchResultDone ) )
+            {
+                count++;
+            }
+        }
+        while ( !( searchResponse instanceof SearchResultDone ) );
+
+        assertEquals( 5, count );
+    }
+
+    
+    @Test
+    public void testSearchWithDerefAlias() throws Exception
+    {
+        SearchRequest searchRequest = new SearchRequest();
+        searchRequest.setBaseDn( "ou=users,ou=system" );
+        searchRequest.setFilter( "(objectClass=*)" );
+        searchRequest.setScope( SearchScope.ONELEVEL );
+        searchRequest.addAttributes( "*" );
+        
+        int count = 0;
+        Cursor<SearchResponse> cursor = connection.search( searchRequest );
+        while( cursor.next() )
+        {
+            count++;
+        }
+        
+        // due to dereferencing of aliases we get only one entry
+        assertEquals( 1, count );
+
+        count = 0;
+        searchRequest.setDerefAliases( AliasDerefMode.NEVER_DEREF_ALIASES );
+        cursor = connection.search( searchRequest );
+        while( cursor.next() )
+        {
+            count++;
+        }
+        
+        assertEquals( 2, count );
+    }
+}

Added: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java?rev=937388&view=auto
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java (added)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java Fri Apr 23 17:08:32 2010
@@ -0,0 +1,514 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.shared.client.api.operations.search;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.message.SearchResponse;
+import org.apache.directory.ldap.client.api.message.SearchResultEntry;
+import org.apache.directory.server.annotations.CreateLdapServer;
+import org.apache.directory.server.annotations.CreateTransport;
+import org.apache.directory.server.core.annotations.ApplyLdifs;
+import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
+import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.shared.ldap.cursor.Cursor;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.filter.SearchScope;
+import org.apache.directory.shared.ldap.name.DN;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * A class to test the search operation with a returningAttributes parameter
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+@RunWith(FrameworkRunner.class)
+@CreateLdapServer(
+    transports = 
+        {
+          @CreateTransport(protocol = "LDAP"), 
+          @CreateTransport(protocol = "LDAPS") 
+        })
+@ApplyLdifs({
+    "dn: cn=user1,ou=users,ou=system",
+    "objectClass: person",
+    "objectClass: top",
+    "sn: user1 sn",
+    "cn: user1",
+    
+    // alias to the above entry
+    "dn: cn=user1-alias,ou=users,ou=system",
+    "objectClass: alias",
+    "objectClass: top",
+    "objectClass: extensibleObject",
+    "aliasedObjectName: cn=user1,ou=users,ou=system",
+    "cn: user1-alias"
+})
+public class SearchRequestReturningAttributesTest extends AbstractLdapTestUnit
+{
+    private LdapConnection connection;
+
+    @Before
+    public void setup() throws Exception
+    {
+        connection = new LdapNetworkConnection( "localhost", ldapServer.getPort() );
+        DN bindDn = new DN( "uid=admin,ou=system" );
+        connection.bind( bindDn.getName(), "secret" );
+    }
+
+
+    /**
+     * Close the LdapConnection
+     */
+    @After
+    public void shutdown()
+    {
+        try
+        {
+            if ( connection != null )
+            {
+                connection.close();
+            }
+        }
+        catch ( Exception ioe )
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test a search requesting all the attributes (* and +)
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchAll() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system", "(objectclass=*)", SearchScope.OBJECT, "*",
+            "+" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 7, entry.size() );
+        assertTrue( entry.containsAttribute( "objectClass" ) );
+        assertTrue( entry.containsAttribute( "cn" ) );
+        assertTrue( entry.containsAttribute( "sn" ) );
+        assertTrue( entry.containsAttribute( "creatorsName" ) );
+        assertTrue( entry.containsAttribute( "createTimestamp" ) );
+        assertTrue( entry.containsAttribute( "entryUUID" ) );
+        assertTrue( entry.containsAttribute( "entryCSN" ) );
+    }
+
+
+    /**
+     * Test a search requesting all the user attributes (*)
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchAllUsers() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system", "(objectclass=*)", SearchScope.OBJECT, "*" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 3, entry.size() );
+        assertTrue( entry.containsAttribute( "objectClass" ) );
+        assertTrue( entry.containsAttribute( "cn" ) );
+        assertTrue( entry.containsAttribute( "sn" ) );
+    }
+
+
+    /**
+     * Test a search requesting all the operational attributes (+)
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchAllOperationals() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system", "(objectclass=*)", SearchScope.OBJECT, "+" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 4, entry.size() );
+        assertTrue( entry.containsAttribute( "creatorsName" ) );
+        assertTrue( entry.containsAttribute( "createTimestamp" ) );
+        assertTrue( entry.containsAttribute( "entryUUID" ) );
+        assertTrue( entry.containsAttribute( "entryCSN" ) );
+    }
+
+
+    /**
+     * Test a search requesting all the user attributes plus a couple of operational
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchAllUsersAndSomeOperationals() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system", "(objectclass=*)", SearchScope.OBJECT, "*",
+            "entryCSN", "entryUUID" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 5, entry.size() );
+        assertTrue( entry.containsAttribute( "objectClass" ) );
+        assertTrue( entry.containsAttribute( "cn" ) );
+        assertTrue( entry.containsAttribute( "sn" ) );
+        assertTrue( entry.containsAttribute( "entryUUID" ) );
+        assertTrue( entry.containsAttribute( "entryCSN" ) );
+    }
+
+
+    /**
+     * Test a search requesting all the operational attributes and a couple of users attributes
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchAllOperationalAndSomeUsers() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system", "(objectclass=*)", SearchScope.OBJECT, "+",
+            "cn", "sn" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 6, entry.size() );
+        assertTrue( entry.containsAttribute( "cn" ) );
+        assertTrue( entry.containsAttribute( "sn" ) );
+        assertTrue( entry.containsAttribute( "creatorsName" ) );
+        assertTrue( entry.containsAttribute( "createTimestamp" ) );
+        assertTrue( entry.containsAttribute( "entryUUID" ) );
+        assertTrue( entry.containsAttribute( "entryCSN" ) );
+    }
+
+
+    /**
+     * Test a search requesting some user and Operational attributes
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchSomeOpsAndUsers() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system", "(objectclass=*)", SearchScope.OBJECT, 
+            "cn", "entryUUID", "sn", "entryCSN" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 4, entry.size() );
+        assertTrue( entry.containsAttribute( "cn" ) );
+        assertTrue( entry.containsAttribute( "sn" ) );
+        assertTrue( entry.containsAttribute( "entryUUID" ) );
+        assertTrue( entry.containsAttribute( "entryCSN" ) );
+    }
+
+
+    /**
+     * Test a search requesting some attributes which appear more than one
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchWithDuplicatedAttrs() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system", "(objectclass=*)", SearchScope.OBJECT, 
+            "cn", "entryUUID", "cn", "sn", "entryCSN", "entryUUID" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 4, entry.size() );
+        assertTrue( entry.containsAttribute( "cn" ) );
+        assertTrue( entry.containsAttribute( "sn" ) );
+        assertTrue( entry.containsAttribute( "entryUUID" ) );
+        assertTrue( entry.containsAttribute( "entryCSN" ) );
+    }
+
+
+    /**
+     * Test a search requesting some attributes using text and OID, and duplicated
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchWithOIDAndtext() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system", "(objectclass=*)", SearchScope.OBJECT, 
+            "cn", "1.3.6.1.1.16.4", "surName", "entryCSN", "entryUUID" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 4, entry.size() );
+        assertTrue( entry.containsAttribute( "cn" ) );
+        assertTrue( entry.containsAttribute( "sn" ) );
+        assertTrue( entry.containsAttribute( "entryUUID" ) );
+        assertTrue( entry.containsAttribute( "entryCSN" ) );
+    }
+
+
+    /**
+     * Test a search requesting some attributes which are not present
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchWithMissingAttributes() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system", "(objectclass=*)", SearchScope.OBJECT, 
+            "cn", "1.3.6.1.1.16.4", "gn", "entryCSN", "entryUUID" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 3, entry.size() );
+        assertTrue( entry.containsAttribute( "cn" ) );
+        assertTrue( entry.containsAttribute( "entryUUID" ) );
+        assertTrue( entry.containsAttribute( "entryCSN" ) );
+    }
+
+
+    /**
+     * Test a search requesting no attributes (1.1)
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchNoAttributes() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system", "(objectclass=*)", SearchScope.OBJECT, 
+            "1.1" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 0, entry.size() );
+    }
+
+
+    /**
+     * Test a search requesting no attributes (1.1) and some attributes
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchNoAttributesAndAttributes() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system", "(objectclass=*)", SearchScope.OBJECT, 
+            "1.1", "cn" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 1, entry.size() );
+        assertTrue( entry.containsAttribute( "cn" ) );
+    }
+
+
+    /**
+     * Test a search requesting no attributes (1.1) and all attributes (*, +)
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchNoAttributesAllAttributes() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system", "(objectclass=*)", SearchScope.OBJECT, 
+            "1.1", "*", "+" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        
+        assertEquals( 7, entry.size() );
+        assertTrue( entry.containsAttribute( "objectClass" ) );
+        assertTrue( entry.containsAttribute( "cn" ) );
+        assertTrue( entry.containsAttribute( "sn" ) );
+        assertTrue( entry.containsAttribute( "creatorsName" ) );
+        assertTrue( entry.containsAttribute( "createTimestamp" ) );
+        assertTrue( entry.containsAttribute( "entryUUID" ) );
+        assertTrue( entry.containsAttribute( "entryCSN" ) );
+    }
+}

Added: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/perf/TestClientApiPerf.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/perf/TestClientApiPerf.java?rev=937388&view=auto
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/perf/TestClientApiPerf.java (added)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/perf/TestClientApiPerf.java Fri Apr 23 17:08:32 2010
@@ -0,0 +1,204 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.client.api.perf;
+
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.message.SearchResponse;
+import org.apache.directory.ldap.client.api.message.SearchResultEntry;
+import org.apache.directory.server.annotations.CreateLdapServer;
+import org.apache.directory.server.annotations.CreateTransport;
+import org.apache.directory.server.core.annotations.ContextEntry;
+import org.apache.directory.server.core.annotations.CreateDS;
+import org.apache.directory.server.core.annotations.CreateIndex;
+import org.apache.directory.server.core.annotations.CreatePartition;
+import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
+import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.shared.ldap.cursor.Cursor;
+import org.apache.directory.shared.ldap.filter.SearchScope;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Tests for comparing performance of client API against various other LDAP client APIs
+ *  (currently only compared against JNDI )
+ * 
+ * TODO print the performance results in a neat tabular fashion 
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+@RunWith(FrameworkRunner.class)
+@CreateDS( 
+    name = "ClientApiPerfTestDS",
+    partitions =
+    {
+        @CreatePartition(
+            name = "example",
+            suffix = "dc=example,dc=com",
+            contextEntry = @ContextEntry( 
+                entryLdif =
+                    "dn: dc=example,dc=com\n" +
+                    "dc: example\n" +
+                    "objectClass: top\n" +
+                    "objectClass: domain\n\n" ),
+            indexes = 
+            {
+                @CreateIndex( attribute = "objectClass" ),
+                @CreateIndex( attribute = "dc" ),
+                @CreateIndex( attribute = "ou" )
+            } )
+    } )
+@CreateLdapServer ( 
+    transports = 
+    {
+        @CreateTransport( protocol = "LDAP" ), 
+        @CreateTransport( protocol = "LDAPS" ) 
+    })
+public class TestClientApiPerf extends AbstractLdapTestUnit
+{
+
+    @Test
+    public void testSearchPerformance() throws Exception
+    {
+        long t1 = System.currentTimeMillis();
+
+        // Create connection
+        LdapConnection connection = new LdapNetworkConnection( "localhost", ldapServer.getPort() );
+        connection.bind( "uid=admin,ou=system", "secret" );
+
+        long t2 = System.currentTimeMillis();
+
+        Cursor<SearchResponse> cursor = connection.search( "dc=example,dc=com", "(objectClass=*)", SearchScope.SUBTREE,
+            "*" );
+        while ( cursor.next() )
+        {
+            SearchResponse sr = cursor.get();
+            SearchResultEntry sre = ( SearchResultEntry ) sr;
+        }
+
+        cursor.close();
+
+        long t3 = System.currentTimeMillis();
+
+        connection.close();
+
+        long t4 = System.currentTimeMillis();
+
+        System.out.println( "============== Client API =============" );
+        System.out.println( "Time to create the connection: " + getElapsedTime( t1, t2 ) );
+        System.out.println( "Time to perform the search: " + getElapsedTime( t2, t3 ) );
+        System.out.println( "Time to close the connection: " + getElapsedTime( t3, t4 ) );
+        System.out.println( "Total time: " + getElapsedTime( t1, t4 ) );
+        System.out.println( "=======================================" );
+    }
+
+
+    @Test
+    public void testSearchPerfWithJndi() throws NamingException
+    {
+        long t1 = System.currentTimeMillis();
+
+        // Getting the connection
+        DirContext ctx = jndiEnv( "localhost", ldapServer.getPort(), "", "uid=admin,ou=system", "secret", false );
+
+        long t2 = System.currentTimeMillis();
+
+        // Preparing the search controls
+        SearchControls searchControls = new SearchControls();
+        searchControls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+        searchControls.setReturningAttributes( new String[]
+            { "*" } );
+
+        // Searching
+        NamingEnumeration<SearchResult> ne = ctx.search( "dc=example,dc=com", "objectClass=*", searchControls );
+        while ( ne.hasMoreElements() )
+        {
+            SearchResult searchResult = ( SearchResult ) ne.nextElement();
+        }
+        ne.close();
+
+        long t3 = System.currentTimeMillis();
+
+        // Closing the connection
+        ctx.close();
+
+        long t4 = System.currentTimeMillis();
+
+        System.out.println( "================= JNDI ================" );
+        System.out.println( "Time to create the connection: " + getElapsedTime( t1, t2 ) );
+        System.out.println( "Time to perform the search: " + getElapsedTime( t2, t3 ) );
+        System.out.println( "Time to close the connection: " + getElapsedTime( t3, t4 ) );
+        System.out.println( "Total time: " + getElapsedTime( t1, t4 ) );
+        System.out.println( "=======================================" );
+    }
+
+
+    /**
+     * Creates the Jndi Context.
+     * 
+     * @param host
+     *            the server host
+     * @param port
+     *            the server port
+     * @param base
+     *            the Active Directory Base
+     * @param principal
+     *            the Active Directory principal
+     * @param credentials
+     *            the Active Directory credentials
+     * @return the jndi context
+     * @throws NamingException
+     */
+    private DirContext jndiEnv( String host, int port, String base, String principal, String credentials, boolean ssl )
+        throws NamingException
+    {
+        Hashtable<String, String> env = new Hashtable<String, String>();
+
+        env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
+        env.put( Context.PROVIDER_URL, "ldap://" + host + ":" + port + "/" + base );
+        env.put( Context.SECURITY_PRINCIPAL, principal );
+        env.put( Context.SECURITY_CREDENTIALS, credentials );
+        if ( ssl )
+        {
+            env.put( Context.SECURITY_PROTOCOL, "ssl" );
+        }
+
+        return new InitialDirContext( env );
+    }
+
+
+    private long getElapsedTime( long t1, long t2 )
+    {
+        return ( t2 - t1 );
+    }
+}

Added: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/utils/SASLPrep.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/utils/SASLPrep.java?rev=937388&view=auto
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/utils/SASLPrep.java (added)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/utils/SASLPrep.java Fri Apr 23 17:08:32 2010
@@ -0,0 +1,32 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.client.api.utils;
+
+/**
+ * This class implement the RFC 4013. It contains methods to prepare
+ * String passwords before the client API can send them to the server.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SASLPrep
+{
+
+}

Added: directory/apacheds/trunk/ldap-client-test/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/resources/log4j.properties?rev=937388&view=auto
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/resources/log4j.properties (added)
+++ directory/apacheds/trunk/ldap-client-test/src/test/resources/log4j.properties Fri Apr 23 17:08:32 2010
@@ -0,0 +1,27 @@
+#############################################################################
+#    Licensed to the Apache Software Foundation (ASF) under one or more
+#    contributor license agreements.  See the NOTICE file distributed with
+#    this work for additional information regarding copyright ownership.
+#    The ASF licenses this file to You under the Apache License, Version 2.0
+#    (the "License"); you may not use this file except in compliance with
+#    the License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+#############################################################################
+log4j.rootCategory=OFF, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss}] %p [%c] - %m%n
+
+#log4j.logger.org.apache.directory.shared.client.api=DEBUG
+log4j.logger.org.apache.directory.shared.asn1.ber=OFF
+log4j.logger.org.apache.directory.ldap.client.api=OFF
+log4j.logger.org.apache.directory.ldap.client.api.protocol.LdapProtocolDecoder=OFF
+log4j.logger.org.apache.directory.ldap.client.api.LdapConnection=OFF
\ No newline at end of file