directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r905507 - in /directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations: compare/CompareIT.java delete/DeleteIT.java modify/IllegalModificationIT.java search/SearchIT.java
Date Tue, 02 Feb 2010 03:58:14 GMT
Author: kayyagari
Date: Tue Feb  2 03:57:57 2010
New Revision: 905507

URL: http://svn.apache.org/viewvc?rev=905507&view=rev
Log:
updated some more tests to use client-api's LdapConnection

Modified:
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/compare/CompareIT.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/delete/DeleteIT.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/IllegalModificationIT.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/compare/CompareIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/compare/CompareIT.java?rev=905507&r1=905506&r2=905507&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/compare/CompareIT.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/compare/CompareIT.java
Tue Feb  2 03:57:57 2010
@@ -20,6 +20,7 @@
 package org.apache.directory.server.operations.compare;
 
 
+import static org.apache.directory.server.integ.ServerIntegrationUtils.getClientApiConnection;
 import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredConnection;
 import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContextThrowOnRefferal;
 import static org.junit.Assert.assertEquals;
@@ -41,6 +42,8 @@
 import netscape.ldap.LDAPResponse;
 import netscape.ldap.LDAPResponseListener;
 
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.message.CompareResponse;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
 import org.apache.directory.server.core.annotations.ApplyLdifs;
@@ -104,17 +107,17 @@
     @Test
     public void testNormalCompare() throws Exception
     {
-        LDAPConnection conn = getWiredConnection( ldapServer );
+        LdapConnection conn = getClientApiConnection( ldapServer );
         
         // comparison success
-        LDAPAttribute attribute = new LDAPAttribute( "sn", "karasulu" );
-        assertTrue( conn.compare( "uid=akarasulu,ou=users,ou=system", attribute ) );
+        CompareResponse resp = conn.compare( "uid=akarasulu,ou=users,ou=system", "sn", "karasulu"
);
+        assertEquals( ResultCodeEnum.COMPARE_TRUE, resp.getLdapResult().getResultCode() );
 
         // comparison failure
-        attribute = new LDAPAttribute( "sn", "lecharny" );
-        assertFalse( conn.compare( "uid=akarasulu,ou=users,ou=system", attribute ) );
+        resp = conn.compare( "uid=akarasulu,ou=users,ou=system", "sn", "lecharny" );
+        assertEquals( ResultCodeEnum.COMPARE_FALSE, resp.getLdapResult().getResultCode()
);
         
-        conn.disconnect();
+        conn.unBind();
     }
     
     

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/delete/DeleteIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/delete/DeleteIT.java?rev=905507&r1=905506&r2=905507&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/delete/DeleteIT.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/delete/DeleteIT.java
Tue Feb  2 03:57:57 2010
@@ -20,6 +20,7 @@
 package org.apache.directory.server.operations.delete;
 
 
+import static org.apache.directory.server.integ.ServerIntegrationUtils.getClientApiConnection;
 import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredConnection;
 import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContextThrowOnRefferal;
 import static org.junit.Assert.assertEquals;
@@ -38,6 +39,9 @@
 import netscape.ldap.LDAPResponseListener;
 import netscape.ldap.LDAPSearchConstraints;
 
+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.DeleteResponse;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
 import org.apache.directory.server.core.annotations.ApplyLdifs;
@@ -102,20 +106,13 @@
     @Test
     public void testNormalDeleteFailContextNotEmpty() throws Exception
     {
-        LDAPConnection conn = getWiredConnection( ldapServer );
+        LdapConnection conn = getClientApiConnection( ldapServer );
         
         // delete failure on non-leaf entry
-        try
-        {
-            conn.delete( "uid=akarasulu,ou=users,ou=system" );
-            fail( "Should never get here." );
-        }
-        catch ( LDAPException e )
-        {
-            assertEquals( ResultCodeEnum.NOT_ALLOWED_ON_NON_LEAF.getValue(), e.getLDAPResultCode()
);
-        }
-        
-        conn.disconnect();
+        DeleteResponse resp = conn.delete( "uid=akarasulu,ou=users,ou=system" );
+        assertEquals( ResultCodeEnum.NOT_ALLOWED_ON_NON_LEAF, resp.getLdapResult().getResultCode()
);
+
+        conn.unBind();
     }
     
     
