You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2013/06/16 13:50:53 UTC
git commit: rename classes as they are not abstract
Updated Branches:
refs/heads/master 13872fd9e -> 55de589b4
rename classes as they are not abstract
Project: http://git-wip-us.apache.org/repos/asf/maven-wagon/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-wagon/commit/55de589b
Tree: http://git-wip-us.apache.org/repos/asf/maven-wagon/tree/55de589b
Diff: http://git-wip-us.apache.org/repos/asf/maven-wagon/diff/55de589b
Branch: refs/heads/master
Commit: 55de589b468db9862c2480973d8f44fb91464e21
Parents: 13872fd
Author: Olivier Lamy <ol...@apache.org>
Authored: Sun Jun 16 21:50:45 2013 +1000
Committer: Olivier Lamy <ol...@apache.org>
Committed: Sun Jun 16 21:50:45 2013 +1000
----------------------------------------------------------------------
.../http/AbstractHttpClientWagonTest.java | 158 ------------
.../providers/http/HttpClientWagonTest.java | 158 ++++++++++++
.../webdav/AbstractHttpClientWagonTest.java | 240 -------------------
.../providers/webdav/HttpClientWagonTest.java | 240 +++++++++++++++++++
4 files changed, 398 insertions(+), 398 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/55de589b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagonTest.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagonTest.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagonTest.java
deleted file mode 100644
index b8ed344..0000000
--- a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagonTest.java
+++ /dev/null
@@ -1,158 +0,0 @@
-package org.apache.maven.wagon.providers.http;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import junit.framework.TestCase;
-import org.apache.http.Header;
-import org.apache.http.client.methods.HttpHead;
-import org.apache.http.client.params.ClientPNames;
-import org.apache.http.params.HttpParams;
-import org.apache.maven.wagon.OutputData;
-import org.apache.maven.wagon.TransferFailedException;
-
-public class AbstractHttpClientWagonTest
- extends TestCase
-{
-
- public void testSetPreemptiveAuthParamViaConfig()
- {
- HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
- //X TODO methodConfig.addParam( HttpClientParams.PREEMPTIVE_AUTHENTICATION, "%b,true" );
-
- HttpConfiguration config = new HttpConfiguration();
- config.setAll( methodConfig );
-
- TestWagon wagon = new TestWagon();
- wagon.setHttpConfiguration( config );
-
- HttpHead method = new HttpHead();
- wagon.setParameters( method );
-
- HttpParams params = method.getParams();
- assertNotNull( params );
- //X TODO assertTrue( params.isParameterTrue( HttpClientParams.PREEMPTIVE_AUTHENTICATION ) );
- }
-
- public void testSetMaxRedirectsParamViaConfig()
- {
- HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
- int maxRedirects = 2;
- methodConfig.addParam( ClientPNames.MAX_REDIRECTS, "%i," + maxRedirects );
-
- HttpConfiguration config = new HttpConfiguration();
- config.setAll( methodConfig );
-
- TestWagon wagon = new TestWagon();
- wagon.setHttpConfiguration( config );
-
- HttpHead method = new HttpHead();
- wagon.setParameters( method );
-
- HttpParams params = method.getParams();
- assertNotNull( params );
- assertEquals( maxRedirects, params.getIntParameter( ClientPNames.MAX_REDIRECTS, -1 ) );
- }
-
- public void testDefaultHeadersUsedByDefault()
- {
- HttpConfiguration config = new HttpConfiguration();
- config.setAll( new HttpMethodConfiguration() );
-
- TestWagon wagon = new TestWagon();
- wagon.setHttpConfiguration( config );
-
- HttpHead method = new HttpHead();
- wagon.setHeaders( method );
-
- // these are the default headers.
- // method.addRequestHeader( "Cache-control", "no-cache" );
- // method.addRequestHeader( "Cache-store", "no-store" );
- // method.addRequestHeader( "Pragma", "no-cache" );
- // method.addRequestHeader( "Expires", "0" );
- // method.addRequestHeader( "Accept-Encoding", "gzip" );
-
- Header header = method.getFirstHeader( "Cache-control" );
- assertNotNull( header );
- assertEquals( "no-cache", header.getValue() );
-
- header = method.getFirstHeader( "Cache-store" );
- assertNotNull( header );
- assertEquals( "no-store", header.getValue() );
-
- header = method.getFirstHeader( "Pragma" );
- assertNotNull( header );
- assertEquals( "no-cache", header.getValue() );
-
- header = method.getFirstHeader( "Expires" );
- assertNotNull( header );
- assertEquals( "0", header.getValue() );
-
- header = method.getFirstHeader( "Accept-Encoding" );
- assertNotNull( header );
- assertEquals( "gzip", header.getValue() );
- }
-
- public void testTurnOffDefaultHeaders()
- {
- HttpConfiguration config = new HttpConfiguration();
- config.setAll( new HttpMethodConfiguration().setUseDefaultHeaders( false ) );
-
- TestWagon wagon = new TestWagon();
- wagon.setHttpConfiguration( config );
-
- HttpHead method = new HttpHead();
- wagon.setHeaders( method );
-
- // these are the default headers.
- // method.addRequestHeader( "Cache-control", "no-cache" );
- // method.addRequestHeader( "Cache-store", "no-store" );
- // method.addRequestHeader( "Pragma", "no-cache" );
- // method.addRequestHeader( "Expires", "0" );
- // method.addRequestHeader( "Accept-Encoding", "gzip" );
-
- Header header = method.getFirstHeader( "Cache-control" );
- assertNull( header );
-
- header = method.getFirstHeader( "Cache-store" );
- assertNull( header );
-
- header = method.getFirstHeader( "Pragma" );
- assertNull( header );
-
- header = method.getFirstHeader( "Expires" );
- assertNull( header );
-
- header = method.getFirstHeader( "Accept-Encoding" );
- assertNull( header );
- }
-
- private static final class TestWagon
- extends AbstractHttpClientWagon
- {
- @Override
- public void fillOutputData( OutputData outputData )
- throws TransferFailedException
- {
-
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/55de589b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java
new file mode 100644
index 0000000..c70f1a3
--- /dev/null
+++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java
@@ -0,0 +1,158 @@
+package org.apache.maven.wagon.providers.http;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import junit.framework.TestCase;
+import org.apache.http.Header;
+import org.apache.http.client.methods.HttpHead;
+import org.apache.http.client.params.ClientPNames;
+import org.apache.http.params.HttpParams;
+import org.apache.maven.wagon.OutputData;
+import org.apache.maven.wagon.TransferFailedException;
+
+public class HttpClientWagonTest
+ extends TestCase
+{
+
+ public void testSetPreemptiveAuthParamViaConfig()
+ {
+ HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
+ //X TODO methodConfig.addParam( HttpClientParams.PREEMPTIVE_AUTHENTICATION, "%b,true" );
+
+ HttpConfiguration config = new HttpConfiguration();
+ config.setAll( methodConfig );
+
+ TestWagon wagon = new TestWagon();
+ wagon.setHttpConfiguration( config );
+
+ HttpHead method = new HttpHead();
+ wagon.setParameters( method );
+
+ HttpParams params = method.getParams();
+ assertNotNull( params );
+ //X TODO assertTrue( params.isParameterTrue( HttpClientParams.PREEMPTIVE_AUTHENTICATION ) );
+ }
+
+ public void testSetMaxRedirectsParamViaConfig()
+ {
+ HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
+ int maxRedirects = 2;
+ methodConfig.addParam( ClientPNames.MAX_REDIRECTS, "%i," + maxRedirects );
+
+ HttpConfiguration config = new HttpConfiguration();
+ config.setAll( methodConfig );
+
+ TestWagon wagon = new TestWagon();
+ wagon.setHttpConfiguration( config );
+
+ HttpHead method = new HttpHead();
+ wagon.setParameters( method );
+
+ HttpParams params = method.getParams();
+ assertNotNull( params );
+ assertEquals( maxRedirects, params.getIntParameter( ClientPNames.MAX_REDIRECTS, -1 ) );
+ }
+
+ public void testDefaultHeadersUsedByDefault()
+ {
+ HttpConfiguration config = new HttpConfiguration();
+ config.setAll( new HttpMethodConfiguration() );
+
+ TestWagon wagon = new TestWagon();
+ wagon.setHttpConfiguration( config );
+
+ HttpHead method = new HttpHead();
+ wagon.setHeaders( method );
+
+ // these are the default headers.
+ // method.addRequestHeader( "Cache-control", "no-cache" );
+ // method.addRequestHeader( "Cache-store", "no-store" );
+ // method.addRequestHeader( "Pragma", "no-cache" );
+ // method.addRequestHeader( "Expires", "0" );
+ // method.addRequestHeader( "Accept-Encoding", "gzip" );
+
+ Header header = method.getFirstHeader( "Cache-control" );
+ assertNotNull( header );
+ assertEquals( "no-cache", header.getValue() );
+
+ header = method.getFirstHeader( "Cache-store" );
+ assertNotNull( header );
+ assertEquals( "no-store", header.getValue() );
+
+ header = method.getFirstHeader( "Pragma" );
+ assertNotNull( header );
+ assertEquals( "no-cache", header.getValue() );
+
+ header = method.getFirstHeader( "Expires" );
+ assertNotNull( header );
+ assertEquals( "0", header.getValue() );
+
+ header = method.getFirstHeader( "Accept-Encoding" );
+ assertNotNull( header );
+ assertEquals( "gzip", header.getValue() );
+ }
+
+ public void testTurnOffDefaultHeaders()
+ {
+ HttpConfiguration config = new HttpConfiguration();
+ config.setAll( new HttpMethodConfiguration().setUseDefaultHeaders( false ) );
+
+ TestWagon wagon = new TestWagon();
+ wagon.setHttpConfiguration( config );
+
+ HttpHead method = new HttpHead();
+ wagon.setHeaders( method );
+
+ // these are the default headers.
+ // method.addRequestHeader( "Cache-control", "no-cache" );
+ // method.addRequestHeader( "Cache-store", "no-store" );
+ // method.addRequestHeader( "Pragma", "no-cache" );
+ // method.addRequestHeader( "Expires", "0" );
+ // method.addRequestHeader( "Accept-Encoding", "gzip" );
+
+ Header header = method.getFirstHeader( "Cache-control" );
+ assertNull( header );
+
+ header = method.getFirstHeader( "Cache-store" );
+ assertNull( header );
+
+ header = method.getFirstHeader( "Pragma" );
+ assertNull( header );
+
+ header = method.getFirstHeader( "Expires" );
+ assertNull( header );
+
+ header = method.getFirstHeader( "Accept-Encoding" );
+ assertNull( header );
+ }
+
+ private static final class TestWagon
+ extends AbstractHttpClientWagon
+ {
+ @Override
+ public void fillOutputData( OutputData outputData )
+ throws TransferFailedException
+ {
+
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/55de589b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/AbstractHttpClientWagonTest.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/AbstractHttpClientWagonTest.java b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/AbstractHttpClientWagonTest.java
deleted file mode 100644
index da55ad7..0000000
--- a/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/AbstractHttpClientWagonTest.java
+++ /dev/null
@@ -1,240 +0,0 @@
-package org.apache.maven.wagon.providers.webdav;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import junit.framework.TestCase;
-import org.apache.commons.httpclient.Credentials;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.NTCredentials;
-import org.apache.commons.httpclient.auth.AuthScope;
-import org.apache.commons.httpclient.methods.HeadMethod;
-import org.apache.commons.httpclient.params.HttpClientParams;
-import org.apache.commons.httpclient.params.HttpMethodParams;
-import org.apache.maven.wagon.ConnectionException;
-import org.apache.maven.wagon.OutputData;
-import org.apache.maven.wagon.TransferFailedException;
-import org.apache.maven.wagon.authentication.AuthenticationException;
-import org.apache.maven.wagon.authentication.AuthenticationInfo;
-import org.apache.maven.wagon.providers.webdav.AbstractHttpClientWagon;
-import org.apache.maven.wagon.providers.webdav.HttpConfiguration;
-import org.apache.maven.wagon.providers.webdav.HttpMethodConfiguration;
-import org.apache.maven.wagon.proxy.ProxyInfo;
-import org.apache.maven.wagon.repository.Repository;
-
-public class AbstractHttpClientWagonTest
- extends TestCase
-{
-
- public void testSetPreemptiveAuthParamViaConfig()
- {
- HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
- methodConfig.addParam( HttpClientParams.PREEMPTIVE_AUTHENTICATION, "%b,true" );
-
- HttpConfiguration config = new HttpConfiguration();
- config.setAll( methodConfig );
-
- TestWagon wagon = new TestWagon();
- wagon.setHttpConfiguration( config );
-
- HeadMethod method = new HeadMethod();
- wagon.setParameters( method );
-
- HttpMethodParams params = method.getParams();
- assertNotNull( params );
- assertTrue( params.isParameterTrue( HttpClientParams.PREEMPTIVE_AUTHENTICATION ) );
- }
-
- public void testSetMaxRedirectsParamViaConfig()
- {
- HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
- int maxRedirects = 2;
- methodConfig.addParam( HttpClientParams.MAX_REDIRECTS, "%i," + maxRedirects );
-
- HttpConfiguration config = new HttpConfiguration();
- config.setAll( methodConfig );
-
- TestWagon wagon = new TestWagon();
- wagon.setHttpConfiguration( config );
-
- HeadMethod method = new HeadMethod();
- wagon.setParameters( method );
-
- HttpMethodParams params = method.getParams();
- assertNotNull( params );
- assertEquals( maxRedirects, params.getIntParameter( HttpClientParams.MAX_REDIRECTS, -1 ) );
- }
-
- public void testDefaultHeadersUsedByDefault()
- {
- HttpConfiguration config = new HttpConfiguration();
- config.setAll( new HttpMethodConfiguration() );
-
- TestWagon wagon = new TestWagon();
- wagon.setHttpConfiguration( config );
-
- HeadMethod method = new HeadMethod();
- wagon.setHeaders( method );
-
- // these are the default headers.
- // method.addRequestHeader( "Cache-control", "no-cache" );
- // method.addRequestHeader( "Cache-store", "no-store" );
- // method.addRequestHeader( "Pragma", "no-cache" );
- // method.addRequestHeader( "Expires", "0" );
- // method.addRequestHeader( "Accept-Encoding", "gzip" );
-
- Header header = method.getRequestHeader( "Cache-control" );
- assertNotNull( header );
- assertEquals( "no-cache", header.getValue() );
-
- header = method.getRequestHeader( "Cache-store" );
- assertNotNull( header );
- assertEquals( "no-store", header.getValue() );
-
- header = method.getRequestHeader( "Pragma" );
- assertNotNull( header );
- assertEquals( "no-cache", header.getValue() );
-
- header = method.getRequestHeader( "Expires" );
- assertNotNull( header );
- assertEquals( "0", header.getValue() );
-
- header = method.getRequestHeader( "Accept-Encoding" );
- assertNotNull( header );
- assertEquals( "gzip", header.getValue() );
- }
-
- public void testTurnOffDefaultHeaders()
- {
- HttpConfiguration config = new HttpConfiguration();
- config.setAll( new HttpMethodConfiguration().setUseDefaultHeaders( false ) );
-
- TestWagon wagon = new TestWagon();
- wagon.setHttpConfiguration( config );
-
- HeadMethod method = new HeadMethod();
- wagon.setHeaders( method );
-
- // these are the default headers.
- // method.addRequestHeader( "Cache-control", "no-cache" );
- // method.addRequestHeader( "Cache-store", "no-store" );
- // method.addRequestHeader( "Pragma", "no-cache" );
- // method.addRequestHeader( "Expires", "0" );
- // method.addRequestHeader( "Accept-Encoding", "gzip" );
-
- Header header = method.getRequestHeader( "Cache-control" );
- assertNull( header );
-
- header = method.getRequestHeader( "Cache-store" );
- assertNull( header );
-
- header = method.getRequestHeader( "Pragma" );
- assertNull( header );
-
- header = method.getRequestHeader( "Expires" );
- assertNull( header );
-
- header = method.getRequestHeader( "Accept-Encoding" );
- assertNull( header );
- }
-
- public void testNTCredentialsWithUsernameNull()
- throws AuthenticationException, ConnectionException
- {
- TestWagon wagon = new TestWagon();
-
- Repository repository = new Repository( "mockRepoId", "mockRepoURL" );
- wagon.connect( repository );
-
- wagon.openConnection();
-
- assertNull( wagon.getAuthenticationInfo().getUserName() );
- assertNull( wagon.getAuthenticationInfo().getPassword() );
-
- assertFalse( wagon.getClient().getState().getCredentials( new AuthScope( null, 0 ) ) instanceof NTCredentials );
- }
-
- public void testNTCredentialsNoNTDomain()
- throws AuthenticationException, ConnectionException
- {
- TestWagon wagon = new TestWagon();
-
- AuthenticationInfo authenticationInfo = new AuthenticationInfo();
- String myUsernameNoNTDomain = "myUserNameNoNTDomain";
- authenticationInfo.setUserName( myUsernameNoNTDomain );
-
- String myPassword = "myPassword";
- authenticationInfo.setPassword( myPassword );
-
- Repository repository = new Repository( "mockRepoId", "mockRepoURL" );
-
- wagon.connect( repository, authenticationInfo, (ProxyInfo) null );
-
- wagon.openConnection();
-
- assertEquals( myUsernameNoNTDomain, wagon.getAuthenticationInfo().getUserName() );
- assertEquals( myPassword, wagon.getAuthenticationInfo().getPassword() );
-
- assertFalse( wagon.getClient().getState().getCredentials( new AuthScope( null, 0 ) ) instanceof NTCredentials );
- }
-
- public void testNTCredentialsWithNTDomain()
- throws AuthenticationException, ConnectionException
- {
- TestWagon wagon = new TestWagon();
-
- AuthenticationInfo authenticationInfo = new AuthenticationInfo();
- String myNTDomain = "myNTDomain";
- String myUsername = "myUsername";
- String myNTDomainAndUser = myNTDomain + "\\" + myUsername;
- authenticationInfo.setUserName( myNTDomainAndUser );
-
- String myPassword = "myPassword";
- authenticationInfo.setPassword( myPassword );
-
- Repository repository = new Repository( "mockRepoId", "mockRepoURL" );
-
- wagon.connect( repository, authenticationInfo, (ProxyInfo) null );
-
- wagon.openConnection();
-
- assertEquals( myNTDomainAndUser, wagon.getAuthenticationInfo().getUserName() );
- assertEquals( myPassword, wagon.getAuthenticationInfo().getPassword() );
-
- Credentials credentials = wagon.getClient().getState().getCredentials( new AuthScope( null, 0 ) );
- assertTrue( credentials instanceof NTCredentials );
-
- NTCredentials ntCredentials = (NTCredentials) credentials;
- assertEquals( myNTDomain, ntCredentials.getDomain() );
- assertEquals( myUsername, ntCredentials.getUserName() );
- assertEquals( myPassword, ntCredentials.getPassword() );
- }
-
- private static final class TestWagon
- extends AbstractHttpClientWagon
- {
- @Override
- public void fillOutputData( OutputData outputData )
- throws TransferFailedException
- {
-
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/55de589b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/HttpClientWagonTest.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/HttpClientWagonTest.java b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/HttpClientWagonTest.java
new file mode 100644
index 0000000..9aeeccd
--- /dev/null
+++ b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/HttpClientWagonTest.java
@@ -0,0 +1,240 @@
+package org.apache.maven.wagon.providers.webdav;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.NTCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.HeadMethod;
+import org.apache.commons.httpclient.params.HttpClientParams;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.maven.wagon.ConnectionException;
+import org.apache.maven.wagon.OutputData;
+import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.authentication.AuthenticationException;
+import org.apache.maven.wagon.authentication.AuthenticationInfo;
+import org.apache.maven.wagon.providers.webdav.AbstractHttpClientWagon;
+import org.apache.maven.wagon.providers.webdav.HttpConfiguration;
+import org.apache.maven.wagon.providers.webdav.HttpMethodConfiguration;
+import org.apache.maven.wagon.proxy.ProxyInfo;
+import org.apache.maven.wagon.repository.Repository;
+
+public class HttpClientWagonTest
+ extends TestCase
+{
+
+ public void testSetPreemptiveAuthParamViaConfig()
+ {
+ HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
+ methodConfig.addParam( HttpClientParams.PREEMPTIVE_AUTHENTICATION, "%b,true" );
+
+ HttpConfiguration config = new HttpConfiguration();
+ config.setAll( methodConfig );
+
+ TestWagon wagon = new TestWagon();
+ wagon.setHttpConfiguration( config );
+
+ HeadMethod method = new HeadMethod();
+ wagon.setParameters( method );
+
+ HttpMethodParams params = method.getParams();
+ assertNotNull( params );
+ assertTrue( params.isParameterTrue( HttpClientParams.PREEMPTIVE_AUTHENTICATION ) );
+ }
+
+ public void testSetMaxRedirectsParamViaConfig()
+ {
+ HttpMethodConfiguration methodConfig = new HttpMethodConfiguration();
+ int maxRedirects = 2;
+ methodConfig.addParam( HttpClientParams.MAX_REDIRECTS, "%i," + maxRedirects );
+
+ HttpConfiguration config = new HttpConfiguration();
+ config.setAll( methodConfig );
+
+ TestWagon wagon = new TestWagon();
+ wagon.setHttpConfiguration( config );
+
+ HeadMethod method = new HeadMethod();
+ wagon.setParameters( method );
+
+ HttpMethodParams params = method.getParams();
+ assertNotNull( params );
+ assertEquals( maxRedirects, params.getIntParameter( HttpClientParams.MAX_REDIRECTS, -1 ) );
+ }
+
+ public void testDefaultHeadersUsedByDefault()
+ {
+ HttpConfiguration config = new HttpConfiguration();
+ config.setAll( new HttpMethodConfiguration() );
+
+ TestWagon wagon = new TestWagon();
+ wagon.setHttpConfiguration( config );
+
+ HeadMethod method = new HeadMethod();
+ wagon.setHeaders( method );
+
+ // these are the default headers.
+ // method.addRequestHeader( "Cache-control", "no-cache" );
+ // method.addRequestHeader( "Cache-store", "no-store" );
+ // method.addRequestHeader( "Pragma", "no-cache" );
+ // method.addRequestHeader( "Expires", "0" );
+ // method.addRequestHeader( "Accept-Encoding", "gzip" );
+
+ Header header = method.getRequestHeader( "Cache-control" );
+ assertNotNull( header );
+ assertEquals( "no-cache", header.getValue() );
+
+ header = method.getRequestHeader( "Cache-store" );
+ assertNotNull( header );
+ assertEquals( "no-store", header.getValue() );
+
+ header = method.getRequestHeader( "Pragma" );
+ assertNotNull( header );
+ assertEquals( "no-cache", header.getValue() );
+
+ header = method.getRequestHeader( "Expires" );
+ assertNotNull( header );
+ assertEquals( "0", header.getValue() );
+
+ header = method.getRequestHeader( "Accept-Encoding" );
+ assertNotNull( header );
+ assertEquals( "gzip", header.getValue() );
+ }
+
+ public void testTurnOffDefaultHeaders()
+ {
+ HttpConfiguration config = new HttpConfiguration();
+ config.setAll( new HttpMethodConfiguration().setUseDefaultHeaders( false ) );
+
+ TestWagon wagon = new TestWagon();
+ wagon.setHttpConfiguration( config );
+
+ HeadMethod method = new HeadMethod();
+ wagon.setHeaders( method );
+
+ // these are the default headers.
+ // method.addRequestHeader( "Cache-control", "no-cache" );
+ // method.addRequestHeader( "Cache-store", "no-store" );
+ // method.addRequestHeader( "Pragma", "no-cache" );
+ // method.addRequestHeader( "Expires", "0" );
+ // method.addRequestHeader( "Accept-Encoding", "gzip" );
+
+ Header header = method.getRequestHeader( "Cache-control" );
+ assertNull( header );
+
+ header = method.getRequestHeader( "Cache-store" );
+ assertNull( header );
+
+ header = method.getRequestHeader( "Pragma" );
+ assertNull( header );
+
+ header = method.getRequestHeader( "Expires" );
+ assertNull( header );
+
+ header = method.getRequestHeader( "Accept-Encoding" );
+ assertNull( header );
+ }
+
+ public void testNTCredentialsWithUsernameNull()
+ throws AuthenticationException, ConnectionException
+ {
+ TestWagon wagon = new TestWagon();
+
+ Repository repository = new Repository( "mockRepoId", "mockRepoURL" );
+ wagon.connect( repository );
+
+ wagon.openConnection();
+
+ assertNull( wagon.getAuthenticationInfo().getUserName() );
+ assertNull( wagon.getAuthenticationInfo().getPassword() );
+
+ assertFalse( wagon.getClient().getState().getCredentials( new AuthScope( null, 0 ) ) instanceof NTCredentials );
+ }
+
+ public void testNTCredentialsNoNTDomain()
+ throws AuthenticationException, ConnectionException
+ {
+ TestWagon wagon = new TestWagon();
+
+ AuthenticationInfo authenticationInfo = new AuthenticationInfo();
+ String myUsernameNoNTDomain = "myUserNameNoNTDomain";
+ authenticationInfo.setUserName( myUsernameNoNTDomain );
+
+ String myPassword = "myPassword";
+ authenticationInfo.setPassword( myPassword );
+
+ Repository repository = new Repository( "mockRepoId", "mockRepoURL" );
+
+ wagon.connect( repository, authenticationInfo, (ProxyInfo) null );
+
+ wagon.openConnection();
+
+ assertEquals( myUsernameNoNTDomain, wagon.getAuthenticationInfo().getUserName() );
+ assertEquals( myPassword, wagon.getAuthenticationInfo().getPassword() );
+
+ assertFalse( wagon.getClient().getState().getCredentials( new AuthScope( null, 0 ) ) instanceof NTCredentials );
+ }
+
+ public void testNTCredentialsWithNTDomain()
+ throws AuthenticationException, ConnectionException
+ {
+ TestWagon wagon = new TestWagon();
+
+ AuthenticationInfo authenticationInfo = new AuthenticationInfo();
+ String myNTDomain = "myNTDomain";
+ String myUsername = "myUsername";
+ String myNTDomainAndUser = myNTDomain + "\\" + myUsername;
+ authenticationInfo.setUserName( myNTDomainAndUser );
+
+ String myPassword = "myPassword";
+ authenticationInfo.setPassword( myPassword );
+
+ Repository repository = new Repository( "mockRepoId", "mockRepoURL" );
+
+ wagon.connect( repository, authenticationInfo, (ProxyInfo) null );
+
+ wagon.openConnection();
+
+ assertEquals( myNTDomainAndUser, wagon.getAuthenticationInfo().getUserName() );
+ assertEquals( myPassword, wagon.getAuthenticationInfo().getPassword() );
+
+ Credentials credentials = wagon.getClient().getState().getCredentials( new AuthScope( null, 0 ) );
+ assertTrue( credentials instanceof NTCredentials );
+
+ NTCredentials ntCredentials = (NTCredentials) credentials;
+ assertEquals( myNTDomain, ntCredentials.getDomain() );
+ assertEquals( myUsername, ntCredentials.getUserName() );
+ assertEquals( myPassword, ntCredentials.getPassword() );
+ }
+
+ private static final class TestWagon
+ extends AbstractHttpClientWagon
+ {
+ @Override
+ public void fillOutputData( OutputData outputData )
+ throws TransferFailedException
+ {
+
+ }
+ }
+
+}