directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1496649 - in /directory/apacheds/trunk: ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
Date Tue, 25 Jun 2013 21:54:09 GMT
Author: elecharny
Date: Tue Jun 25 21:54:08 2013
New Revision: 1496649

URL: http://svn.apache.org/r1496649
Log:
Adding tests to check that we can insert null values in Attributes that accept such addition

Modified:
    directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java

Modified: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java?rev=1496649&r1=1496648&r2=1496649&view=diff
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java
(original)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java
Tue Jun 25 21:54:08 2013
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.io.IOException;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.UUID;
@@ -37,6 +38,7 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.entry.DefaultEntry;
 import org.apache.directory.api.ldap.model.entry.Entry;
 import org.apache.directory.api.ldap.model.entry.Value;
+import org.apache.directory.api.ldap.model.exception.LdapException;
 import org.apache.directory.api.ldap.model.exception.LdapNoPermissionException;
 import org.apache.directory.api.ldap.model.ldif.LdifUtils;
 import org.apache.directory.api.ldap.model.message.AddRequest;
@@ -46,6 +48,7 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.message.controls.ManageDsaITImpl;
 import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.api.util.DateUtils;
+import org.apache.directory.api.util.Strings;
 import org.apache.directory.ldap.client.api.LdapNetworkConnection;
 import org.apache.directory.ldap.client.api.future.AddFuture;
 import org.apache.directory.server.annotations.CreateLdapServer;
@@ -78,7 +81,7 @@ public class ClientAddRequestTest extend
     @Before
     public void setup() throws Exception
     {
-        connection = (LdapNetworkConnection)LdapApiIntegrationUtils.getPooledAdminConnection(
getLdapServer() );
+        connection = ( LdapNetworkConnection ) LdapApiIntegrationUtils.getPooledAdminConnection(
getLdapServer() );
         session = getLdapServer().getDirectoryService().getAdminSession();
     }
 
@@ -259,7 +262,7 @@ public class ClientAddRequestTest extend
         }
     }
 
