Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 65876 invoked from network); 14 Jun 2009 12:34:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Jun 2009 12:34:26 -0000 Received: (qmail 72021 invoked by uid 500); 14 Jun 2009 12:34:37 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 71961 invoked by uid 500); 14 Jun 2009 12:34:37 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 71952 invoked by uid 99); 14 Jun 2009 12:34:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Jun 2009 12:34:37 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Jun 2009 12:34:34 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B04E823888CD; Sun, 14 Jun 2009 12:34:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r784549 - in /directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations: ClientAddRequestTest.java ClientDeleteRequestTest.java ClientModifyDnRequestTest.java ClientModifyRequestTest.java Date: Sun, 14 Jun 2009 12:34:14 -0000 To: commits@directory.apache.org From: kayyagari@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090614123414.B04E823888CD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kayyagari Date: Sun Jun 14 12:34:14 2009 New Revision: 784549 URL: http://svn.apache.org/viewvc?rev=784549&view=rev Log: added test cases for async feature Modified: directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientDeleteRequestTest.java directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyDnRequestTest.java directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyRequestTest.java Modified: directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java?rev=784549&r1=784548&r2=784549&view=diff ============================================================================== --- directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java (original) +++ directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java Sun Jun 14 12:34:14 2009 @@ -25,18 +25,24 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.util.concurrent.Semaphore; + import org.apache.directory.server.core.CoreSession; import org.apache.directory.server.core.integ.Level; import org.apache.directory.server.core.integ.annotations.CleanupLevel; import org.apache.directory.server.integ.SiRunner; import org.apache.directory.server.ldap.LdapServer; +import org.apache.directory.shared.ldap.client.api.AddRequest; 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.AddListener; import org.apache.directory.shared.ldap.client.api.messages.AddResponse; import org.apache.directory.shared.ldap.constants.SchemaConstants; import org.apache.directory.shared.ldap.entry.Entry; import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry; import org.apache.directory.shared.ldap.message.ResultCodeEnum; import org.apache.directory.shared.ldap.name.LdapDN; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -53,22 +59,30 @@ /** The server instance */ public static LdapServer ldapServer; - @Test - public void testModify() throws Exception + private LdapConnection connection; + + private CoreSession session; + + @Before + public void setup() throws Exception { - LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort() ); - + connection = new LdapConnection( "localhost", ldapServer.getPort() ); LdapDN bindDn = new LdapDN( "uid=admin,ou=system" ); connection.bind( bindDn.getUpName(), "secret" ); - + + session = ldapServer.getDirectoryService().getSession(); + } + + + @Test + public void testModify() throws Exception + { LdapDN dn = new LdapDN( "cn=testadd,ou=system" ); Entry entry = new DefaultClientEntry( dn ); entry.add( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.PERSON_OC ); entry.add( SchemaConstants.CN_AT, "testadd_cn" ); entry.add( SchemaConstants.SN_AT, "testadd_sn" ); - CoreSession session = ldapServer.getDirectoryService().getSession(); - assertFalse( session.exists( dn ) ); AddResponse response = connection.add( entry ); @@ -78,4 +92,32 @@ assertTrue( session.exists( dn ) ); } + + @Test + public void testModifyAsync() throws Exception + { + LdapDN dn = new LdapDN( "cn=testAsyncAdd,ou=system" ); + Entry entry = new DefaultClientEntry( dn ); + entry.add( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.PERSON_OC ); + entry.add( SchemaConstants.CN_AT, "testAsyncAdd_cn" ); + entry.add( SchemaConstants.SN_AT, "testAsyncAdd_sn" ); + + assertFalse( session.exists( dn ) ); + + final Semaphore lock = new Semaphore( 1 ); + lock.acquire(); + + connection.add( new AddRequest( entry ), new AddListener() + { + public void entryAdded( LdapConnection connection, AddResponse response ) throws LdapException + { + assertNotNull( response ); + assertEquals( ResultCodeEnum.SUCCESS, response.getLdapResult().getResultCode() ); + lock.release(); + } + }); + + lock.acquire(); + assertTrue( session.exists( dn ) ); + } } Modified: directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientDeleteRequestTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientDeleteRequestTest.java?rev=784549&r1=784548&r2=784549&view=diff ============================================================================== --- directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientDeleteRequestTest.java (original) +++ directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientDeleteRequestTest.java Sun Jun 14 12:34:14 2009 @@ -23,10 +23,12 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.lang.reflect.Method; import java.util.Map; +import java.util.concurrent.Semaphore; import org.apache.directory.server.core.CoreSession; import org.apache.directory.server.core.integ.Level; @@ -35,6 +37,8 @@ import org.apache.directory.server.integ.SiRunner; import org.apache.directory.server.ldap.LdapServer; 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.DeleteListener; import org.apache.directory.shared.ldap.client.api.messages.DeleteResponse; import org.apache.directory.shared.ldap.message.ResultCodeEnum; import org.apache.directory.shared.ldap.name.LdapDN; @@ -184,4 +188,29 @@ assertFalse( session.exists( dn ) ); } + + + @Test + public void testDeleteAsync() throws Exception + { + LdapDN dn = new LdapDN( "cn=grand_child12,cn=child1,cn=parent,ou=system" ); + + assertTrue( session.exists( dn ) ); + + final Semaphore lock = new Semaphore(1); + lock.acquire(); + DeleteResponse response = connection.delete( dn, new DeleteListener() + { + public void entryDeleted( LdapConnection connection, DeleteResponse response ) throws LdapException + { + assertNotNull( response ); + assertEquals( ResultCodeEnum.SUCCESS, response.getLdapResult().getResultCode() ); + lock.release(); + } + }); + + lock.acquire(); + assertNull( response ); + assertFalse( session.exists( dn ) ); + } } Modified: directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyDnRequestTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyDnRequestTest.java?rev=784549&r1=784548&r2=784549&view=diff ============================================================================== --- directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyDnRequestTest.java (original) +++ directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyDnRequestTest.java Sun Jun 14 12:34:14 2009 @@ -20,10 +20,14 @@ package org.apache.directory.shared.client.api.operations; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.util.concurrent.Semaphore; + import org.apache.directory.server.core.CoreSession; import org.apache.directory.server.core.integ.Level; import org.apache.directory.server.core.integ.annotations.ApplyLdifs; @@ -31,8 +35,12 @@ import org.apache.directory.server.integ.SiRunner; import org.apache.directory.server.ldap.LdapServer; 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.ModifyDnListener; +import org.apache.directory.shared.ldap.client.api.messages.ModifyDnRequest; import org.apache.directory.shared.ldap.client.api.messages.ModifyDnResponse; 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.apache.directory.shared.ldap.name.Rdn; import org.junit.Before; @@ -115,4 +123,31 @@ System.out.println( session.lookup( new LdapDN( "cn=modDn,ou=users,ou=system" ) ) ); } + + + @Test + public void testModifyDnAsync() throws Exception + { + ModifyDnRequest modDnReq = new ModifyDnRequest(); + modDnReq.setEntryDn( new LdapDN( dn ) ); + modDnReq.setNewRdn( new Rdn( "cn=modifyDnWithString" ) ); + modDnReq.setDeleteOldRdn( true ); + + final Semaphore lock = new Semaphore(1); + lock.acquire(); + ModifyDnResponse resp = connection.modifyDn( modDnReq, new ModifyDnListener() + { + public void modifyDnCompleted( LdapConnection connection, ModifyDnResponse response ) throws LdapException + { + assertNotNull( response ); + assertEquals( ResultCodeEnum.SUCCESS, response.getLdapResult().getResultCode() ); + lock.release(); + } + }); + + lock.acquire(); + assertNull( resp ); + assertFalse( session.exists( new LdapDN( dn ) ) ); + assertTrue( session.exists( new LdapDN( "cn=modifyDnWithString,ou=system" ) ) ); + } } Modified: directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyRequestTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyRequestTest.java?rev=784549&r1=784548&r2=784549&view=diff ============================================================================== --- directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyRequestTest.java (original) +++ directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyRequestTest.java Sun Jun 14 12:34:14 2009 @@ -21,19 +21,29 @@ import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import java.util.concurrent.Semaphore; + +import org.apache.directory.server.core.CoreSession; import org.apache.directory.server.core.entry.ServerEntry; import org.apache.directory.server.core.integ.Level; import org.apache.directory.server.core.integ.annotations.CleanupLevel; import org.apache.directory.server.integ.SiRunner; import org.apache.directory.server.ldap.LdapServer; 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.ModifyListener; import org.apache.directory.shared.ldap.client.api.messages.ModifyRequest; +import org.apache.directory.shared.ldap.client.api.messages.ModifyResponse; import org.apache.directory.shared.ldap.constants.SchemaConstants; import org.apache.directory.shared.ldap.entry.Entry; import org.apache.directory.shared.ldap.entry.ModificationOperation; import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry; +import org.apache.directory.shared.ldap.message.ResultCodeEnum; import org.apache.directory.shared.ldap.name.LdapDN; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -51,13 +61,26 @@ /** The server instance */ public static LdapServer ldapServer; + private LdapConnection connection; + + private CoreSession session; + + @Before + public void setup() throws Exception + { + connection = new LdapConnection( "localhost", ldapServer.getPort() ); + + LdapDN bindDn = new LdapDN( "uid=admin,ou=system" ); + connection.bind( bindDn.getUpName(), "secret" ); + + session = ldapServer.getDirectoryService().getAdminSession(); + } + + @Test public void testModify() throws Exception { - LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort() ); - LdapDN dn = new LdapDN( "uid=admin,ou=system" ); - connection.bind( dn.getUpName(), "secret" ); String expected = String.valueOf( System.currentTimeMillis() ); ModifyRequest modRequest = new ModifyRequest( dn ); @@ -65,7 +88,7 @@ connection.modify( modRequest, null ); - ServerEntry entry = ldapServer.getDirectoryService().getAdminSession().lookup( dn ); + ServerEntry entry = session.lookup( dn ); String actual = entry.get( SchemaConstants.SN_AT ).getString(); @@ -76,10 +99,7 @@ @Test public void testModifyWithEntry() throws Exception { - LdapConnection connection = new LdapConnection( "localhost", ldapServer.getPort() ); - LdapDN dn = new LdapDN( "uid=admin,ou=system" ); - connection.bind( dn.getUpName(), "secret" ); Entry entry = new DefaultClientEntry( dn ); @@ -92,7 +112,7 @@ connection.modify( entry, ModificationOperation.REPLACE_ATTRIBUTE ); - ServerEntry lookupEntry = ldapServer.getDirectoryService().getAdminSession().lookup( dn ); + ServerEntry lookupEntry = session.lookup( dn ); String actualSn = lookupEntry.get( SchemaConstants.SN_AT ).getString(); assertEquals( expectedSn, actualSn ); @@ -100,4 +120,37 @@ String actualCn = lookupEntry.get( SchemaConstants.CN_AT ).getString(); assertEquals( expectedCn, actualCn ); } + + + @Test + public void modifyAsync() throws Exception + { + LdapDN dn = new LdapDN( "uid=admin,ou=system" ); + + String expected = String.valueOf( System.currentTimeMillis() ); + ModifyRequest modRequest = new ModifyRequest( dn ); + modRequest.replace( SchemaConstants.SN_AT, expected ); + + final Semaphore lock = new Semaphore(1); + lock.acquire(); + + ModifyResponse response = connection.modify( modRequest, new ModifyListener() + { + public void modifyCompleted( LdapConnection connection, ModifyResponse response ) throws LdapException + { + assertNotNull( response ); + assertEquals( ResultCodeEnum.SUCCESS, response.getLdapResult().getResultCode() ); + lock.release(); + } + }); + + lock.acquire(); + assertNull( response ); + + ServerEntry entry = session.lookup( dn ); + + String actual = entry.get( SchemaConstants.SN_AT ).getString(); + + assertEquals( expected, actual ); + } }