1   package org.apache.maven.wagon.providers.http;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
32   * @version $Id: LightweightHttpWagonTest.java 681203 2008-07-30 21:07:48Z brett $
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 }