public void testSearchingNewSchemaElements() throws Exception
{
DirContext ctx = getWiredContext( getLdapServer() );
// create an entry with the schema objectClass personActiveDirectory
Attributes person = new BasicAttributes( "objectClass", "top", true );
person.get( "objectClass" ).add( "person" );
person.get( "objectClass" ).add( "personActiveDirectory" );
person.put( "cn", "foobar" );
person.put( "sn", "bar" );
person.put( "pwdLastSet", "3" );
person.put( "SourceAD", "blah" );
person.put( "useraccountcontrol", "7" );
person.put( "sAMAccountName", "foobar" );
ctx.createSubcontext( "cn=foobar,ou=system", person );
// Confirm creation with a lookup
Attributes read = ctx.getAttributes( "cn=foobar,ou=system" );
assertNotNull( read );
assertEquals( "3", read.get( "pwdLastSet" ).get() );
// Now search for foobar with pwdLastSet value of 3
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
NamingEnumeration<SearchResult> results = ctx.search( "ou=system", "(pwdLastSet=3)", searchControls );
assertTrue( results.hasMore() );
SearchResult result = results.next();
assertNotNull( result );
assertEquals( "cn=foobar", result.getName() );
Attributes attributes = result.getAttributes();
assertEquals( "3", attributes.get( "pwdLastSet" ).get() );
results.close();
// Now search with bogus value for pwdLastSet
results = ctx.search( "ou=system", "(pwdLastSet=300)", searchControls );
assertFalse( results.hasMore() );