directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r905357 - in /directory/apacheds/trunk/server-integ: pom.xml src/main/java/org/apache/directory/server/integ/ServerIntegrationUtils.java src/test/java/org/apache/directory/server/operations/add/AddIT.java
Date Mon, 01 Feb 2010 18:44:31 GMT
Author: kayyagari
Date: Mon Feb  1 18:44:30 2010
New Revision: 905357

URL: http://svn.apache.org/viewvc?rev=905357&view=rev
Log:
o added dependency on ldap-client-api
o added a utility method to create a client-api's LdapConnection
o migrated some tests of AddIT to use the new client-api's LdapConnection

Modified:
    directory/apacheds/trunk/server-integ/pom.xml
    directory/apacheds/trunk/server-integ/src/main/java/org/apache/directory/server/integ/ServerIntegrationUtils.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java

Modified: directory/apacheds/trunk/server-integ/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/pom.xml?rev=905357&r1=905356&r2=905357&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/pom.xml (original)
+++ directory/apacheds/trunk/server-integ/pom.xml Mon Feb  1 18:44:30 2010
@@ -67,6 +67,12 @@
       <artifactId>ldapsdk</artifactId>
       <version>${ldapsdk.version}</version>
     </dependency>  
+    
+    <dependency>
+      <groupId>org.apache.directory.client.ldap</groupId>
+      <artifactId>ldap-client-api</artifactId>
+      <version>0.1-SNAPSHOT</version>
+    </dependency>  
   </dependencies>
 
   <build>

Modified: directory/apacheds/trunk/server-integ/src/main/java/org/apache/directory/server/integ/ServerIntegrationUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/main/java/org/apache/directory/server/integ/ServerIntegrationUtils.java?rev=905357&r1=905356&r2=905357&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/main/java/org/apache/directory/server/integ/ServerIntegrationUtils.java
(original)
+++ directory/apacheds/trunk/server-integ/src/main/java/org/apache/directory/server/integ/ServerIntegrationUtils.java
Mon Feb  1 18:44:30 2010
@@ -27,6 +27,7 @@
 
 import netscape.ldap.LDAPConnection;
 
+import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.integ.IntegrationUtils;
 import org.apache.directory.server.ldap.LdapServer;
@@ -48,7 +49,6 @@
     private static final String DEFAULT_PASSWORD = "secret";
 
 
-
     /**
      * Creates a JNDI LdapContext with a connection over the wire using the 
      * SUN LDAP provider.  The connection is made using the administrative 
@@ -73,7 +73,7 @@
      * @return an LdapContext as the administrative user to the RootDSE
      * @throws Exception if there are problems creating the context
      */
-    public static LdapContext getWiredContext( LdapServer ldapServer, String principalDn,
String password ) 
+    public static LdapContext getWiredContext( LdapServer ldapServer, String principalDn,
String password )
         throws Exception
     {
         LOG.debug( "Creating a wired context to local LDAP server on port {}", ldapServer.getPort()
);
@@ -108,7 +108,7 @@
         return new InitialLdapContext( env, JndiUtils.toJndiControls( controls ) );
     }
 
