public void testRevokeService_ParentContext()
throws TooManyListenersException {
MockBeanContextServicesSupport support = new MockBeanContextServicesSupport();
MockBeanContextServicesSupport childSupport = new MockBeanContextServicesSupport();
support.add(childSupport);
MockBeanContextServicesListener l1 = new MockBeanContextServicesListener();
MockBeanContextServicesListener l2 = new MockBeanContextServicesListener();
support.addBeanContextServicesListener(l1);
childSupport.addBeanContextServicesListener(l2);
support.records.assertRecord("initialize", null);
childSupport.records.assertRecord("initialize", null);
MockBeanContextServiceProvider provider = new MockBeanContextServiceProvider();
support.addService(Collection.class, provider);
MockBeanContextChild child = new MockBeanContextChild();
childSupport.add(child);
String requestor = "requestor";
String selector = "selector";
MockBeanContextServiceRevokedListener rl = new MockBeanContextServiceRevokedListener();
Object service = childSupport.getService(child, requestor,
Collection.class, selector, rl);
assertNotNull(service);
support.records.clear();
childSupport.records.clear();
provider.records.clear();
l1.clearLastEvent();
l2.clearLastEvent();
support.revokeService(Collection.class, provider, false);
assertEquals(0, support.services().size());
support.records.assertEndOfRecords();
childSupport.records.assertEndOfRecords();
provider.records.assertEndOfRecords();
assertSame(support, l1.lastRevokedEvent
.getSourceAsBeanContextServices());
assertSame(Collection.class, l1.lastRevokedEvent.getServiceClass());
assertFalse(l1.lastRevokedEvent.isCurrentServiceInvalidNow());
assertNull(l2.lastRevokedEvent);
assertSame(childSupport, rl.lastEvent.getSourceAsBeanContextServices());
assertSame(Collection.class, rl.lastEvent.getServiceClass());
assertFalse(rl.lastEvent.isCurrentServiceInvalidNow());
support.records.clear();
childSupport.records.clear();
provider.records.clear();
l1.clearLastEvent();
l2.clearLastEvent();
rl.clearLastEvent();
childSupport.releaseService(child, requestor, service);
support.records.assertEndOfRecords();