@Test
void filter() {

    ListenPortFilter filter = new ListenPortFilter();
    Bundle filteredBundle = new Bundle();
    filteredBundle.addEntity(TestUtils.createPolicy("my-policy", "1", "", "", null, ""));
    Bundle bundle = FilterTestUtils.getBundle();
    bundle.setDependencyMap(
            ImmutableMap.of(
                    new Dependency("1", Policy.class, "my-policy", EntityTypes.POLICY_TYPE), Arrays.asList(new Dependency("2", ListenPort.class, "lp2", EntityTypes.LISTEN_PORT_TYPE), new Dependency("3", ListenPort.class, "lp3", EntityTypes.LISTEN_PORT_TYPE)),
                    new Dependency("2", Policy.class, "my-policy2", EntityTypes.POLICY_TYPE), Collections.singletonList(new Dependency("4", ListenPort.class, "lp4", EntityTypes.LISTEN_PORT_TYPE))));
    bundle.addEntity(new ListenPort.Builder().name("lp1").id("1").build());
    bundle.addEntity(new ListenPort.Builder().name("lp2").id("2").build());
    bundle.addEntity(new ListenPort.Builder().name("lp3").id("3").build());
    bundle.addEntity(new ListenPort.Builder().name("lp4").id("4").build());
    FilterConfiguration filterConfiguration = new FilterConfiguration();
    List<ListenPort> filteredEntities = filter.filter("/my/folder/path", filterConfiguration, bundle, filteredBundle);
    assertEquals(2, filteredEntities.size());
    assertTrue(filteredEntities.stream().anyMatch(c -> "lp2".equals(c.getName())));
    assertTrue(filteredEntities.stream().anyMatch(c -> "lp3".equals(c.getName())));
    filterConfiguration.getEntityFilters().put(filter.getFilterableEntityName(), new HashSet<>());
    filterConfiguration.getEntityFilters().get(filter.getFilterableEntityName()).add("lp4");
    filteredEntities = filter.filter("/my/folder/path", filterConfiguration, bundle, filteredBundle);
    assertEquals(3, filteredEntities.size());
    assertTrue(filteredEntities.stream().anyMatch(c -> "lp2".equals(c.getName())));
    assertTrue(filteredEntities.stream().anyMatch(c -> "lp3".equals(c.getName())));
    assertTrue(filteredEntities.stream().anyMatch(c -> "lp4".equals(c.getName())));
    filterConfiguration.getEntityFilters().get(filter.getFilterableEntityName()).add("non-existing-entity");
    EntityFilterException entityFilterException = assertThrows(EntityFilterException.class, () -> filter.filter("/my/folder/path", filterConfiguration, bundle, filteredBundle));
    assertTrue(entityFilterException.getMessage().contains("non-existing-entity"));
}