ClientDelegate extends Delegate { @Override public void applyDelegate(Config config) { config.setDefaultRunningMode(RunningModeType.CLIENT); if (host == null) { throw new ParameterException("Could not parse provided host: " + host); } String[] split = host.split(": if (split.length > 0) { host = split[split.length - 1]; } host = IDN.toASCII(host); URI uri; try { uri = new URI("my: } catch (URISyntaxException ex) { throw new ParameterException("Could not parse host '" + host + "'", ex); } if (uri.getHost() == null) { throw new ParameterException("Provided host seems invalid:" + host); } OutboundConnection con = config.getDefaultClientConnection(); if (con == null) { con = new OutboundConnection(); config.setDefaultClientConnection(con); } if (uri.getPort() <= 0) { con.setPort(DEFAULT_HTTPS_PORT); } else { con.setPort(uri.getPort()); } if (IPAddress.isValid(uri.getHost())) { con.setIp(uri.getHost()); if (sniHostname != null) { con.setHostname(sniHostname); } else { con.setHostname(getHostForIp(uri.getHost())); } } else { if (sniHostname != null) { con.setHostname(sniHostname); } else { con.setHostname(uri.getHost()); } con.setIp(getIpForHost(uri.getHost())); } } ClientDelegate(); String getHost(); void setHost(String host); @Override void applyDelegate(Config config); String getSniHostname(); void setSniHostname(String sniHostname);  }
@Test public void testApplyDelegate() { Config config = Config.createConfig(); args = new String[2]; args[0] = "-connect"; args[1] = "99.99.99.99:1448"; jcommander.parse(args); delegate.applyDelegate(config); AliasedConnection actual = config.getDefaultClientConnection(); assertNotNull(actual); assertThat(actual.getHostname(), equalTo("99.99.99.99")); assertThat(actual.getPort(), equalTo(1448)); assertThat(actual.getLocalConnectionEndType(), equalTo(ConnectionEndType.CLIENT)); }
@Test public void testApplyDelegateNullHost() { Config config = Config.createConfig(); exception.expect(ParameterException.class); exception.expectMessage("Could not parse provided host: null"); delegate.applyDelegate(config); }