return props.get(EasyMock.getCurrentArguments()[0]);
}
}).anyTimes();
EasyMock.replay(sr);
EndpointListener el = EasyMock.createMock(EndpointListener.class);
EasyMock.replay(el);
assertEquals("Precondition failed", 0, ld.listenerToFilters.size());
assertEquals("Precondition failed", 0, ld.filterToListeners.size());
ld.registerTracker(sr, el);
assertEquals(1, ld.listenerToFilters.size());
assertEquals(Collections.singletonList("(objectClass=Aaaa)"), ld.listenerToFilters.get(el));
assertEquals(1, ld.filterToListeners.size());
assertEquals(Collections.singletonList(el), ld.filterToListeners.get("(objectClass=Aaaa)"));
// Add another one with the same scope filter
ServiceReference sr2 = EasyMock.createMock(ServiceReference.class);
EasyMock.expect(sr2.getPropertyKeys()).andReturn(props.keySet().toArray(new String [] {})).anyTimes();
EasyMock.expect(sr2.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer<Object>() {
public Object answer() throws Throwable {
return props.get(EasyMock.getCurrentArguments()[0]);
}
}).anyTimes();
EasyMock.replay(sr2);
EndpointListener el2 = EasyMock.createMock(EndpointListener.class);
EasyMock.replay(el2);
ld.registerTracker(sr2, el2);
assertEquals(2, ld.listenerToFilters.size());
assertEquals(Collections.singletonList("(objectClass=Aaaa)"), ld.listenerToFilters.get(el));
assertEquals(Collections.singletonList("(objectClass=Aaaa)"), ld.listenerToFilters.get(el2));
assertEquals(1, ld.filterToListeners.size());
assertEquals(Arrays.asList(el, el2), ld.filterToListeners.get("(objectClass=Aaaa)"));
// Add another listener with a multi-value scope
final Hashtable<String, Object> props2 = new Hashtable<String, Object>();
props2.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, Arrays.asList("(objectClass=X)","(objectClass=Y)"));
ServiceReference sr3 = EasyMock.createMock(ServiceReference.class);
EasyMock.expect(sr3.getPropertyKeys()).andReturn(props2.keySet().toArray(new String [] {})).anyTimes();
EasyMock.expect(sr3.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer<Object>() {
public Object answer() throws Throwable {
return props2.get(EasyMock.getCurrentArguments()[0]);
}
}).anyTimes();
EasyMock.replay(sr3);
EndpointListener el3 = EasyMock.createMock(EndpointListener.class);
EasyMock.replay(el3);
ld.registerTracker(sr3, el3);
assertEquals(3, ld.listenerToFilters.size());
assertEquals(Collections.singletonList("(objectClass=Aaaa)"), ld.listenerToFilters.get(el));