HttpServerConfigurationParser { public HttpServerConfiguration parseConfiguration(HierarchicalConfiguration config) throws ConfigurationException { HttpServerConfigurationImpl result = new HttpServerConfigurationImpl(); 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; }  HttpServerConfiguration parseConfiguration(HierarchicalConfiguration config);  }
@Test public void testHttpServerConfigurationWithoutServerConfiguration() throws Exception { HttpServerConfiguration HttpServerConfig = parser.parseConfiguration(config.configurationAt("HttpServer(0)")); Assert.assertEquals(8080, HttpServerConfig.getServerConfiguration().getListenAddress().getPort()); Assert.assertEquals(InetAddress.getByName("0.0.0.0"), HttpServerConfig.getServerConfiguration().getListenAddress().getAddress()); }
@Test public void testHttpServerConfigurationWithEmptyServerConfiguration() throws Exception { HttpServerConfiguration HttpServerConfig = parser.parseConfiguration(config.configurationAt("HttpServer(1)")); Assert.assertEquals(8080, HttpServerConfig.getServerConfiguration().getListenAddress().getPort()); Assert.assertEquals(InetAddress.getByName("0.0.0.0"), HttpServerConfig.getServerConfiguration().getListenAddress().getAddress()); }
@Test public void testHttpServerConfigurationWithServerPortConfiguration() throws Exception { HttpServerConfiguration HttpServerConfig = parser.parseConfiguration(config.configurationAt("HttpServer(2)")); Assert.assertEquals(17179, HttpServerConfig.getServerConfiguration().getListenAddress().getPort()); Assert.assertEquals(InetAddress.getByName("0.0.0.0"), HttpServerConfig.getServerConfiguration().getListenAddress().getAddress()); }
@Test(expected=ConfigurationException.class) public void testHttpServerConfigurationDuplicateServerConfiguration() throws Exception { parser.parseConfiguration(config.configurationAt("HttpServer(3)")); }