RoutingPeerConfigurationParser { RoutingPeerConfiguration parseConfiguration(HierarchicalConfiguration config) throws ConfigurationException { RoutingPeerConfigurationImpl result = new RoutingPeerConfigurationImpl(); Set<AddressFamilyKey> afks = new HashSet<AddressFamilyKey>(); String peerName = config.getString("[@peerName]"); String extension = config.getString("[@extension]"); String key = config.getString("[@key]"); if(StringUtils.isBlank(peerName)) { if(StringUtils.isBlank(extension) || StringUtils.isBlank(key)) throw new ConfigurationException("Either peerName or extension and key attributes are required"); peerName = extension + "_" + key; } else if(StringUtils.isNotBlank(extension) || StringUtils.isNotBlank(key)) throw new ConfigurationException("Either peerName or extension and key attributes are required"); result.setPeerName(peerName); for(HierarchicalConfiguration subConfig : config.configurationsAt("Routing")) { AddressFamilyRoutingPeerConfiguration afprc = peerParser.parseConfiguration(subConfig); if(afks.contains(afprc.getAddressFamilyKey())) throw new ConfigurationException("Duplicated configuration for address family: " + afprc.getAddressFamilyKey()); result.getAddressFamilyConfigrations().add(afprc); afks.add(afprc.getAddressFamilyKey()); } return result; }    }
@Test public void testOneEntry() throws Exception { RoutingPeerConfiguration prc = parser.parseConfiguration(config.configurationAt("RoutingPeer(0)")); Assert.assertEquals("peer", prc.getPeerName()); Assert.assertEquals(1, prc.getAddressFamilyConfigrations().size()); Assert.assertTrue(prc.getAddressFamilyConfigrations().contains(ipv4Peer)); }
@Test public void testTwoEntry() throws Exception { RoutingPeerConfiguration prc = parser.parseConfiguration(config.configurationAt("RoutingPeer(1)")); Assert.assertEquals("extension_key", prc.getPeerName()); Assert.assertEquals(2, prc.getAddressFamilyConfigrations().size()); Assert.assertTrue(prc.getAddressFamilyConfigrations().contains(ipv4Peer)); Assert.assertTrue(prc.getAddressFamilyConfigrations().contains(ipv6Peer)); }