EndpointGroupingRuleReader { EndpointGroupingRule read() { EndpointGroupingRule endpointGroupingRule = new EndpointGroupingRule(); if (Objects.nonNull(yamlData)) { List rulesData = (List) yamlData.get("grouping"); if (rulesData != null) { rulesData.forEach(ruleObj -> { final Map rule = (Map) ruleObj; final String serviceName = (String) rule.get("service-name"); if (StringUtil.isEmpty(serviceName)) { throw new IllegalArgumentException("service-name can't be empty"); } final List endpointRules = (List) rule.get("rules"); if (endpointRules != null) { endpointRules.forEach(endpointRuleObj -> { final Map endpointRule = (Map) endpointRuleObj; final String endpointLogicGroupName = (String) endpointRule.get("endpoint-name"); final String groupRegex = (String) endpointRule.get("regex"); if (StringUtil.isEmpty(endpointLogicGroupName) || StringUtil.isEmpty(groupRegex)) { return; } endpointGroupingRule.addRule(serviceName, endpointLogicGroupName, groupRegex); }); } }); } } return endpointGroupingRule; } EndpointGroupingRuleReader(InputStream inputStream);  EndpointGroupingRuleReader(Reader io);   }
@Test public void testReadingRule() { EndpointGroupingRuleReader reader = new EndpointGroupingRuleReader(this.getClass() .getClassLoader() .getResourceAsStream( "endpoint-name-grouping.yml")); final EndpointGroupingRule rule = reader.read(); StringFormatGroup.FormatResult formatResult = rule.format("serviceA", "/prod/123"); Assert.assertTrue(formatResult.isMatch()); Assert.assertEquals("/prod/{id}", formatResult.getName()); formatResult = rule.format("serviceA", "/prod/"); Assert.assertFalse(formatResult.isMatch()); formatResult = rule.format("serviceB", "/prod/123"); Assert.assertFalse(formatResult.isMatch()); }