AddressFamilyRoutingConfigurationParser { AddressFamilyRoutingConfiguration parseConfiguration(HierarchicalConfiguration config) throws ConfigurationException { try { AddressFamilyKey key = new AddressFamilyKey(AddressFamily.fromString(config.getString("[@addressFamily]")), SubsequentAddressFamily.fromString(config.getString("[@subsequentAddressFamily]"))); List<RouteConfiguration> routes = new LinkedList<RouteConfiguration>(); for(HierarchicalConfiguration routeConfig : config.configurationsAt("Route")) routes.add(routeParser.parseConfiguration(routeConfig)); return new AddressFamilyRoutingConfigurationImpl(key, routes); } catch(IllegalArgumentException e) { throw new ConfigurationException("Invalid value: ", e); } }    }
@Test public void testParseCompleteWithOneRoute() throws Exception { AddressFamilyRoutingConfiguration result = parser.parseConfiguration(config.configurationAt("AddressFamily(0)")); Assert.assertEquals(AddressFamily.IPv4, result.getKey().getAddressFamily()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, result.getKey().getSubsequentAddressFamily()); Iterator<RouteConfiguration> it = result.getRoutes().iterator(); Assert.assertTrue(it.hasNext()); RouteConfiguration route = it.next(); Assert.assertEquals(new NetworkLayerReachabilityInformation(24, new byte[] { (byte)0xc0, (byte)0xa8, (byte)0x01 }), route.getNlri()); Assert.assertFalse(it.hasNext()); }
@Test public void testParseCompleteWithTwoRoute() throws Exception { AddressFamilyRoutingConfiguration result = parser.parseConfiguration(config.configurationAt("AddressFamily(1)")); Assert.assertEquals(AddressFamily.IPv4, result.getKey().getAddressFamily()); Assert.assertEquals(SubsequentAddressFamily.NLRI_UNICAST_FORWARDING, result.getKey().getSubsequentAddressFamily()); Iterator<RouteConfiguration> it = result.getRoutes().iterator(); Assert.assertTrue(it.hasNext()); RouteConfiguration route = it.next(); Assert.assertEquals(new NetworkLayerReachabilityInformation(24, new byte[] { (byte)0xc0, (byte)0xa8, (byte)0x01 }), route.getNlri()); Assert.assertTrue(it.hasNext()); route = it.next(); Assert.assertEquals(new NetworkLayerReachabilityInformation(24, new byte[] { (byte)0xc0, (byte)0xa8, (byte)0x02 }), route.getNlri()); Assert.assertFalse(it.hasNext()); }
@Test(expected=ConfigurationException.class) public void testMissingAddressFamily() throws Exception { parser.parseConfiguration(config.configurationAt("AddressFamily(2)")); }
@Test(expected=ConfigurationException.class) public void testMissingSubsequentAddressFamily() throws Exception { parser.parseConfiguration(config.configurationAt("AddressFamily(3)")); }