[ 
https://issues.apache.org/jira/browse/DIRSERVER-1974?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14951272#comment-14951272
 ] 

lucas theisen commented on DIRSERVER-1974:
------------------------------------------

Ok, still struggling to get a real unit test for this, but here is my test code 
for running against an _already running_ external instance:

{code:java}
package org.mitre.caasd.portal.ldap.service.impl;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;


import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ProcessBuilder.Redirect;
import java.nio.file.Paths;
import java.util.Properties;


import org.apache.commons.pool.impl.GenericObjectPool;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.message.AddRequest;
import org.apache.directory.api.ldap.model.message.AddResponse;
import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
import org.apache.directory.api.ldap.model.message.SearchScope;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.ldap.model.name.Rdn;
import org.apache.directory.ldap.client.api.DefaultLdapConnectionFactory;
import org.apache.directory.ldap.client.api.LdapConnection;
import org.apache.directory.ldap.client.api.LdapConnectionConfig;
import org.apache.directory.ldap.client.api.LdapConnectionPool;
import 
org.apache.directory.ldap.client.api.ValidatingPoolableLdapConnectionFactory;
import org.apache.directory.ldap.client.api.search.FilterBuilder;
import org.apache.directory.ldap.client.template.ConnectionCallback;
import org.apache.directory.ldap.client.template.EntryMapper;
import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
import org.apache.directory.ldap.client.template.RequestBuilder;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class UserServiceImplIT {
    private static final Logger logger = LoggerFactory.getLogger( 
UserServiceImplIT.class );
    private static final EntryMapper<Entry> DEFAULT_ENTRY_MAPPER = new 
EntryMapper<Entry>() {
        @Override
        public Entry map( Entry entry ) throws LdapException {
            return entry;
        }
    };

    private static String adminDn;
    private static String adminPassword;
    private static String baseDn;
    private static String hostname;
    private static String peopleDn;
    private static int port;

    @BeforeClass
    public static void loadProperties() throws IOException {
        // set member variables here
        logger.debug( "Property config'd, lets go!" );
    }

    @Test
    public void testRenameOnExternalInstance() {
        LdapConnectionConfig config = new LdapConnectionConfig();
        config.setLdapHost( hostname );
        config.setLdapPort( port );
        config.setName( adminDn );
        config.setCredentials( adminPassword );

        DefaultLdapConnectionFactory factory = new 
DefaultLdapConnectionFactory( config );
        factory.setTimeOut( 1000 );

        // optional, values below are defaults
        GenericObjectPool.Config poolConfig = new GenericObjectPool.Config();
        poolConfig.lifo = true;
        poolConfig.maxActive = 1;
        poolConfig.maxIdle = 1;
        poolConfig.maxWait = -1L;
        poolConfig.minEvictableIdleTimeMillis = 1000L * 60L * 30L;
        poolConfig.minIdle = 0;
        poolConfig.numTestsPerEvictionRun = 3;
        poolConfig.softMinEvictableIdleTimeMillis = -1L;
        poolConfig.testOnBorrow = false;
        poolConfig.testOnReturn = false;
        poolConfig.testWhileIdle = false;
        poolConfig.timeBetweenEvictionRunsMillis = -1L;
        poolConfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;

        LdapConnectionTemplate template =
                new LdapConnectionTemplate( new LdapConnectionPool(
                        new ValidatingPoolableLdapConnectionFactory( factory ), 
poolConfig ) );

        final String oldUid = "myra-ellen-amos";
        final String oldCn = "Myra Ellen Amos";
        final String oldRdn = "uid=" + oldUid;
        final String oldDnString = oldRdn + ", " + peopleDn;
        final Dn oldDn = template.newDn( oldDnString );

        final String newUid = "tory-amos";
        final String newRdn = "uid=" + newUid;
        final String newDnString = newRdn + "," + peopleDn;
        final Dn newDn = template.newDn( newDnString );

        AddResponse response = template.add( oldDn,
                new RequestBuilder<AddRequest>() {
                    @Override
                    public void buildRequest( AddRequest request ) throws 
LdapException {
                        request.getEntry()
                                .add( "objectClass", "top", "person", 
"inetOrgPerson" )
                                .add( "cn", oldCn )
                                .add( "sn", "Amos" )
                                .add( "description", oldCn + " is a person." );
                    }
                } );
        assertEquals( response.getLdapResult().getDiagnosticMessage(), 
ResultCodeEnum.SUCCESS, response.getLdapResult().getResultCode() );

        assertNotNull( template.lookup( oldDn, DEFAULT_ENTRY_MAPPER ) );

        Entry found = template.searchFirst( peopleDn, FilterBuilder.equal( 
"sn", "amos" ), 
                SearchScope.ONELEVEL, DEFAULT_ENTRY_MAPPER );
        assertNotNull( found );
        Rdn foundRdn = found.getDn().getRdn();
        assertEquals( "uid", foundRdn.getType() );
        assertEquals( oldUid, foundRdn.getValue().getString() );

        template.execute(
                new ConnectionCallback<Void>() {
                    @Override
                    public Void doWithConnection( LdapConnection connection ) 
throws LdapException {
                        connection.rename( oldDnString, newRdn );
                        return null;
                    }
                } );

        assertNull( template.lookup( oldDn, DEFAULT_ENTRY_MAPPER ) );
        assertNotNull( template.lookup( newDn, DEFAULT_ENTRY_MAPPER ) );
        
        found = template.searchFirst( peopleDn, FilterBuilder.equal( "sn", 
"amos" ), 
                SearchScope.ONELEVEL, DEFAULT_ENTRY_MAPPER );
        foundRdn = found.getDn().getRdn();
        assertNotNull( found );
        foundRdn = found.getDn().getRdn();
        assertEquals( "uid", foundRdn.getType() );
        assertEquals( newUid, foundRdn.getValue().getString() );

        template.delete( newDn );
    }
}
{code}

The first couple times i run this against a fresh instance, its ok.  But after 
that, it starts failing.

> Rename Operation Issue - ApacheDS
> ---------------------------------
>
>                 Key: DIRSERVER-1974
>                 URL: https://issues.apache.org/jira/browse/DIRSERVER-1974
>             Project: Directory ApacheDS
>          Issue Type: Bug
>          Components: ldap
>    Affects Versions: 2.0.0-M15
>         Environment: Window server 2008 R2
>            Reporter: Mohd Usman
>            Priority: Blocker
>              Labels: build, features, patch
>         Attachments: ApacheDSSchemaBrowser.png, CNAttributeInSchema.png, 
> PostRename.png, PreRename.png, SchemaViewerLDAPAdminTool.png
>
>   Original Estimate: 168h
>  Remaining Estimate: 168h
>
> Whenever we perform Rename operation on an object entry (let’s say Person 
> object), the person gets renamed successfully but the issue is that the old 
> value of the person object still remains.
> The ‘cn’ attribute contains two values now - old value and also the new value.
>  
> Example:
> I have created a person object with DN 
> "cn=person,ou=Apache,dc=example,dc=com" and I want to rename this entry to 
> "cn=person_Rename,ou=Apache,dc=example,dc=com".
> The rename operation executes successfully and the person is renamed to 
> "cn=person_Rename,ou=Apache,dc=example,dc=com". 
> But, the ‘cn’ attribute now contains 
> “person”
> “person_Rename”.
> When verified the schema, ‘cn’ attribute show as ‘single valued’ but after 
> performing the rename operation – the ‘cn’ becomes ‘multi-valued’ and 
> contains two values.
> This an issue with Apache directory which needs to be resolved. Also find the 
> screenshots attached for your reference. Please look into the same.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to