QueueCircuitBreakerRulePatternToCircuitMapping { public PatternAndCircuitHash getCircuitFromRequestUri(String requestUri){ for (PatternAndCircuitHash mapping : rulePatternToCircuitMapping) { if(mapping.getPattern().matcher(requestUri).matches()){ return mapping; } } return null; }  List<PatternAndCircuitHash> updateRulePatternToCircuitMapping(List<Rule> rules); PatternAndCircuitHash getCircuitFromRequestUri(String requestUri);  }
@Test public void testGetCircuitFromRequestUri(TestContext context){ context.assertNotNull(rules); context.assertNotNull(rulesAfterUpdate); context.assertEquals(3, rules.size()); context.assertEquals(4, rulesAfterUpdate.size()); List<PatternAndCircuitHash> patternAndCircuitHashes = mapping.updateRulePatternToCircuitMapping(rules); context.assertEquals(0, patternAndCircuitHashes.size()); String circuit_1 = mapping.getCircuitFromRequestUri("/playground/img/test.jpg").getCircuitHash(); context.assertNotNull(circuit_1); String circuit_2 = mapping.getCircuitFromRequestUri("/playground/js/code.js").getCircuitHash(); context.assertNotNull(circuit_2); context.assertNotEquals(circuit_1, circuit_2); String circuit_2a = mapping.getCircuitFromRequestUri("/playground/js/another.js").getCircuitHash(); context.assertNotNull(circuit_2a); context.assertEquals(circuit_2, circuit_2a); PatternAndCircuitHash circuit_3 = mapping.getCircuitFromRequestUri("/playground/unknown/uri"); context.assertNull(circuit_3); }