private static Predicate<FilteredTopic> applyNamespaceFilter(final WithId signal) { return t -> t.getNamespaces().isEmpty() || t.getNamespaces().contains(namespaceFromId(signal)); }
private static Predicate<FilteredTopic> applyNamespaceFilter(final WithId signal) { return t -> t.getNamespaces().isEmpty() || t.getNamespaces().contains(namespaceFromId(signal)); }
@Test public void fromStringParsesAsExpectedWithOnlyNamespace() { final List<String> namespaces = Arrays.asList("this.is.a.namespace", "eat.that", "foo.bar"); final String filterTopicString = "_/_/things/live/commands?namespaces=" + String.join(",", namespaces); final FilteredTopic filteredTopic = ImmutableFilteredTopic.fromString(filterTopicString); assertThat(filteredTopic.getNamespaces()).isEqualTo(namespaces); assertThat(filteredTopic.getTopic()).isEqualTo(Topic.LIVE_COMMANDS); }
@Test public void fromStringParsesAsExpectedWithOnlyFilter() { final String filterTopicString = "_/_/things/live/events?filter=" + FILTER_EXAMPLE; final FilteredTopic filteredTopic = ImmutableFilteredTopic.fromString(filterTopicString); assertThat(filteredTopic.getNamespaces()).isEmpty(); assertThat(filteredTopic.getTopic()).isEqualTo(Topic.LIVE_EVENTS); assertThat(filteredTopic.getFilter()).contains(FILTER_EXAMPLE); }
@Test public void fromStringParsesAsExpected() { final String filterTopicString = "_/_/things/twin/events"; final FilteredTopic filteredTopic = ImmutableFilteredTopic.fromString(filterTopicString); assertThat(filteredTopic.getNamespaces()).isEmpty(); assertThat(filteredTopic.getTopic()).isEqualTo(Topic.TWIN_EVENTS); assertThat(filteredTopic.getFilter()).isEmpty(); }
@Test public void fromStringParsesAsExpectedWithFilterAndNamespaces() { final String filterTopicString = "_/_/things/twin/events?namespaces=foo,bar&filter=" + FILTER_EXAMPLE; final FilteredTopic filteredTopic = ImmutableFilteredTopic.fromString(filterTopicString); assertThat(filteredTopic.getNamespaces()).isEqualTo(Arrays.asList("foo", "bar")); assertThat(filteredTopic.getTopic()).isEqualTo(Topic.TWIN_EVENTS); assertThat(filteredTopic.getFilter()).contains(FILTER_EXAMPLE); }