BgpServerConfigurationParser { public BgpServerConfiguration parseConfiguration(HierarchicalConfiguration config) throws ConfigurationException { BgpServerConfigurationImpl result = new BgpServerConfigurationImpl(); List<HierarchicalConfiguration> serverConfig = config.configurationsAt("Server"); if(serverConfig.size() == 1) result.setServerConfiguration(serverConfigurationParser.parseConfig(serverConfig.get(0))); else if(serverConfig.size() > 1) throw new ConfigurationException("duplicate <Server/> element"); else result.setServerConfiguration(new ServerConfigurationImpl()); return result; }  BgpServerConfiguration parseConfiguration(HierarchicalConfiguration config);  }
@Test public void testBgpServerConfigurationWithoutServerConfiguration() throws Exception { BgpServerConfiguration bgpServerConfig = parser.parseConfiguration(config.configurationAt("BgpServer(0)")); Assert.assertEquals(179, bgpServerConfig.getServerConfiguration().getListenAddress().getPort()); Assert.assertEquals(InetAddress.getByName("0.0.0.0"), bgpServerConfig.getServerConfiguration().getListenAddress().getAddress()); }
@Test public void testBgpServerConfigurationWithEmptyServerConfiguration() throws Exception { BgpServerConfiguration bgpServerConfig = parser.parseConfiguration(config.configurationAt("BgpServer(1)")); Assert.assertEquals(179, bgpServerConfig.getServerConfiguration().getListenAddress().getPort()); Assert.assertEquals(InetAddress.getByName("0.0.0.0"), bgpServerConfig.getServerConfiguration().getListenAddress().getAddress()); }
@Test public void testBgpServerConfigurationWithServerPortConfiguration() throws Exception { BgpServerConfiguration bgpServerConfig = parser.parseConfiguration(config.configurationAt("BgpServer(2)")); Assert.assertEquals(17179, bgpServerConfig.getServerConfiguration().getListenAddress().getPort()); Assert.assertEquals(InetAddress.getByName("0.0.0.0"), bgpServerConfig.getServerConfiguration().getListenAddress().getAddress()); }
@Test(expected=ConfigurationException.class) public void testBgpServerConfigurationDuplicateServerConfiguration() throws Exception { parser.parseConfiguration(config.configurationAt("BgpServer(3)")); }