1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.util;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertNotNull;
14
15 import java.io.IOException;
16 import java.net.InetSocketAddress;
17 import java.net.Proxy;
18 import java.net.ProxySelector;
19 import java.net.SocketAddress;
20 import java.net.URI;
21 import java.net.URL;
22 import java.util.Collections;
23 import java.util.List;
24
25 import org.junit.Test;
26
27 public class HttpSupportTest {
28
29 private static class TestProxySelector extends ProxySelector {
30
31 private static final Proxy DUMMY = new Proxy(Proxy.Type.HTTP,
32 InetSocketAddress.createUnresolved("localhost", 0));
33
34 @Override
35 public List<Proxy> select(URI uri) {
36 if ("http".equals(uri.getScheme())
37 && "somehost".equals(uri.getHost())) {
38 return Collections.singletonList(DUMMY);
39 }
40 return Collections.singletonList(Proxy.NO_PROXY);
41 }
42
43 @Override
44 public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
45
46 }
47 }
48
49 @Test
50 public void testMalformedUri() throws Exception {
51
52
53
54
55 Proxy proxy = HttpSupport.proxyFor(new TestProxySelector(), new URL(
56 "http://infor\\c.jones@somehost/somewhere/someproject.git"));
57 assertNotNull(proxy);
58 assertEquals(Proxy.Type.HTTP, proxy.type());
59 }
60
61 @Test
62 public void testCorrectUri() throws Exception {
63
64 Proxy proxy = HttpSupport.proxyFor(new TestProxySelector(), new URL(
65 "http://infor%5Cc.jones@somehost/somewhere/someproject.git"));
66 assertNotNull(proxy);
67 assertEquals(Proxy.Type.HTTP, proxy.type());
68 }
69 }