@@ -126,23 +123,16 @@
     @Test
     public void testNormalDelete() throws Exception
     {
-        LDAPConnection conn = getWiredConnection( ldapServer );
+        LdapConnection conn = getClientApiConnection( ldapServer );
         
         // delete success
         conn.delete( "ou=computers,uid=akarasulu,ou=users,ou=system" );
 
         // delete failure non-existant entry
-        try
-        {
-            conn.delete( "uid=elecharny,ou=users,ou=system" );
-            fail( "Should never get here." );
-        }
-        catch ( LDAPException e )
-        {
-            assertEquals( ResultCodeEnum.NO_SUCH_OBJECT.getValue(), e.getLDAPResultCode()
);
-        }
+        DeleteResponse resp = conn.delete( "uid=elecharny,ou=users,ou=system" );
+        assertEquals( ResultCodeEnum.NO_SUCH_OBJECT, resp.getLdapResult().getResultCode()
);
         
-        conn.disconnect();
+        conn.unBind();
     }
     
     
@@ -153,20 +143,13 @@
     @Test
     public void testDeleteNonExistent() throws Exception
     {
-        LDAPConnection conn = getWiredConnection( ldapServer );
+        LdapConnection conn = getClientApiConnection( ldapServer );
         
         // delete failure non-existent entry
-        try
-        {
-            conn.delete( "uid=elecharny,ou=users,ou=system" );
-            fail( "Should never get here." );
-        }
-        catch ( LDAPException e )
-        {
-            assertEquals( ResultCodeEnum.NO_SUCH_OBJECT.getValue(), e.getLDAPResultCode()
);
-        }
+        DeleteResponse resp = conn.delete( "uid=elecharny,ou=users,ou=system" );
+        assertEquals( ResultCodeEnum.NO_SUCH_OBJECT, resp.getLdapResult().getResultCode()
);
         
-        conn.disconnect();
+        conn.unBind();
     }
     
     
@@ -296,22 +279,22 @@
     
 
     /**
-     * Try to delete an entry with invalid DN. Expected result code is 32
-     * (NO_SUCH_OBJECT) or 34 (INVALID_DN_SYNTAX).
+     * Try to delete an entry with invalid DN. The operation fails
+     * during parsing the given DN
      */
+    @Test
     public void testDeleteWithIllegalName() throws Exception 
     {
-        LDAPConnection conn = getWiredConnection( ldapServer );
+        LdapConnection conn = getClientApiConnection( ldapServer );
         
         try 
         {
             conn.delete("This is an illegal name,dc=example,dc=com" );
             fail( "deletion should fail" );
         } 
-        catch ( LDAPException e ) 
+        catch ( LdapException e ) 
         {
-            assertTrue( e.getLDAPResultCode() == LDAPException.INVALID_DN_SYNTAX || 
-                        e.getLDAPResultCode() == LDAPException.NO_SUCH_OBJECT );
+            // expected
         }
     }
 }

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/IllegalModificationIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/IllegalModificationIT.java?rev=905507&r1=905506&r2=905507&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/IllegalModificationIT.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modify/IllegalModificationIT.java
Tue Feb  2 03:57:57 2010
@@ -20,6 +20,7 @@
 package org.apache.directory.server.operations.modify;
 
 
+import static org.apache.directory.server.integ.ServerIntegrationUtils.getClientApiConnection;
 import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredConnection;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
@@ -29,11 +30,19 @@
 import netscape.ldap.LDAPException;
 import netscape.ldap.LDAPModification;
 
+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.ModifyRequest;
+import org.apache.directory.ldap.client.api.message.ModifyResponse;
+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.entry.Entry;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -82,23 +91,17 @@
     @Test
     public void testIllegalModification() throws Exception
     {
-        LDAPConnection con = getWiredConnection( ldapServer );
-        LDAPAttribute attr = new LDAPAttribute( "description" );
-        LDAPModification mod = new LDAPModification( LDAPModification.ADD, attr );
+        LdapConnection con = getClientApiConnection( ldapServer );
 
-        try
-        {
-            con.modify( "cn=Kate Bush,ou=system", mod );
-            fail( "error expected due to empty attribute value" );
-        }
-        catch ( LDAPException e )
-        {
-            // expected
-        }
+        ModifyRequest modReq = new ModifyRequest( new LdapDN( DN ) );
+        modReq.add( "description", "" );
+
+        ModifyResponse resp = con.modify( modReq, null );
+        assertEquals( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, resp.getLdapResult().getResultCode()
);
 
         // Check whether entry is unmodified, i.e. no description
-        LDAPEntry entry = con.read( DN );
-        assertEquals( "description exists?", null, entry.getAttribute( "description" ) );
+        Entry entry = ( ( SearchResultEntry )con.lookup( DN ) ).getEntry();
+        assertEquals( "description exists?", null, entry.get( "description" ) );
     }
     
     

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java?rev=905507&r1=905506&r2=905507&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java
Tue Feb  2 03:57:57 2010
@@ -45,14 +45,9 @@
 import javax.naming.directory.SearchResult;
 import javax.naming.ldap.LdapContext;
 
