This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
HttpClientProxyUtilTest.java
153 lines (126 loc) · 4.13 KB
/
HttpClientProxyUtilTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package org.sonatype.nexus.proxy.storage.remote.commonshttpclient;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import java.util.Set;
import org.apache.commons.httpclient.HttpClient;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonatype.nexus.proxy.repository.RemoteAuthenticationSettings;
import org.sonatype.nexus.proxy.repository.RemoteConnectionSettings;
import org.sonatype.nexus.proxy.repository.RemoteProxySettings;
import org.sonatype.nexus.proxy.storage.remote.DefaultRemoteStorageContext;
public class HttpClientProxyUtilTest
{
private final Logger logger = LoggerFactory.getLogger( getClass() );
@Test
public void testHttpClientProxyUtilUseDoesNotModifyContext()
{
final RemoteConnectionSettings remoteConnectionSettings = new RemoteConnectionSettings()
{
@Override
public void setUserAgentCustomizationString( String userAgentCustomizationString )
{
}
@Override
public void setRetrievalRetryCount( int retrievalRetryCount )
{
}
@Override
public void setQueryString( String queryString )
{
}
@Override
public void setConnectionTimeout( int connectionTimeout )
{
}
@Override
public String getUserAgentCustomizationString()
{
return null;
}
@Override
public int getRetrievalRetryCount()
{
return 3;
}
@Override
public String getQueryString()
{
return null;
}
@Override
public int getConnectionTimeout()
{
return 12000;
}
};
final RemoteProxySettings remoteProxySettings = new RemoteProxySettings()
{
@Override
public void setProxyAuthentication( RemoteAuthenticationSettings proxyAuthentication )
{
}
@Override
public void setPort( int port )
{
}
@Override
public void setNonProxyHosts( Set<String> nonProxyHosts )
{
}
@Override
public void setHostname( String hostname )
{
}
@Override
public void setBlockInheritance( boolean val )
{
}
@Override
public boolean isEnabled()
{
return false;
}
@Override
public boolean isBlockInheritance()
{
return false;
}
@Override
public RemoteAuthenticationSettings getProxyAuthentication()
{
return null;
}
@Override
public int getPort()
{
return 0;
}
@Override
public Set<String> getNonProxyHosts()
{
return null;
}
@Override
public String getHostname()
{
return null;
}
};
final DefaultRemoteStorageContext ctx = new DefaultRemoteStorageContext( null );
ctx.setRemoteConnectionSettings( remoteConnectionSettings );
ctx.setRemoteProxySettings( remoteProxySettings );
final HttpClient httpClient = new HttpClient();
// get last changed
long lastChanged = ctx.getLastChanged();
// 1st invocation, should modify it
HttpClientProxyUtil.applyProxyToHttpClient( httpClient, ctx, logger );
assertThat( ctx.getLastChanged(), greaterThan( lastChanged ) );
// now 2nd invocation, should not change
lastChanged = ctx.getLastChanged();
HttpClientProxyUtil.applyProxyToHttpClient( httpClient, ctx, logger );
assertThat( ctx.getLastChanged(), equalTo( lastChanged ) );
}
}