EventContext ectx = (EventContext) ctx;
ectx.addNamingListener("", EventContext.SUBTREE_SCOPE, listener);
log.info("Added NamingListener");
ctx.bind("testAddObject", "testAddObject.bind");
assertTrue("Saw bind event", listener.waitOnEvent());
NamingEvent event = listener.getEvent(0);
assertEquals("OBJECT_ADDED", NamingEvent.OBJECT_ADDED, event.getType());
assertNull("getOldBinding", event.getOldBinding());
assertEquals("testAddObject.bind", getValue(event.getNewBinding()));
ctx.rebind("testAddObject", "testAddObject.rebind");
assertTrue("Saw rebind event", listener.waitOnEvent());
event = listener.getEvent(1);
assertEquals("OBJECT_CHANGED", NamingEvent.OBJECT_CHANGED, event.getType());
assertEquals("testAddObject.bind", getValue(event.getOldBinding()));
assertEquals("testAddObject.rebind", getValue(event.getNewBinding()));
ctx.unbind("testAddObject");
assertTrue("Saw unbind event", listener.waitOnEvent());
event = listener.getEvent(2);
assertEquals("OBJECT_REMOVED", NamingEvent.OBJECT_REMOVED, event.getType());
assertEquals("testAddObject.rebind", getValue(event.getOldBinding()));
assertNull("getNewBinding", event.getNewBinding());
// Create a subcontext
Context subctx = ctx.createSubcontext("subctx");
listener.waitOnEvent();
assertEquals("Should be 4 events", 4, listener.getEventCount());
event = listener.getEvent(3);
assertEquals("OBJECT_ADDED", NamingEvent.OBJECT_ADDED, event.getType());
assertNull("getOldBinding", event.getOldBinding());
assertEquals("getNewBinding", subctx, getValue(event.getNewBinding()));
// Creating a binding under subctx should produce an event
subctx.bind("subctx.testAddObject", "testAddObject.subctx.bind");
assertTrue("Wait on subctx bind", listener.waitOnEvent());
event = listener.getEvent(4);
assertEquals("OBJECT_ADDED", NamingEvent.OBJECT_ADDED, event.getType());
}