@Test void filter() { JDBCConnectionFilter filter = new JDBCConnectionFilter(); 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", JdbcConnection.class, "jdbc2", EntityTypes.JDBC_CONNECTION), new Dependency("3", JdbcConnection.class, "jdbc3", EntityTypes.JDBC_CONNECTION)), new Dependency("2", Policy.class, "my-policy2", EntityTypes.POLICY_TYPE), Collections.singletonList(new Dependency("4", JdbcConnection.class, "jdbc4", EntityTypes.JDBC_CONNECTION)))); bundle.addEntity(new JdbcConnection.Builder().name("jdbc1").id("1").build()); bundle.addEntity(new JdbcConnection.Builder().name("jdbc2").id("2").build()); bundle.addEntity(new JdbcConnection.Builder().name("jdbc3").id("3").build()); bundle.addEntity(new JdbcConnection.Builder().name("jdbc4").id("4").build()); FilterConfiguration filterConfiguration = new FilterConfiguration(); List<JdbcConnection> filteredEntities = filter.filter("/my/folder/path", filterConfiguration, bundle, filteredBundle); assertEquals(2, filteredEntities.size()); assertTrue(filteredEntities.stream().anyMatch(c -> "jdbc2".equals(c.getName()))); assertTrue(filteredEntities.stream().anyMatch(c -> "jdbc3".equals(c.getName()))); filterConfiguration.getEntityFilters().put(filter.getFilterableEntityName(), new HashSet<>()); filterConfiguration.getEntityFilters().get(filter.getFilterableEntityName()).add("jdbc1"); filteredEntities = filter.filter("/my/folder/path", filterConfiguration, bundle, filteredBundle); assertEquals(3, filteredEntities.size()); assertTrue(filteredEntities.stream().anyMatch(c -> "jdbc2".equals(c.getName()))); assertTrue(filteredEntities.stream().anyMatch(c -> "jdbc3".equals(c.getName()))); assertTrue(filteredEntities.stream().anyMatch(c -> "jdbc1".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")); }
@Override public List<JdbcConnection> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle) { List<JdbcConnection> jdbcConnections = DependencyUtils.filterDependencies(JdbcConnection.class, bundle, filteredBundle, e -> filterConfiguration.getRequiredEntityNames(ENTITY_NAME).contains(e.getName())); DependencyUtils.validateEntitiesInList(jdbcConnections, filterConfiguration.getRequiredEntityNames(ENTITY_NAME), "JDBC Connection(s)"); return jdbcConnections; }
JDBCConnectionFilter implements EntityFilter<JdbcConnection> { @Override public List<JdbcConnection> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle) { List<JdbcConnection> jdbcConnections = DependencyUtils.filterDependencies(JdbcConnection.class, bundle, filteredBundle, e -> filterConfiguration.getRequiredEntityNames(ENTITY_NAME).contains(e.getName())); DependencyUtils.validateEntitiesInList(jdbcConnections, filterConfiguration.getRequiredEntityNames(ENTITY_NAME), "JDBC Connection(s)"); return jdbcConnections; } }
JDBCConnectionFilter implements EntityFilter<JdbcConnection> { @Override public List<JdbcConnection> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle) { List<JdbcConnection> jdbcConnections = DependencyUtils.filterDependencies(JdbcConnection.class, bundle, filteredBundle, e -> filterConfiguration.getRequiredEntityNames(ENTITY_NAME).contains(e.getName())); DependencyUtils.validateEntitiesInList(jdbcConnections, filterConfiguration.getRequiredEntityNames(ENTITY_NAME), "JDBC Connection(s)"); return jdbcConnections; }  }
JDBCConnectionFilter implements EntityFilter<JdbcConnection> { @Override public List<JdbcConnection> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle) { List<JdbcConnection> jdbcConnections = DependencyUtils.filterDependencies(JdbcConnection.class, bundle, filteredBundle, e -> filterConfiguration.getRequiredEntityNames(ENTITY_NAME).contains(e.getName())); DependencyUtils.validateEntitiesInList(jdbcConnections, filterConfiguration.getRequiredEntityNames(ENTITY_NAME), "JDBC Connection(s)"); return jdbcConnections; }  @Override @NotNull Collection<Class<? extends EntityFilter>> getDependencyEntityFilters(); @Override List<JdbcConnection> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle); @Override String getFilterableEntityName(); }
JDBCConnectionFilter implements EntityFilter<JdbcConnection> { @Override public List<JdbcConnection> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle) { List<JdbcConnection> jdbcConnections = DependencyUtils.filterDependencies(JdbcConnection.class, bundle, filteredBundle, e -> filterConfiguration.getRequiredEntityNames(ENTITY_NAME).contains(e.getName())); DependencyUtils.validateEntitiesInList(jdbcConnections, filterConfiguration.getRequiredEntityNames(ENTITY_NAME), "JDBC Connection(s)"); return jdbcConnections; }  @Override @NotNull Collection<Class<? extends EntityFilter>> getDependencyEntityFilters(); @Override List<JdbcConnection> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle); @Override String getFilterableEntityName();  }