Search in sources :

Example 6 with Proxies

use of org.eclipse.ceylon.common.config.Proxies in project ceylon by eclipse.

the class ProxiesTest method testProxyWithNonProxyHosts.

@Test
public void testProxyWithNonProxyHosts() throws Exception {
    CeylonConfig testConfig = loadTestConfig("proxy+non-proxy-hosts.config");
    Proxies proxies = getProxies(testConfig);
    Proxy proxy = proxies.getProxy();
    Assert.assertEquals("myproxy", proxy.getHost());
    Assert.assertEquals(1234, proxy.getPort());
    Authentication auth = Authentication.fromConfig(testConfig);
    Assert.assertNull(auth.getProxyAuthenticator());
    auth.installProxy();
    Assert.assertEquals(null, auth.getProxyAuthenticator());
    InetSocketAddress address = (InetSocketAddress) auth.getProxy().address();
    Assert.assertEquals("myproxy", address.getHostName());
    Assert.assertEquals(1234, address.getPort());
    List<java.net.Proxy> selectedProxies = auth.getProxySelector().select(URI.create("http://anything"));
    Assert.assertEquals(1, selectedProxies.size());
    Assert.assertEquals(java.net.Proxy.Type.HTTP, selectedProxies.get(0).type());
    Assert.assertEquals("myproxy", ((InetSocketAddress) selectedProxies.get(0).address()).getHostName());
    Assert.assertEquals(1234, ((InetSocketAddress) selectedProxies.get(0).address()).getPort());
    selectedProxies = auth.getProxySelector().select(URI.create("http://foo"));
    Assert.assertEquals(1, selectedProxies.size());
    Assert.assertEquals(java.net.Proxy.Type.DIRECT, selectedProxies.get(0).type());
    Assert.assertNull(selectedProxies.get(0).address());
    mockPrompt.assertSeenOnlyGivenPrompts();
}
Also used : Proxy(org.eclipse.ceylon.common.config.Proxies.Proxy) Proxies(org.eclipse.ceylon.common.config.Proxies) CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) Authentication(org.eclipse.ceylon.common.config.Authentication) PasswordAuthentication(java.net.PasswordAuthentication) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Aggregations

PasswordAuthentication (java.net.PasswordAuthentication)6 Authentication (org.eclipse.ceylon.common.config.Authentication)6 CeylonConfig (org.eclipse.ceylon.common.config.CeylonConfig)6 Proxies (org.eclipse.ceylon.common.config.Proxies)6 Proxy (org.eclipse.ceylon.common.config.Proxies.Proxy)6 Test (org.junit.Test)6 InetSocketAddress (java.net.InetSocketAddress)5 File (java.io.File)2