This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
And a fix for a slipped in bug.
- Loading branch information
Showing
2 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
...va/org/sonatype/nexus/proxy/storage/remote/commonshttpclient/HttpClientProxyUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 ) ); | ||
} | ||
|
||
} |