ServerWebApp extends Server implements ServletContextListener { protected InetSocketAddress resolveAuthority() throws ServerException { String hostnameKey = getName() + HTTP_HOSTNAME; String portKey = getName() + HTTP_PORT; String host = System.getProperty(hostnameKey); String port = System.getProperty(portKey); if (host == null) { throw new ServerException(ServerException.ERROR.S13, hostnameKey); } if (port == null) { throw new ServerException(ServerException.ERROR.S13, portKey); } try { InetAddress add = InetAddress.getByName(host); int portNum = Integer.parseInt(port); return new InetSocketAddress(add, portNum); } catch (UnknownHostException ex) { throw new ServerException(ServerException.ERROR.S14, ex.toString(), ex); } } protected  ServerWebApp(String name, String homeDir, String configDir,
      String logDir, String tempDir, Configuration config); protected  ServerWebApp(String name, String homeDir, Configuration config);  ServerWebApp(String name); static void setHomeDirForCurrentThread(String homeDir); @Override void contextInitialized(ServletContextEvent event); @Override void contextDestroyed(ServletContextEvent event); InetSocketAddress getAuthority(); @VisibleForTesting void setAuthority(InetSocketAddress authority); boolean isSslEnabled(); static final String SSL_ENABLED; }
@Test @TestDir public void testResolveAuthority() throws Exception { String dir = TestDirHelper.getTestDir().getAbsolutePath(); System.setProperty("TestServerWebApp3.home.dir", dir); System.setProperty("TestServerWebApp3.config.dir", dir); System.setProperty("TestServerWebApp3.log.dir", dir); System.setProperty("TestServerWebApp3.temp.dir", dir); System.setProperty("testserverwebapp3.http.hostname", "localhost"); System.setProperty("testserverwebapp3.http.port", "14000"); ServerWebApp server = new ServerWebApp("TestServerWebApp3") { }; InetSocketAddress address = server.resolveAuthority(); Assert.assertEquals("localhost", address.getHostName()); Assert.assertEquals(14000, address.getPort()); }