-import netscape.ldap.LDAPAttribute;
-import netscape.ldap.LDAPAttributeSet;
-import netscape.ldap.LDAPConnection;
-import netscape.ldap.LDAPEntry;
-import netscape.ldap.LDAPException;
-import netscape.ldap.LDAPMessage;
-import netscape.ldap.LDAPSearchListener;
-
+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.SearchResponse;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
 import org.apache.directory.server.core.annotations.ApplyLdifs;
@@ -62,8 +57,13 @@
 import org.apache.directory.server.ldap.LdapServer;
 import org.apache.directory.shared.ldap.codec.search.controls.subentries.SubentriesControl;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.cursor.Cursor;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry;
+import org.apache.directory.shared.ldap.filter.SearchScope;
 import org.apache.directory.shared.ldap.jndi.JndiUtils;
 import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -1667,41 +1667,34 @@
     @Test
     public void testAbandonnedRequest() throws Exception
     {
-        LDAPConnection asyncCnx = new LDAPConnection();
+        LdapConnection asyncCnx = new LdapConnection( "localhost", ldapServer.getPort() );
         
         try
         {
-            // Use the netscape API as JNDI cannot be used to do a search without
-            // first binding.
-            //conn.connect( 3, "localhost", ldapServer.getPort(), "uid=admin,ou=system",
"secret" );
-           
-            asyncCnx.connect( 3, "localhost", ldapServer.getPort(), "uid=admin,ou=system",
"secret" );
+            // Use the client API as JNDI cannot be used to do a search without
+            // first binding. (hmmm, even client API won't allow searching without binding)
+            asyncCnx.bind( "uid=admin,ou=system", "secret" );
             
             // First, add 1000 entries in the server
             for ( int i = 0; i < 1000; i++ )
             {
-                LDAPAttributeSet attrs = new LDAPAttributeSet();
-                LDAPAttribute ocls = new LDAPAttribute( "objectclass", new String[]
-                    { "top", "person" } );
-                attrs.add( ocls );
-                attrs.add( new LDAPAttribute( "sn", "Bush" ) );
-                attrs.add( new LDAPAttribute( "cn", "user" + i ) );
-
                 String dn = "cn=user" + i + "," + BASE;
-                LDAPEntry kate = new LDAPEntry( dn, attrs );
+                Entry kate = new DefaultClientEntry( new LdapDN( dn ) );
+
+                kate.add( "objectclass", "top", "person" );
+                kate.add( "sn", "Bush" );
+                kate.add( "cn", "user" + i );
 
                 asyncCnx.add( kate );
             }
             
             // Searches for all the entries in ou=system
-            LDAPSearchListener listener = asyncCnx.search( "ou=system", LDAPConnection.SCOPE_SUB,
-                "(ObjectClass=*)", new String[]{"*"}, false, (LDAPSearchListener)null);
+            Cursor<SearchResponse> cursor = asyncCnx.search( "ou=system", "(ObjectClass=*)",
SearchScope.SUBTREE, "*" );
 
             // Now loop on all the elements found, and abandon after 10 elements returned
             int count = 0;
-            LDAPMessage msg = null;
             
-            while ( (msg = listener.getResponse() ) != null ) 
+            while ( cursor.next() ) 
             {
                 count++;
 
@@ -1713,14 +1706,13 @@
             
             assertEquals( 100, count );
         }
-        catch ( LDAPException e )
+        catch ( LdapException e )
         {
             fail( "Should not have caught exception." );
         }
         finally
         {
-            // Reset the allowAnonymousAccess flag
-           asyncCnx.disconnect();
+           asyncCnx.unBind();
         }
     }
 



Mime
View raw message