directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r771451 - /directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
Date Mon, 04 May 2009 21:29:38 GMT
Author: elecharny
Date: Mon May  4 21:29:38 2009
New Revision: 771451

URL: http://svn.apache.org/viewvc?rev=771451&view=rev
Log:
Added a test for AsyncBind

Modified:
    directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java

Modified: directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java?rev=771451&r1=771450&r2=771451&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
(original)
+++ directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
Mon May  4 21:29:38 2009
@@ -27,7 +27,12 @@
 import org.apache.directory.server.ldap.LdapService;
 import org.apache.directory.shared.ldap.client.api.LdapConnection;
 import org.apache.directory.shared.ldap.client.api.exception.LdapException;
+import org.apache.directory.shared.ldap.client.api.listeners.BindListener;
+import org.apache.directory.shared.ldap.client.api.messages.BindRequest;
+import org.apache.directory.shared.ldap.client.api.messages.BindRequestImpl;
 import org.apache.directory.shared.ldap.client.api.messages.BindResponse;
+import org.apache.directory.shared.ldap.client.api.messages.future.BindFuture;
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -47,7 +52,14 @@
 {
     /** The server instance */
     public static LdapService ldapService;
+    
+    private static boolean responseReceived = false;
 
+    @Before
+    public void init()
+    {
+        responseReceived = false;
+    }
     
     /**
      * Test a successful bind request
@@ -61,25 +73,70 @@
         
         try
         {
-            assertTrue( connection.connect() );
+            BindResponse bindResponse = connection.bind( "uid=admin,ou=system", "secret"
);
+            
+            assertNotNull( bindResponse );
+            
+            connection.unBind();
         }
-        catch ( IOException ioe )
+        catch ( LdapException le )
         {
             fail();
         }
+        finally
+        {
+            try
+            {
+                connection.close();
+            }
+            catch( IOException ioe )
+            {
+                fail();
+            }
+        }
+    }
+
+
+    /**
+     * Test a successful asynchronous bind request
+     *
+     * @throws IOException
+     */
+    @Test
+    public void testAsyncBindRequest()
+    {
+        LdapConnection connection = new LdapConnection( "localhost", ldapService.getPort()
);
         
         try
         {
-            BindResponse bindResponse = connection.bind( "uid=admin,ou=system", "secret"
);
+            BindRequest bindRequest = new BindRequestImpl();
+            bindRequest.setCredentials( "secret" );
+            bindRequest.setName( "uid=admin,ou=system" );
             
-            assertNotNull( bindResponse );
+            connection.bind( bindRequest, new BindListener() 
+                {
+                    public void bindCompleted( LdapConnection connection, BindResponse bindResponse
) throws LdapException
+                    {
+                        assertNotNull( bindResponse );
+                        responseReceived = true;
+                    }
+                } );
+
+            // Wait a bit
+            Thread.sleep( 1000 );
             
-            //connection.unBind();
+            assertTrue( responseReceived );
+            
+            connection.unBind();
         }
         catch ( LdapException le )
         {
             fail();
         }
+        catch ( InterruptedException ie )
+        {
+            fail();
+        }
         finally
         {
             try



Mime
View raw message