-    
+
     /**
      * Creates a JNDI LdapContext with a connection over the wire using the 
      * SUN LDAP provider.  The connection is made using the administrative 
@@ -131,7 +131,7 @@
         return new InitialLdapContext( env, null );
     }
 
-    
+
     /**
      * Creates a JNDI LdapContext with a connection over the wire using the 
      * SUN LDAP provider.  The connection is made using the administrative 
@@ -154,7 +154,7 @@
         return new InitialLdapContext( env, null );
     }
 
-    
+
     /**
      * Creates a JNDI LdapContext with a connection over the wire using the 
      * SUN LDAP provider.  The connection is made using the administrative 
@@ -177,18 +177,18 @@
         return new InitialLdapContext( env, null );
     }
 
-    
+
     public static LDAPConnection getWiredConnection( LdapServer ldapServer ) throws Exception
     {
         String testServer = System.getProperty( "ldap.test.server", null );
-        
+
         if ( testServer == null )
         {
             return getWiredConnection( ldapServer, ServerDNConstants.ADMIN_SYSTEM_DN, "secret"
);
         }
-        
+
         LOG.debug( "ldap.test.server = " + testServer );
-        
+
         String admin = System.getProperty( testServer + ".admin", DEFAULT_ADMIN );
         LOG.debug( testServer + ".admin = " + admin );
 
@@ -200,18 +200,27 @@
 
         int port = Integer.parseInt( System.getProperty( testServer + ".port", Integer.toString(
DEFAULT_PORT ) ) );
         LOG.debug( testServer + ".port = " + port );
-        
+
         LDAPConnection conn = new LDAPConnection();
         conn.connect( 3, host, port, admin, password );
         return conn;
     }
 
-    
-    public static LDAPConnection getWiredConnection( LdapServer ldapServer, String principalDn,
String password ) 
+
+    public static LDAPConnection getWiredConnection( LdapServer ldapServer, String principalDn,
String password )
         throws Exception
     {
         LDAPConnection conn = new LDAPConnection();
         conn.connect( 3, "localhost", ldapServer.getPort(), principalDn, password );
         return conn;
     }
+
+
+    public static LdapConnection getClientApiConnection( LdapServer ldapServer ) throws Exception
+    {
+        LdapConnection conn = new LdapConnection( "localhost", ldapServer.getPort() );
+        conn.bind( ServerDNConstants.ADMIN_SYSTEM_DN, "secret" );
+        return conn;
+    }
+
 }

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=905357&r1=905356&r2=905357&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
Mon Feb  1 18:44:30 2010
@@ -20,6 +20,7 @@
 package org.apache.directory.server.operations.add;
 
 
+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.getWiredContext;
 import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContextThrowOnRefferal;
@@ -58,6 +59,8 @@
 import netscape.ldap.LDAPResponseListener;
 import netscape.ldap.LDAPSearchConstraints;
 
+import org.apache.directory.ldap.client.api.LdapConnection;
+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.constants.ServerDNConstants;
@@ -76,6 +79,9 @@
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.csn.Csn;
 import org.apache.directory.shared.ldap.csn.CsnFactory;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry;
 import org.apache.directory.shared.ldap.ldif.LdifUtils;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
@@ -280,35 +286,33 @@
     @Test
     public void testAddEntryWithTwoDescriptions() throws Exception
     {
-        LDAPConnection con = getWiredConnection( ldapServer );
-        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", "Kate Bush" ) );
+        LdapConnection con = getClientApiConnection( ldapServer );
+        
+        String dn = "cn=Kate Bush," + BASE;
+        Entry kate = new DefaultClientEntry( new LdapDN( dn ) );
+
+        kate.add( "objectclass", "top", "person" );
+        kate.add( "sn", "Bush" );
+        kate.add( "cn", "Kate Bush" );
 
         String descr[] =
             { "a British singer-songwriter with an expressive four-octave voice",
                 "one of the most influential female artists of the twentieth century" };
 
-        attrs.add( new LDAPAttribute( "description", descr ) );
-
-        String dn = "cn=Kate Bush," + BASE;
-        LDAPEntry kate = new LDAPEntry( dn, attrs );
+        kate.add( "description", descr );
 
         con.add( kate );
 
         // Analyze entry and description attribute
-        LDAPEntry kateReloaded = con.read( dn );
+        Entry kateReloaded = ( ( SearchResultEntry ) con.lookup( dn ) ).getEntry();
         assertNotNull( kateReloaded );
-        LDAPAttribute attr = kateReloaded.getAttribute( "description" );
+        EntryAttribute attr = kateReloaded.get( "description" );
         assertNotNull( attr );
-        assertEquals( 2, attr.getStringValueArray().length );
+        assertEquals( 2, attr.size() );
 
         // Remove entry
         con.delete( dn );
-        con.disconnect();
+        con.unBind();
     }
 
 
@@ -322,36 +326,33 @@
     @Test
     public void testAddEntryWithTwoDescriptionsVariant() throws Exception
     {
-        LDAPConnection con = getWiredConnection( ldapServer );
-        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", "Kate Bush" ) );
+        LdapConnection con = getClientApiConnection( ldapServer );
+
+        String dn = "cn=Kate Bush," + BASE;
+        Entry kate = new DefaultClientEntry( new LdapDN( dn ) );
+        kate.add( "objectclass", "top", "person" );
+        kate.add( "sn", "Bush" );
+        kate.add( "cn", "Kate Bush" );
 
         String descr[] =
             { "a British singer-songwriter with an expressive four-octave voice",
                 "one of the most influential female artists of the twentieth century" };
 
-        attrs.add( new LDAPAttribute( "description", descr[0] ) );
-        attrs.add( new LDAPAttribute( "description", descr[1] ) );
-
-        String dn = "cn=Kate Bush," + BASE;
-        LDAPEntry kate = new LDAPEntry( dn, attrs );
+        kate.add( "description", descr[0] );
+        kate.add( "description", descr[1] );
 
         con.add( kate );
 
         // Analyze entry and description attribute
-        LDAPEntry kateReloaded = con.read( dn );
+        Entry kateReloaded = ( (SearchResultEntry ) con.lookup( dn ) ).getEntry();
         assertNotNull( kateReloaded );
-        LDAPAttribute attr = kateReloaded.getAttribute( "description" );
+        EntryAttribute attr = kateReloaded.get( "description" );
         assertNotNull( attr );
-        assertEquals( 2, attr.getStringValueArray().length );
+        assertEquals( 2, attr.size() );
 
         // Remove entry
         con.delete( dn );
-        con.disconnect();
+        con.unBind();
     }
 
 
@@ -365,36 +366,34 @@
     @Test
     public void testAddEntryWithTwoDescriptionsSecondVariant() throws Exception
     {
-        LDAPConnection con = getWiredConnection( ldapServer );
-        LDAPAttributeSet attrs = new LDAPAttributeSet();
-        LDAPAttribute ocls = new LDAPAttribute( "objectclass", new String[]
-            { "top", "person" } );
-        attrs.add( ocls );
-        attrs.add( new LDAPAttribute( "sn", "Bush" ) );
+        LdapConnection con = getClientApiConnection( ldapServer );
+
+        String dn = "cn=Kate Bush," + BASE;
+        Entry kate = new DefaultClientEntry( new LdapDN( dn ) );
+        
+        kate.add( "objectclass", "top", "person" );
+        kate.add( "sn", "Bush" );
 
         String descr[] =
             { "a British singer-songwriter with an expressive four-octave voice",
                 "one of the most influential female artists of the twentieth century" };
 
-        attrs.add( new LDAPAttribute( "description", descr[0] ) );
-        attrs.add( new LDAPAttribute( "cn", "Kate Bush" ) );
-        attrs.add( new LDAPAttribute( "description", descr[1] ) );
-
-        String dn = "cn=Kate Bush," + BASE;
-        LDAPEntry kate = new LDAPEntry( dn, attrs );
+        kate.add( "description", descr[0] );
+        kate.add( "cn", "Kate Bush" );
+        kate.add( "description", descr[1] );
 
         con.add( kate );
 
         // Analyze entry and description attribute
-        LDAPEntry kateReloaded = con.read( dn );
+        Entry kateReloaded = ( ( SearchResultEntry ) con.lookup( dn ) ).getEntry();
         assertNotNull( kateReloaded );
-        LDAPAttribute attr = kateReloaded.getAttribute( "description" );
+        EntryAttribute attr = kateReloaded.get( "description" );
         assertNotNull( attr );
-        assertEquals( 2, attr.getStringValueArray().length );
+        assertEquals( 2, attr.size() );
 
         // Remove entry
         con.delete( dn );
-        con.disconnect();
+        con.unBind();
     }
 
     
@@ -1228,45 +1227,43 @@
     @Test
     public void testAddEntryUUIDAndCSNAttributes() throws Exception
     {
-        LDAPConnection con = getWiredConnection( ldapServer );
-        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", "Kate Bush" ) );
+        LdapConnection con = getClientApiConnection( ldapServer );
+        
+        String dn = "cn=Kate Bush," + BASE;
+        Entry entry = new DefaultClientEntry( new LdapDN( dn ) );
+        entry.add( "objectclass", "top", "person" );
+        entry.add( "sn", "Bush" );
+        entry.add( "cn", "Kate Bush" );
 
         String descr = "a British singer-songwriter with an expressive four-octave voice";
-        attrs.add( new LDAPAttribute( "description", descr ) );
+        entry.add( "description", descr );
 
         UUID uuid = UUID.randomUUID();
-        attrs.add( new LDAPAttribute( SchemaConstants.ENTRY_UUID_AT, uuid.toString() ) );
+        entry.add( SchemaConstants.ENTRY_UUID_AT, uuid.toString() );
 
         CsnFactory csnFac = new CsnFactory( 0 );
         Csn csn = csnFac.newInstance();
-        attrs.add( new LDAPAttribute( SchemaConstants.ENTRY_CSN_AT, csn.toString() ) );
+        entry.add( SchemaConstants.ENTRY_CSN_AT, csn.toString() );
         
-        String dn = "cn=Kate Bush," + BASE;
-        LDAPEntry kate = new LDAPEntry( dn, attrs );
-
-        con.add( kate );
+        con.add( entry );
 
         // Analyze entry and description attribute
-        LDAPEntry addedEntry = con.read( dn, new String[]{ "*", "+"} );
+        SearchResultEntry resp = ( SearchResultEntry ) con.lookup( dn, "*", "+" );
+        Entry addedEntry = resp.getEntry();
         assertNotNull( addedEntry );
 
-        LDAPAttribute attr = addedEntry.getAttribute( SchemaConstants.ENTRY_UUID_AT );
+        EntryAttribute attr = addedEntry.get( SchemaConstants.ENTRY_UUID_AT );
         assertNotNull( attr );
         
-        assertEquals( uuid.toString(), attr.getStringValueArray()[0] );
+        assertEquals( uuid.toString(), attr.getString() );
 
-        attr = addedEntry.getAttribute( SchemaConstants.ENTRY_CSN_AT );
+        attr = addedEntry.get( SchemaConstants.ENTRY_CSN_AT );
         assertNotNull( attr );
-        assertEquals( csn.toString(), new String( attr.getStringValueArray()[0] ) );
+        assertEquals( csn.toString(), attr.getString() );
         
         // Remove entry
         con.delete( dn );
-        con.disconnect();
+        con.unBind();
     }
 
     



Mime
View raw message