DefaultRequestLimitRulesSupplier implements RequestLimitRulesSupplier<Set<RequestLimitRule>> { @Override public Set<RequestLimitRule> getRules(String key) { Set<RequestLimitRule> ruleSet = ruleMap.get(key); if (ruleSet != null) { return ruleSet; } return defaultRules; } DefaultRequestLimitRulesSupplier(Set<RequestLimitRule> rules); @Override Set<RequestLimitRule> getRules(String key);  }
@Test void shouldContainsDefaultRules() { Set<String> ruleNames = requestLimitRulesSupplier.getRules("other") .stream() .map(RequestLimitRule::getName) .collect(Collectors.toSet()); assertThat(ruleNames).hasSize(2); assertThat(ruleNames).contains("perSeconds", "perHours"); }
@Test void shouldContainLocalhostRulesForLocalhost() { Set<String> ruleNames = requestLimitRulesSupplier.getRules("localhost") .stream() .map(RequestLimitRule::getName) .collect(Collectors.toSet()); assertThat(ruleNames).hasSize(2); assertThat(ruleNames).contains("localhostPerSeconds", "localhostPerHours"); }
@Test void shouldContainLocalhostRulesFor127_0_0_1() { Set<String> ruleNames = requestLimitRulesSupplier.getRules("127.0.0.1") .stream() .map(RequestLimitRule::getName) .collect(Collectors.toSet()); assertThat(ruleNames).hasSize(2); assertThat(ruleNames).contains("localhostPerSeconds", "localhostPerHours"); }