RoutingFilterConfigurationParser { RoutingFilterConfiguration parseConfiguration(HierarchicalConfiguration config) throws ConfigurationException { List<HierarchicalConfiguration> prefixList = config.configurationsAt("Prefixes"); RoutingFilterConfigurationImpl rfc = null; if(prefixList.size() > 1) throw new ConfigurationException("more then one subnode specified"); if(prefixList.size() == 1) rfc = parsePrefixFilter(prefixList.get(0)); if(rfc == null) throw new ConfigurationException("no filter type specified"); rfc.setName(config.getString("[@name]", "")); return rfc; }    }
@Test public void testEmptyPrefixFilter() throws Exception { RoutingFilterConfiguration rfc = parser.parseConfiguration(config.configurationAt("Filter(0)")); Assert.assertTrue(rfc instanceof PrefixRoutingFilterConfiguration); PrefixRoutingFilterConfiguration prfc = (PrefixRoutingFilterConfiguration)rfc; Iterator<NetworkLayerReachabilityInformation> it = prfc.getFilterPrefixes().iterator(); Assert.assertFalse(it.hasNext()); }
@Test public void testOnePrefixFilter() throws Exception { RoutingFilterConfiguration rfc = parser.parseConfiguration(config.configurationAt("Filter(1)")); Assert.assertTrue(rfc instanceof PrefixRoutingFilterConfiguration); PrefixRoutingFilterConfiguration prfc = (PrefixRoutingFilterConfiguration)rfc; Iterator<NetworkLayerReachabilityInformation> it = prfc.getFilterPrefixes().iterator(); Assert.assertTrue(it.hasNext()); Assert.assertEquals(new NetworkLayerReachabilityInformation(24, new byte[] {(byte)0xc0, (byte)0xa8, (byte)0x01}), it.next()); Assert.assertFalse(it.hasNext()); }
@Test public void testTwoPrefixFilter() throws Exception { RoutingFilterConfiguration rfc = parser.parseConfiguration(config.configurationAt("Filter(2)")); Assert.assertTrue(rfc instanceof PrefixRoutingFilterConfiguration); PrefixRoutingFilterConfiguration prfc = (PrefixRoutingFilterConfiguration)rfc; Iterator<NetworkLayerReachabilityInformation> it = prfc.getFilterPrefixes().iterator(); Assert.assertTrue(it.hasNext()); Assert.assertEquals(new NetworkLayerReachabilityInformation(24, new byte[] {(byte)0xc0, (byte)0xa8, (byte)0x01}), it.next()); Assert.assertTrue(it.hasNext()); Assert.assertEquals(new NetworkLayerReachabilityInformation(24, new byte[] {(byte)0xc0, (byte)0xa8, (byte)0x02}), it.next()); Assert.assertFalse(it.hasNext()); }
@Test(expected=ConfigurationException.class) public void testNoFilterType() throws Exception { parser.parseConfiguration(config.configurationAt("Filter(3)")); }
@Test(expected=ConfigurationException.class) public void testMisspelledFilterType() throws Exception { parser.parseConfiguration(config.configurationAt("Filter(4)")); }
@Test(expected=ConfigurationException.class) public void testNoPrefixValue() throws Exception { parser.parseConfiguration(config.configurationAt("Filter(5)")); }
@Test(expected=ConfigurationException.class) public void testBlankPrefixValue() throws Exception { parser.parseConfiguration(config.configurationAt("Filter(6)")); }