EasyMock.expect(bundle.findEntries("OSGI-INF/rsa", "*.xml", false))
.andReturn(Collections.enumeration(
Collections.singleton(getClass().getResource("/ed3.xml"))));
EasyMock.replay(bundle);
BundleEvent be0 = new BundleEvent(BundleEvent.INSTALLED, bundle);
ld.bundleChanged(be0);
assertEquals(0, ld.endpointDescriptions.size());
// Create an EndpointListener
final Hashtable<String, Object> props = new Hashtable<String, Object>();
props.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, "(objectClass=*)");
ServiceReference sr = EasyMock.createMock(ServiceReference.class);
EasyMock.expect(sr.getPropertyKeys()).andReturn(props.keySet().toArray(new String [] {})).anyTimes();
EasyMock.expect(sr.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer<Object>() {
public Object answer() throws Throwable {
return props.get(EasyMock.getCurrentArguments()[0]);
}
}).anyTimes();
EasyMock.replay(sr);
EndpointListener el = EasyMock.createMock(EndpointListener.class);
el.endpointAdded((EndpointDescription) EasyMock.anyObject(), EasyMock.eq("(objectClass=*)"));
EasyMock.expectLastCall();
EasyMock.replay(el);
ld.registerTracker(sr, el);
// Start the bundle
BundleEvent be = new BundleEvent(BundleEvent.STARTED, bundle);
ld.bundleChanged(be);
assertEquals(1, ld.endpointDescriptions.size());
EndpointDescription ed = ld.endpointDescriptions.keySet().iterator().next();
assertEquals("http://somewhere:12345", ed.getId());
assertSame(bundle, ld.endpointDescriptions.get(ed));
EasyMock.verify(el);
// Stop the bundle
EasyMock.reset(el);
el.endpointRemoved((EndpointDescription) EasyMock.anyObject(), EasyMock.eq("(objectClass=*)"));
EasyMock.expectLastCall();
EasyMock.replay(el);
BundleEvent be1 = new BundleEvent(BundleEvent.STOPPED, bundle);
ld.bundleChanged(be1);
assertEquals(0, ld.endpointDescriptions.size());
EasyMock.verify(el);
}