-    
+
     @Test
     /**
      * tests adding en entry with escaped chars in the RDN
@@ -278,13 +281,13 @@ public class ClientAddRequestTest extend
         Entry loadedEntry = connection.lookup( dn.getName(), "*" );
         assertNotNull( loadedEntry );
         assertTrue( loadedEntry.containsAttribute( "cn" ) );
-        
+
         String cn = loadedEntry.get( "cn" ).get().getString();
-        
+
         assertEquals( "a+B", cn );
     }
 
-    
+
     @Test
     /**
      * tests adding en entry with escaped chars in the RDN
@@ -304,13 +307,13 @@ public class ClientAddRequestTest extend
         Entry loadedEntry = connection.lookup( dn.getName(), "*" );
         assertNotNull( loadedEntry );
         assertTrue( loadedEntry.containsAttribute( "cn" ) );
-        
+
         String cn = loadedEntry.get( "cn" ).get().getString();
-        
+
         assertEquals( "a+b", cn );
     }
 
-    
+
     @Test
     /**
      * tests adding en entry with escaped chars in the RDN
@@ -330,26 +333,26 @@ public class ClientAddRequestTest extend
         Entry loadedEntry = connection.lookup( dn.getName(), "*" );
         assertNotNull( loadedEntry );
         assertTrue( loadedEntry.containsAttribute( "cn" ) );
-        
+
         Attribute attribute = loadedEntry.get( "cn" );
         Set<String> expected = new HashSet<String>();
         expected.add( "a+B" );
         expected.add( "c" );
         int count = 0;
-        
+
         for ( Value<?> value : attribute )
         {
             String val = value.getString();
-            
+
             assertTrue( expected.contains( val ) );
             count++;
-            
+
         }
-        
+
         assertEquals( 2, count );
     }
-    
-    
+
+
     /**
      * the below test fails cause the API is failing to
      * preserve the UP name of the attribute of RDN
@@ -369,11 +372,49 @@ public class ClientAddRequestTest extend
 
         assertTrue( session.exists( dn ) );
 
-        entry = connection.lookup(dn);
-        
-        String ldif = LdifUtils.convertToLdif(entry);
-        
-        assertTrue( ldif.contains(dn.getName()) );
+        entry = connection.lookup( dn );
+
+        String ldif = LdifUtils.convertToLdif( entry );
+
+        assertTrue( ldif.contains( dn.getName() ) );
+    }
+
+
+    @Test
+    public void testAddNullValueSchemaAware() throws LdapException, IOException
+    {
+        connection.setTimeOut( 0L );
+        connection.loadSchema();
+
+        // Use the client API
+        connection.bind( "uid=admin,ou=system", "secret" );
+
+        // Add a new entry with some null values
+        Entry entry = new DefaultEntry( getLdapServer().getDirectoryService().getSchemaManager(),
"cn=test,ou=system",
+            "ObjectClass: top",
+            "ObjectClass: person",
+            "ObjectClass: person",
+            "ObjectClass: OrganizationalPerson",
+            "ObjectClass: inetOrgPerson",
+            "cn: test",
+            "sn: Test",
+            "userPassword:",
+            "mail:" );
+
+        connection.add( entry );
+
+        // Now fetch the entry
+        Entry found = connection.lookup( "cn=test,ou=system" );
+
+        assertNotNull( found );
+        assertNotNull( found.get( "userPassword" ) );
+        assertNotNull( found.get( "mail" ) );
+        byte[] userPassword = found.get( "userPassword" ).getBytes();
+        String mail = found.get( "mail" ).getString();
+
+        assertTrue( Strings.isEmpty( userPassword ) );
+        assertTrue( Strings.isEmpty( mail ) );
+
+        connection.close();
     }
-    
 }

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java?rev=1496649&r1=1496648&r2=1496649&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
Tue Jun 25 21:54:08 2013
@@ -31,6 +31,7 @@ import static org.junit.Assert.assertNul
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.io.IOException;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.UUID;
@@ -51,6 +52,8 @@ import javax.naming.directory.SearchResu
 import javax.naming.ldap.LdapContext;
 import javax.naming.ldap.LdapName;
 
+import netscape.ldap.LDAPException;
+
 import org.apache.directory.api.ldap.model.constants.AuthenticationLevel;
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
 import org.apache.directory.api.ldap.model.csn.Csn;
@@ -1510,15 +1513,54 @@ public class AddIT extends AbstractLdapT
         assertNotNull( certificate );
         assertEquals( 1, certificate.size() );
         assertTrue( certificate.contains( Strings.getBytesUtf8( "<Hello world !>" )
) );
-        
+
         // Same check without the ";binary"
         certificate = kateReloaded.get( "userCertificate" );
         assertNotNull( certificate );
         assertEquals( 1, certificate.size() );
         assertTrue( certificate.contains( Strings.getBytesUtf8( "<Hello world !>" )
) );
-        
+
         // Remove entry
         con.delete( dn );
         con.unBind();
     }
+
+
+    @Test
+    public void testAddNullValue() throws LdapException, IOException
+    {
+        LdapConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort()
);
+        connection.setTimeOut( 0L );
+
+        // Use the client API
+        connection.bind( "uid=admin,ou=system", "secret" );
+
+        // Add a new entry with some null values
+        Entry entry = new DefaultEntry( "cn=test,ou=system",
+            "ObjectClass: top",
+            "ObjectClass: person",
+            "ObjectClass: person",
+            "ObjectClass: OrganizationalPerson",
+            "ObjectClass: inetOrgPerson",
+            "cn: test",
+            "sn: Test",
+            "userPassword:",
+            "mail:" );
+
+        connection.add( entry );
+
+        // Now fetch the entry
+        Entry found = connection.lookup( "cn=test,ou=system" );
+
+        assertNotNull( found );
+        assertNotNull( found.get( "userPassword" ) );
+        assertNotNull( found.get( "mail" ) );
+        String userPassword = found.get( "userPassword" ).getString();
+        String mail = found.get( "mail" ).getString();
+
+        assertTrue( Strings.isEmpty( userPassword ) );
+        assertTrue( Strings.isEmpty( mail ) );
+
+        connection.close();
+    }
 }



Mime
View raw message