BgpSecFilterService { public Stream<ValidatedRpkiObjects.RouterCertificate> filterCertificates(final Stream<ValidatedRpkiObjects.RouterCertificate> routerCertificates) { return filterCertificates(routerCertificates, all().collect(Collectors.toList())); } @Autowired  BgpSecFilterService(SlurmStore slurmStore); long execute(@Valid AddBgpSecFilter command); void remove(long id); Stream<BgpSecFilter> all(); void clear(); Stream<ValidatedRpkiObjects.RouterCertificate> filterCertificates(final Stream<ValidatedRpkiObjects.RouterCertificate> routerCertificates);  }
@Test public void should_not_filter_out_unrelated_certificate() { final List<ValidatedRpkiObjects.RouterCertificate> certificates = Collections.singletonList(CERTIFICATE_1); final List<BgpSecFilter> filters = Collections.singletonList(new BgpSecFilter(1L, 12L, null, null)); final Stream<ValidatedRpkiObjects.RouterCertificate> s = bgpSecFilterService.filterCertificates(certificates.stream(), filters); assertEquals(certificates, s.collect(Collectors.toList())); }
@Test public void should_filter_out_one_certificate_by_asn() { final List<ValidatedRpkiObjects.RouterCertificate> certificates = Arrays.asList(CERTIFICATE_1, CERTIFICATE_2); final List<BgpSecFilter> filters = Collections.singletonList(new BgpSecFilter(10L, ASN_2, null, null)); final Stream<ValidatedRpkiObjects.RouterCertificate> s = bgpSecFilterService.filterCertificates(certificates.stream(), filters); assertEquals(Collections.singletonList(CERTIFICATE_1), s.collect(Collectors.toList())); }
@Test public void should_filter_out_one_certificate_by_ski() { final List<ValidatedRpkiObjects.RouterCertificate> certificates = Collections.singletonList(CERTIFICATE_1); final List<BgpSecFilter> filters = Collections.singletonList(new BgpSecFilter(10L, null, SKI_1, null)); final Stream<ValidatedRpkiObjects.RouterCertificate> s = bgpSecFilterService.filterCertificates(certificates.stream(), filters); assertEquals(Collections.emptyList(), s.collect(Collectors.toList())); }
@Test public void should_filter_out_one_certificate_by_asn_and_ski() { final List<ValidatedRpkiObjects.RouterCertificate> certificates = Arrays.asList(CERTIFICATE_1, CERTIFICATE_3); final List<BgpSecFilter> filters = Collections.singletonList(new BgpSecFilter(20L, ASN_1, SKI_3, null)); final Stream<ValidatedRpkiObjects.RouterCertificate> s = bgpSecFilterService.filterCertificates(certificates.stream(), filters); assertEquals(Collections.singletonList(CERTIFICATE_1), s.collect(Collectors.toList())); }