From commits-return-22134-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Wed Jun 10 17:06:56 2009 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 96696 invoked from network); 10 Jun 2009 17:06:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Jun 2009 17:06:56 -0000 Received: (qmail 80499 invoked by uid 500); 10 Jun 2009 17:07:08 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 80443 invoked by uid 500); 10 Jun 2009 17:07:08 -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 80434 invoked by uid 99); 10 Jun 2009 17:07:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Jun 2009 17:07:07 +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; Wed, 10 Jun 2009 17:07:05 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0EB5823888D7; Wed, 10 Jun 2009 17:06:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r783430 - /directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientDeleteRequestTest.java Date: Wed, 10 Jun 2009 17:06:44 -0000 To: commits@directory.apache.org From: kayyagari@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090610170645.0EB5823888D7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kayyagari Date: Wed Jun 10 17:06:44 2009 New Revision: 783430 URL: http://svn.apache.org/viewvc?rev=783430&view=rev Log: o test case for the delete operation o one test method related to delete operation using CascadeControl is failing (to be fixed, @Ignored atm) Added: directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientDeleteRequestTest.java Added: 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=783430&view=auto ============================================================================== --- directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientDeleteRequestTest.java (added) +++ directory/apacheds/trunk/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientDeleteRequestTest.java Wed Jun 10 17:06:44 2009 @@ -0,0 +1,188 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +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.assertTrue; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import org.apache.directory.server.core.CoreSession; +import org.apache.directory.server.core.integ.Level; +import org.apache.directory.server.core.integ.annotations.ApplyLdifs; +import org.apache.directory.server.core.integ.annotations.CleanupLevel; +import org.apache.directory.server.integ.SiRunner; +import org.apache.directory.server.ldap.LdapService; +import org.apache.directory.shared.ldap.client.api.LdapConnection; +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; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Test case for client delete operation. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +@RunWith(SiRunner.class) +@CleanupLevel(Level.METHOD) +@ApplyLdifs( { + "dn: cn=parent,ou=system\n" + + "objectClass: person\n" + + "cn: parent_cn\n" + + "sn: parent_sn\n" + + + "\n" + + + "dn: cn=child1,cn=parent,ou=system\n" + + "objectClass: person\n" + + "cn: child1_cn\n" + + "sn: child1_sn\n" + + + "\n" + + + "dn: cn=child2,cn=parent,ou=system\n" + + "objectClass: person\n" + + "cn: child2_cn\n" + + "sn: child2_sn\n" + + + "\n" + + + "dn: cn=grand_child11,cn=child1,cn=parent,ou=system\n" + + "objectClass: person\n" + + "cn: grand_child11_cn\n" + + "sn: grand_child11_sn\n" + + + "\n" + + + "dn: cn=grand_child12,cn=child1,cn=parent,ou=system\n" + + "objectClass: person\n" + + "cn: grand_child12_cn\n" + + "sn: grand_child12_sn\n" +}) +public class ClientDeleteRequestTest +{ + public static LdapService ldapService; + + private LdapConnection connection; + + private CoreSession session; + + @Before + public void setup() throws Exception + { + connection = new LdapConnection( "localhost", ldapService.getPort() ); + + LdapDN bindDn = new LdapDN( "uid=admin,ou=system" ); + connection.bind( bindDn.getUpName(), "secret" ); + + session = ldapService.getDirectoryService().getAdminSession(); + } + + @After + public void clean() throws Exception + { + connection.close(); + } + + + @Test + public void testDeleteLeafNode() throws Exception + { + LdapDN dn = new LdapDN( "cn=grand_child12,cn=child1,cn=parent,ou=system" ); + + assertTrue( session.exists( dn ) ); + + DeleteResponse response = connection.delete( dn.getUpName() ); + assertNotNull( response ); + assertEquals( ResultCodeEnum.SUCCESS, response.getLdapResult().getResultCode() ); + + assertFalse( session.exists( dn ) ); + } + + + @Test + public void testDeleteNonLeafFailure() throws Exception + { + LdapDN dn = new LdapDN( "cn=child1,cn=parent,ou=system" ); // has children + assertTrue( session.exists( dn ) ); + + DeleteResponse response = connection.delete( dn.getUpName() ); + assertNotNull( response ); + assertEquals( ResultCodeEnum.NOT_ALLOWED_ON_NON_LEAF, response.getLdapResult().getResultCode() ); + + assertTrue( session.exists( dn ) ); + } + + + @Ignore( "this method is failing, need to figure out the issue" ) + @Test + public void testDeleteWithCascadeControl() throws Exception + { + LdapDN dn = new LdapDN( "cn=parent,ou=system" ); + + assertTrue( session.exists( dn ) ); + + DeleteResponse response = connection.delete( dn, true ); + assertNotNull( response ); + assertEquals( ResultCodeEnum.SUCCESS, response.getLdapResult().getResultCode() ); + + assertFalse( session.exists( dn ) ); + } + + + /** + * this method uses reflection to test deleteChildren method without using the + * convenient method delete( dn, true ), cause the convenient method checks + * whether the server supports the CascadeControl. + * + * Cause ADS supports this control, delete(dn, true) will never call the method + * deleteChildren() (which has private scope) + * To test the manual deletion of the entries in the absence of this CascadeControl + * reflection was used to invoke the private method deleteChildren(). + * + */ + @Test + public void testDeleteWithoutCascadeControl() throws Exception + { + LdapDN dn = new LdapDN( "cn=parent,ou=system" ); + + assertTrue( session.exists( dn ) ); + + Method deleteChildrenMethod = connection.getClass().getDeclaredMethod( "deleteChildren", LdapDN.class, Map.class ); + deleteChildrenMethod.setAccessible( true ); + + DeleteResponse response = ( DeleteResponse ) deleteChildrenMethod.invoke( connection, dn, null ); + assertNotNull( response ); + assertEquals( ResultCodeEnum.SUCCESS, response.getLdapResult().getResultCode() ); + + assertFalse( session.exists( dn ) ); + } +}