directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r905353 - in /directory/clients/ldap/trunk: ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
Date Mon, 01 Feb 2010 18:22:33 GMT
Author: kayyagari
Date: Mon Feb  1 18:22:32 2010
New Revision: 905353

URL: http://svn.apache.org/viewvc?rev=905353&view=rev
Log:
o added a new method lookup() to search and fetch a single entry
o added a test case for the lookup operation
o cleaned up the test case code

Modified:
    directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
    directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java

Modified: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java?rev=905353&r1=905352&r2=905353&view=diff
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
(original)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
Mon Feb  1 18:22:32 2010
@@ -2700,6 +2700,46 @@
 
 
     /**
+     * @see #lookup(String, String...)
+     */
+    public SearchResponse lookup( String dn ) throws LdapException
+    {
+        return lookup( dn, SchemaConstants.ALL_USER_ATTRIBUTES_ARRAY );
+    }
+    
+    
+    /**
+     * searches for an entry having the given DN
+     *
+     * @param dn the DN of the entry to be fetched
+     * @param attributes the attributes to be returned along with entry
+     * @return the Entry with the given DN or null if no entry exists with that DN
+     * @throws LdapException in case of any problems while searching for the DN
+     */
+    public SearchResponse lookup( String dn, String... attributes ) throws LdapException
+    {
+        SearchResponse resp = null;
+        
+        try
+        {
+            Cursor<SearchResponse> cursor = search( dn, "(objectClass=*)", SearchScope.OBJECT,
attributes );
+            if( cursor.next() )
+            {
+                resp = cursor.get();
+            }
+            
+            cursor.close();
+        }
+        catch( Exception e )
+        {
+            throw new LdapException( e );
+        }
+
+        return resp;
+    }
+    
+
+    /**
      * converts the ExtendedResponseCodec to ExtendedResponse.
      */
     private ExtendedResponse convert( ExtendedResponseCodec extRespCodec )

Modified: directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java?rev=905353&r1=905352&r2=905353&view=diff
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
(original)
+++ directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
Mon Feb  1 18:22:32 2010
@@ -21,6 +21,7 @@
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.fail;
 
 import java.io.IOException;
@@ -29,11 +30,16 @@
 import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.ldap.client.api.exception.LdapException;
 import org.apache.directory.ldap.client.api.message.BindResponse;
+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.integ.AbstractLdapTestUnit;
 import org.apache.directory.server.core.integ.FrameworkRunner;
-import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -53,6 +59,24 @@
 public class LdapConnectionTest extends AbstractLdapTestUnit
 {
     
+    private LdapConnection connection;
+    
+    
+    @Before
+    public void bindConnection() throws Exception
+    {
+        connection = new LdapConnection( "localhost", ldapServer.getPort() );
+        connection.bind( "uid=admin,ou=system", "secret" );
+    }
+    
+    
+    @After
+    public void unbindConnection() throws Exception
+    {
+        connection.unBind();
+    }
+    
+    
     /**
      * Test a successful bind request
      *
@@ -62,7 +86,6 @@
     public void testBindRequest() throws Exception
     {
         LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort()
);
-        
         try
         {
             BindResponse bindResponse = connection.bind( "uid=admin,ou=system", "secret"
);
@@ -96,13 +119,24 @@
     @Test
     public void testGetSupportedControls() throws Exception
     {
-        LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort()
);
-
-        LdapDN dn = new LdapDN( "uid=admin,ou=system" );
-        connection.bind( dn.getName(), "secret" );
-        
         List<String> controlList = connection.getSupportedControls();
         assertNotNull( controlList );
         assertFalse( controlList.isEmpty() );
     }
+    
+    
+    @Test
+    public void testLookup() throws Exception
+    {
+        SearchResponse resp = connection.lookup( "uid=admin,ou=system" );
+        assertNotNull( resp );
+        
+        Entry entry = ( ( SearchResultEntry ) resp ).getEntry();
+        assertNull( entry.get( SchemaConstants.ENTRY_UUID_AT ) );
+
+        // perform lookup with operational attributes
+        resp = connection.lookup( "uid=admin,ou=system", "+", "*" );
+        entry = ( ( SearchResultEntry ) resp ).getEntry();
+        assertNotNull( entry.get( SchemaConstants.ENTRY_UUID_AT ) );
+    }
 }



Mime
View raw message