*/
@Test
public void testRemoveNamingListener() throws Exception
{
TestListener listener = new TestListener();
EventDirContext ctx = ( EventDirContext ) getSystemContext( getService() ).lookup( "" );
ctx.addNamingListener( "", SearchControls.SUBTREE_SCOPE, listener );
Attributes testEntry = LdifUtils.createJndiAttributes(
"objectClass: top",
"objectClass: organizationalUnit",
"ou", "testentry");
ctx.createSubcontext( "ou=testentry", testEntry );
// Wait 1 second, as the process is asynchronous
Thread.sleep( 1000 );
assertEquals( 1, listener.getEventRecords().size() );
EventRecord rec = ( EventRecord ) listener.getEventRecords().get( 0 );
assertEquals( "objectAdded", rec.method );
assertEquals( ctx, rec.event.getSource() );
ctx.removeNamingListener( listener );
ctx.destroySubcontext( "ou=testentry" );
// Wait 1 second, as the process is asynchronous
Thread.sleep( 1000 );
assertEquals( 1, listener.getEventRecords().size() );
rec = ( EventRecord ) listener.getEventRecords().get( 0 );
assertEquals( "objectAdded", rec.method );
assertEquals( ctx, rec.event.getSource() );
// read the entry once again just to make sure
ctx.createSubcontext( "ou=testentry", testEntry );
// Wait 1 second, as the process is asynchronous
Thread.sleep( 1000 );
assertEquals( 1, listener.getEventRecords().size() );