ArchaiusTokenBucketAdmissionConfigurationParser implements Supplier<List<TokenBucketConfiguration>> { public List<TokenBucketConfiguration> get() { List<TokenBucketConfiguration> currentConfiguration = parseToBucketConfiguration(); currentConfiguration.sort(Comparator.comparingInt(TokenBucketConfiguration::getOrder)); if (currentConfiguration.equals(bucketConfigurations)) { return bucketConfigurations; } return this.bucketConfigurations = currentConfiguration; } ArchaiusTokenBucketAdmissionConfigurationParser(Config config); List<TokenBucketConfiguration> get();  }
@Test public void testNoConfiguration() { MapConfig config = new MapConfig(new HashMap<>()); ArchaiusTokenBucketAdmissionConfigurationParser parser = new ArchaiusTokenBucketAdmissionConfigurationParser(config); assertThat(parser.get()).isEmpty(); }
@Test public void testValidConfiguration() { MapConfig config = new MapConfig(CollectionsExt.merge( TokenBucketTestConfigurations.NOT_SHARED_PROPERTIES, SHARED_ANY_PROPERTIES )); ArchaiusTokenBucketAdmissionConfigurationParser parser = new ArchaiusTokenBucketAdmissionConfigurationParser(config); List<TokenBucketConfiguration> configuration = parser.get(); assertThat(configuration).hasSize(2); assertThat(configuration.get(0)).isEqualTo(TokenBucketTestConfigurations.NOT_SHARED_CONFIGURATION); assertThat(configuration.get(1)).isEqualTo(TokenBucketTestConfigurations.SHARED_ANY_CONFIGURATION); }
@Test public void testPartiallyInvalid() { MapConfig config = new MapConfig(CollectionsExt.merge( TokenBucketTestConfigurations.NOT_SHARED_BAD_PROPERTIES, SHARED_ANY_PROPERTIES )); ArchaiusTokenBucketAdmissionConfigurationParser parser = new ArchaiusTokenBucketAdmissionConfigurationParser(config); List<TokenBucketConfiguration> configuration = parser.get(); assertThat(configuration).hasSize(1); assertThat(configuration.get(0).getName()).isEqualTo(SHARED_ANY_CONFIGURATION.getName()); }
@Test public void testAllInvalid() { MapConfig config = new MapConfig(CollectionsExt.merge( TokenBucketTestConfigurations.NOT_SHARED_BAD_PROPERTIES, TokenBucketTestConfigurations.SHARED_ANY_BAD_PROPERTIES )); ArchaiusTokenBucketAdmissionConfigurationParser parser = new ArchaiusTokenBucketAdmissionConfigurationParser(config); assertThat(parser.get()).isEmpty(); }