*/
@Test
public void testRemoveNamingListener() throws Exception
{
TestListener listener = new TestListener();
EventDirContext ctx = ( EventDirContext ) getSystemContext( service ).lookup( "" );
ctx.addNamingListener( "", SearchControls.SUBTREE_SCOPE, listener );
Attributes testEntry = new BasicAttributes( "ou", "testentry", true );
Attribute objectClass = new BasicAttribute( "objectClass", "top" );
objectClass.add( "organizationalUnit" );
testEntry.put( objectClass );
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() );