EasyMock.expect(b1.findEntries("OSGI-INF/remote-service", "*.xml", false)).
andReturn(rsBEnum).anyTimes();
EasyMock.replay(b1);
// Call back on the LDS just like what would have happened with the BundleListener
BundleEvent be = new BundleEvent(BundleEvent.STARTED, b1);
lds.bundleChanged(be);
Map<Collection<String>, String> eids2 = getEndpointIDs(lds.servicesInfo.keySet());
Map<String, Object> sed3Props = new HashMap<String, Object>();
setEndpointID(eids2, sed3Props, "org.example.SomeRelatedService", "org.example.SomeService");
ServiceEndpointDescription sed3 = new ServiceEndpointDescriptionImpl(
Arrays.asList("org.example.SomeRelatedService", "org.example.SomeService"), sed3Props);
assertEquals(3, lds.servicesInfo.size());
assertTrue(lds.servicesInfo.containsKey(sed1));
assertTrue(lds.servicesInfo.containsKey(sed2));
assertTrue(lds.servicesInfo.containsKey(sed3));
assertEquals("We should have been notified of the new bundle",
2, dst.notifications.size());
assertEquals(DiscoveredServiceNotification.AVAILABLE,
dst.notifications.get(1).getType());
assertEquals(sed3, dst.notifications.get(1).getServiceEndpointDescription());
verifyNotification(dst.notifications.get(1), 0, 1, "org.example.SomeService");
ArrayList<DiscoveredServiceNotification> copiedNotifications =
new ArrayList<DiscoveredServiceNotification>(dst.notifications);
// add an unrelated bundle - no notification...
Bundle b2 = EasyMock.createNiceMock(Bundle.class);
EasyMock.expect(b2.getState()).andReturn(Bundle.ACTIVE).anyTimes();
EasyMock.expect(b2.findEntries("OSGI-INF/remote-service", "*.xml", false)).
andReturn(rsCEnum).anyTimes();
EasyMock.replay(b2);
BundleEvent be2 = new BundleEvent(BundleEvent.STARTED, b1);
lds.bundleChanged(be2);
assertEquals("There should not have been any extra notification",
copiedNotifications, dst.notifications);
// Send an irrelevant bundle event
BundleEvent be3 = new BundleEvent(BundleEvent.LAZY_ACTIVATION, b0);
lds.bundleChanged(be3);
assertEquals("There should not have been any changes to the registered serviceInfos",
3, lds.servicesInfo.size());
assertEquals("There should not have been any extra notification",
copiedNotifications, dst.notifications);
// remove bundle b0
BundleEvent be4 = new BundleEvent(BundleEvent.STOPPING, b0);
lds.bundleChanged(be4);
assertEquals(1, lds.servicesInfo.size());
assertEquals(sed3, lds.servicesInfo.keySet().iterator().next());