@Test void testFilter() { JmsDestinationFilter filter = new JmsDestinationFilter(); 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", JmsDestination.class, "jms2", EntityTypes.JMS_DESTINATION_TYPE), new Dependency("3", JmsDestination.class, "jms3", EntityTypes.JMS_DESTINATION_TYPE)), new Dependency("2", Policy.class, "my-policy2", EntityTypes.POLICY_TYPE), Collections.singletonList(new Dependency("4", JmsDestination.class, "jms4", EntityTypes.JMS_DESTINATION_TYPE)))); bundle.addEntity(TestUtils.createJmsDestination("jms1", "1")); bundle.addEntity(TestUtils.createJmsDestination("jms2", "2")); bundle.addEntity(TestUtils.createJmsDestination("jms3", "3")); bundle.addEntity(TestUtils.createJmsDestination("jms4", "4")); FilterConfiguration filterConfiguration = new FilterConfiguration(); List<JmsDestination> filteredEntities = filter.filter("/my/folder/path", filterConfiguration, bundle, filteredBundle); assertEquals(2, filteredEntities.size()); assertTrue(filteredEntities.stream().anyMatch(c -> "jms2".equals(c.getName()))); assertTrue(filteredEntities.stream().anyMatch(c -> "jms3".equals(c.getName()))); filterConfiguration.getEntityFilters().put(filter.getFilterableEntityName(), new HashSet<>()); filterConfiguration.getEntityFilters().get(filter.getFilterableEntityName()).add("jms1"); filteredEntities = filter.filter("/my/folder/path", filterConfiguration, bundle, filteredBundle); assertEquals(3, filteredEntities.size()); assertTrue(filteredEntities.stream().anyMatch(c -> "jms2".equals(c.getName()))); assertTrue(filteredEntities.stream().anyMatch(c -> "jms3".equals(c.getName()))); assertTrue(filteredEntities.stream().anyMatch(c -> "jms1".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<JmsDestination> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle) { List<JmsDestination> jmsDestinations = DependencyUtils.filterDependencies( JmsDestination.class, bundle, filteredBundle, e -> filterConfiguration.getRequiredEntityNames(ENTITY_NAME).contains(e.getName()) ); DependencyUtils.validateEntitiesInList( jmsDestinations, filterConfiguration.getRequiredEntityNames(ENTITY_NAME), "JMS Destination(s)" ); return jmsDestinations; }
JmsDestinationFilter implements EntityFilter<JmsDestination> { @Override public List<JmsDestination> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle) { List<JmsDestination> jmsDestinations = DependencyUtils.filterDependencies( JmsDestination.class, bundle, filteredBundle, e -> filterConfiguration.getRequiredEntityNames(ENTITY_NAME).contains(e.getName()) ); DependencyUtils.validateEntitiesInList( jmsDestinations, filterConfiguration.getRequiredEntityNames(ENTITY_NAME), "JMS Destination(s)" ); return jmsDestinations; } }
JmsDestinationFilter implements EntityFilter<JmsDestination> { @Override public List<JmsDestination> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle) { List<JmsDestination> jmsDestinations = DependencyUtils.filterDependencies( JmsDestination.class, bundle, filteredBundle, e -> filterConfiguration.getRequiredEntityNames(ENTITY_NAME).contains(e.getName()) ); DependencyUtils.validateEntitiesInList( jmsDestinations, filterConfiguration.getRequiredEntityNames(ENTITY_NAME), "JMS Destination(s)" ); return jmsDestinations; }  }
JmsDestinationFilter implements EntityFilter<JmsDestination> { @Override public List<JmsDestination> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle) { List<JmsDestination> jmsDestinations = DependencyUtils.filterDependencies( JmsDestination.class, bundle, filteredBundle, e -> filterConfiguration.getRequiredEntityNames(ENTITY_NAME).contains(e.getName()) ); DependencyUtils.validateEntitiesInList( jmsDestinations, filterConfiguration.getRequiredEntityNames(ENTITY_NAME), "JMS Destination(s)" ); return jmsDestinations; }  @Override String getFilterableEntityName(); @Override @NotNull Collection<Class<? extends EntityFilter>> getDependencyEntityFilters(); @Override List<JmsDestination> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle); }
JmsDestinationFilter implements EntityFilter<JmsDestination> { @Override public List<JmsDestination> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle) { List<JmsDestination> jmsDestinations = DependencyUtils.filterDependencies( JmsDestination.class, bundle, filteredBundle, e -> filterConfiguration.getRequiredEntityNames(ENTITY_NAME).contains(e.getName()) ); DependencyUtils.validateEntitiesInList( jmsDestinations, filterConfiguration.getRequiredEntityNames(ENTITY_NAME), "JMS Destination(s)" ); return jmsDestinations; }  @Override String getFilterableEntityName(); @Override @NotNull Collection<Class<? extends EntityFilter>> getDependencyEntityFilters(); @Override List<JmsDestination> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle);  }