Hashtable<String,Object> env = new Hashtable<String, Object>();
env.put( DirectoryService.JNDI_KEY, service );
env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
env.put( Context.PROVIDER_URL, "ou=system" );
DirContext ctx = new InitialDirContext( env );
ctx.createSubcontext( rdn, attrs );
// Add the first value for description
String description1 = "an American singer-songwriter";
Attribute firstDescr = new BasicAttribute( "description", description1 );
ModificationItem modification = new ModificationItem(DirContext.ADD_ATTRIBUTE, firstDescr);
ctx.modifyAttributes(rdn, new ModificationItem[] { modification });
// Add a second value to description
String description2 = "Grammy award winning";
Attribute otherDescr = new BasicAttribute( "description", description2 );
modification = new ModificationItem(DirContext.ADD_ATTRIBUTE, otherDescr );
ctx.modifyAttributes(rdn, new ModificationItem[] { modification } );
// Add a third value to description
String description3 = "MTV Music Award winning";
Attribute thirdDescr = new BasicAttribute( "description", description3 );
modification = new ModificationItem(DirContext.ADD_ATTRIBUTE, thirdDescr );
ctx.modifyAttributes(rdn, new ModificationItem[] { modification });
// Search Entry
SearchControls sctls = new SearchControls();
sctls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
String filter = '(' + rdn + ')';
String base = "";
// Check entry
NamingEnumeration<SearchResult> enm = ctx.search(base, filter, sctls);
assertTrue(enm.hasMore());
while (enm.hasMore())
{
SearchResult sr = enm.next();
Attribute desc = sr.getAttributes().get("description");
assertNotNull(desc);
assertTrue(desc.contains(description1));
assertTrue(desc.contains(description2));
assertTrue(desc.contains(description3));
assertEquals(3, desc.size());
}
// Remove the person entry
ctx.destroySubcontext(rdn);
}