public void testAddEntryComposedRDN() throws Exception
{
DirContext ctx = ( DirContext ) getWiredContext( getLdapServer() ).lookup( BASE );
// Create a person
Attributes person = new BasicAttributes( "objectClass", "inetOrgPerson", true );
person.get( "objectClass" ).add( "top" );
person.get( "objectClass" ).add( "person" );
person.get( "objectClass" ).add( "organizationalPerson" );
person.put( "sn", "Michael Jackson" );
person.put( "cn", "Jackson" );
DirContext michaelCtx = ctx.createSubcontext( "displayName=test+cn=Michael", person );
assertNotNull( michaelCtx );
DirContext jackson = ( DirContext ) ctx.lookup( "displayName=test+cn=Michael" );
person = jackson.getAttributes( "" );
javax.naming.directory.Attribute newOcls = person.get( "objectClass" );
String[] expectedOcls =
{ "top", "person", "organizationalPerson", "inetOrgPerson" };
for ( String name : expectedOcls )
{
assertTrue( "object class " + name + " is present", newOcls.contains( name ) );
}
// Check that the DIsplayName attribute has been added
javax.naming.directory.Attribute displayName = person.get( "displayName" );
assertEquals( 1, displayName.size() );
assertTrue( displayName.contains( "test" ) );
// Check that the cn attribute value has been added
javax.naming.directory.Attribute cn = person.get( "cn" );
assertEquals( 2, cn.size() );
assertTrue( cn.contains( "Jackson" ) );
assertTrue( cn.contains( "Michael" ) );
}