EndpointListenerNotifier { public static Set<Filter> filtersFromEL(ServiceReference<EndpointListener> sref) { List<String> scopes = StringPlus.normalize(sref.getProperty(EndpointListener.ENDPOINT_LISTENER_SCOPE)); return getFilterSet(scopes); } EndpointListenerNotifier(); static Set<Filter> filtersFromEL(ServiceReference<EndpointListener> sref); static Set<Filter> filtersFromEEL(ServiceReference<EndpointEventListener> sref); void add(EndpointEventListener ep, Set<Filter> filters, Collection<EndpointDescription> endpoints); void remove(EndpointEventListener ep); void sendEvent(EndpointEvent event);  }
@Test public void testNormalizeScopeForSingleString() { ServiceReference sr = createListenerServiceWithFilter("(myProp=A)"); Set<Filter> res = EndpointListenerNotifier.filtersFromEL(sr); assertEquals(1, res.size()); Filter filter = res.iterator().next(); filterMatches(filter); }
@Test public void testNormalizeScopeForStringArray() { String[] filters = {"(myProp=A)", "(otherProp=B)"}; ServiceReference sr = createListenerServiceWithFilter(filters); Set<Filter> res = EndpointListenerNotifier.filtersFromEL(sr); assertEquals(filters.length, res.size()); Iterator<Filter> it = res.iterator(); Filter filter1 = it.next(); Filter filter2 = it.next(); Dictionary<String, String> props = new Hashtable(); props.put("myProp", "A"); assertThat(filter1.match(props) || filter2.match(props), is(true)); }
@Test public void testNormalizeScopeForCollection() { Collection<String> collection = Arrays.asList("(myProp=A)", "(otherProp=B)"); ServiceReference sr = createListenerServiceWithFilter(collection); Set<Filter> res = EndpointListenerNotifier.filtersFromEL(sr); Iterator<Filter> it = res.iterator(); Filter filter1 = it.next(); Filter filter2 = it.next(); Dictionary<String, String> props = new Hashtable(); props.put("myProp", "A"); Assert.assertThat(filter1.match(props) || filter2.match(props), is(true)); }