FilterBindingsProvider implements Provider<FilterBindings> { @Override public FilterBindings get() { return new FilterBindings(requestFilters, responseFilters); } FilterBindingsProvider(ComponentId componentId,
                                  ServerConfig config,
                                  FilterChainRepository filterChainRepository,
                                  ComponentRegistry<SecurityRequestFilter> legacyRequestFilters); @Override FilterBindings get(); @Override void deconstruct();  }
@Test public void requireThatEmptyInputGivesEmptyOutput() { final FilterChainRepository filterChainRepository = new FilterChainRepository( new ChainsConfig(new ChainsConfig.Builder()), new ComponentRegistry<>(), new ComponentRegistry<>(), new ComponentRegistry<>(), new ComponentRegistry<>()); final FilterBindingsProvider provider = new FilterBindingsProvider( new ComponentId("foo"), new ServerConfig(configBuilder), filterChainRepository, new ComponentRegistry<>()); final FilterBindings filterBindings = provider.get(); assertNotNull(filterBindings); assertFalse(filterBindings.getRequestFilters().iterator().hasNext()); assertFalse(filterBindings.getResponseFilters().iterator().hasNext()); }
@Test public void requireThatCorrectlyConfiguredFiltersAreIncluded() { final String requestFilter1Id = "requestFilter1"; final String requestFilter2Id = "requestFilter2"; final String requestFilter3Id = "requestFilter3"; final String responseFilter1Id = "responseFilter1"; final String responseFilter2Id = "responseFilter2"; final String responseFilter3Id = "responseFilter3"; configBuilder.filter(new ServerConfig.Filter.Builder().id(requestFilter1Id).binding("http:/b")); configBuilder.filter(new ServerConfig.Filter.Builder().id(responseFilter1Id).binding("http:/d")); final ComponentRegistry<RequestFilter> availableRequestFilters = new ComponentRegistry<>(); final RequestFilter requestFilter1Instance = mock(RequestFilter.class); final RequestFilter requestFilter2Instance = mock(RequestFilter.class); final RequestFilter requestFilter3Instance = mock(RequestFilter.class); availableRequestFilters.register(ComponentId.fromString(requestFilter1Id), requestFilter1Instance); availableRequestFilters.register(ComponentId.fromString(requestFilter2Id), requestFilter2Instance); availableRequestFilters.register(ComponentId.fromString(requestFilter3Id), requestFilter3Instance); final ComponentRegistry<ResponseFilter> availableResponseFilters = new ComponentRegistry<>(); final ResponseFilter responseFilter1Instance = mock(ResponseFilter.class); final ResponseFilter responseFilter2Instance = mock(ResponseFilter.class); final ResponseFilter responseFilter3Instance = mock(ResponseFilter.class); availableResponseFilters.register(ComponentId.fromString(responseFilter1Id), responseFilter1Instance); availableResponseFilters.register(ComponentId.fromString(responseFilter2Id), responseFilter2Instance); availableResponseFilters.register(ComponentId.fromString(responseFilter3Id), responseFilter3Instance); final FilterChainRepository filterChainRepository = new FilterChainRepository( new ChainsConfig(new ChainsConfig.Builder()), availableRequestFilters, availableResponseFilters, new ComponentRegistry<>(), new ComponentRegistry<>()); final FilterBindingsProvider provider = new FilterBindingsProvider( new ComponentId("foo"), new ServerConfig(configBuilder), filterChainRepository, new ComponentRegistry<>()); final FilterBindings filterBindings = provider.get(); assertNotNull(filterBindings); assertThat( filterBindings.getRequestFilters(), containsFilters(requestFilter1Instance, requestFilter2Instance)); assertThat( filterBindings.getRequestFilters(), not(containsFilters(requestFilter3Instance))); assertThat( filterBindings.getResponseFilters(), containsFilters(responseFilter1Instance, responseFilter3Instance)); assertThat( filterBindings.getResponseFilters(), not(containsFilters(responseFilter2Instance))); }