1 package org.apache.maven.wagon.providers.http;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Properties;
23
24 import org.apache.maven.wagon.StreamingWagon;
25 import org.apache.maven.wagon.Wagon;
26 import org.apache.maven.wagon.http.HttpWagonTestCase;
27 import org.apache.maven.wagon.proxy.ProxyInfo;
28 import org.apache.maven.wagon.repository.Repository;
29
30
31
32
33
34 public class LightweightHttpWagonTest
35 extends HttpWagonTestCase
36 {
37 protected String getProtocol()
38 {
39 return "http";
40 }
41
42 protected String getTestRepositoryUrl()
43 {
44 return getProtocol() + "://localhost:10007/";
45 }
46
47 protected void setHttpHeaders( StreamingWagon wagon, Properties properties )
48 {
49 ( (LightweightHttpWagon) wagon ).setHttpHeaders( properties );
50 }
51
52 public void testProxyReset()
53 throws Exception
54 {
55 ProxyInfo proxyInfo = new ProxyInfo();
56 proxyInfo.setType( "http" );
57 proxyInfo.setHost( "proxyhost" );
58 proxyInfo.setPort( 1234 );
59 proxyInfo.setNonProxyHosts( "non" );
60
61 Repository repository = new Repository();
62
63 String proxyHost = System.getProperty( "http.proxyHost" );
64 String proxyPort = System.getProperty( "http.proxyPort" );
65 String nonProxyHosts = System.getProperty( "http.nonProxyHosts" );
66
67 System.getProperties().remove( "http.proxyHost" );
68 System.getProperties().remove( "http.proxyPort" );
69
70 Wagon wagon = getWagon();
71
72 wagon.connect( repository, proxyInfo );
73
74 assertEquals( "proxyhost", System.getProperty( "http.proxyHost" ) );
75 assertEquals( "1234", System.getProperty( "http.proxyPort" ) );
76 assertEquals( "non", System.getProperty( "http.nonProxyHosts" ) );
77
78 wagon.disconnect();
79
80 assertNull( System.getProperty( "http.proxyHost" ) );
81 assertNull( System.getProperty( "http.proxyPort" ) );
82
83 System.setProperty( "http.proxyHost", "host" );
84 System.setProperty( "http.proxyPort", "port" );
85 System.setProperty( "http.nonProxyHosts", "hosts" );
86
87 wagon = getWagon();
88
89 wagon.connect( repository, proxyInfo );
90
91 assertEquals( "proxyhost", System.getProperty( "http.proxyHost" ) );
92 assertEquals( "1234", System.getProperty( "http.proxyPort" ) );
93 assertEquals( "non", System.getProperty( "http.nonProxyHosts" ) );
94
95 wagon.disconnect();
96
97 assertEquals( "host", System.getProperty( "http.proxyHost" ) );
98 assertEquals( "port", System.getProperty( "http.proxyPort" ) );
99 assertEquals( "hosts", System.getProperty( "http.nonProxyHosts" ) );
100
101 wagon = getWagon();
102
103 wagon.connect( repository );
104
105 assertNull( System.getProperty( "http.proxyHost" ) );
106 assertNull( System.getProperty( "http.proxyPort" ) );
107
108 wagon.disconnect();
109
110 assertEquals( "host", System.getProperty( "http.proxyHost" ) );
111 assertEquals( "port", System.getProperty( "http.proxyPort" ) );
112 assertEquals( "hosts", System.getProperty( "http.nonProxyHosts" ) );
113
114 if ( proxyHost != null )
115 {
116 System.setProperty( "http.proxyHost", proxyHost );
117 }
118 else
119 {
120 System.getProperties().remove( "http.proxyHost" );
121 }
122 if ( proxyPort != null )
123 {
124 System.setProperty( "http.proxyPort", proxyPort );
125 }
126 else
127 {
128 System.getProperties().remove( "http.proxyPort" );
129 }
130 if ( nonProxyHosts != null )
131 {
132 System.setProperty( "http.nonProxyHosts", nonProxyHosts );
133 }
134 else
135 {
136 System.getProperties().remove( "http.nonProxyHosts" );
137 }
138 }
139 }