hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r653864 - in /httpcomponents/httpclient/trunk/module-client/src: main/java/org/apache/http/auth/ test/java/org/apache/http/auth/ test/java/org/apache/http/client/
Date Tue, 06 May 2008 18:12:39 GMT
Author: olegk
Date: Tue May  6 11:12:39 2008
New Revision: 653864

URL: http://svn.apache.org/viewvc?rev=653864&view=rev
Log:
* Refactored UsernamePasswordCredentials and NTCredentials (copied from HttpClient 3.1 code
line)
* Added test coverage

Added:
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/NTCredentials.java
      - copied, changed from r653863, httpcomponents/oac.hc3x/trunk/src/java/org/apache/commons/httpclient/NTCredentials.java
    httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/auth/
    httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/auth/TestAllAuth.java
  (with props)
    httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/auth/TestCredentials.java
  (with props)
Modified:
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/UsernamePasswordCredentials.java
    httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/TestAll.java

Copied: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/NTCredentials.java
(from r653863, httpcomponents/oac.hc3x/trunk/src/java/org/apache/commons/httpclient/NTCredentials.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/NTCredentials.java?p2=httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/NTCredentials.java&p1=httpcomponents/oac.hc3x/trunk/src/java/org/apache/commons/httpclient/NTCredentials.java&r1=653863&r2=653864&rev=653864&view=diff
==============================================================================
--- httpcomponents/oac.hc3x/trunk/src/java/org/apache/commons/httpclient/NTCredentials.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/NTCredentials.java
Tue May  6 11:12:39 2008
@@ -28,40 +28,63 @@
  *
  */
 
-package org.apache.commons.httpclient;
+package org.apache.http.auth;
 
-import org.apache.commons.httpclient.util.LangUtils;
+import java.util.Locale;
 
-/** {@link Credentials} for use with the NTLM authentication scheme which requires additional
- * information.
+import org.apache.http.util.LangUtils;
+
+/** {@link Credentials} specific to the Windows platform.
  *
  * @author <a href="mailto:adrian@ephox.com">Adrian Sutton</a>
  * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
- * 
- * @version $Revision$ $Date$
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  * 
  * @since 2.0
  */
-public class NTCredentials extends UsernamePasswordCredentials {
+public class NTCredentials implements Credentials {
 
-    // ----------------------------------------------------- Instance Variables
+    /** User name */
+    private final String userName;
 
+    /** Password */
+    private final String password;
+    
     /** The Domain to authenticate with.  */
-    private String domain;
+    private final String domain;
 
     /** The host the authentication request is originating from.  */
-    private String host;
-
-
-    // ----------------------------------------------------------- Constructors
+    private final String workstation;
 
     /**
-     * Default constructor.
-     * 
-     * @deprecated Do not use. Null user name, domain & host no longer allowed
+     * The constructor with the fully qualified username and password combined 
+     * string argument.
+     *
+     * @param usernamePassword the domain/username:password formed string
      */
-    public NTCredentials() {
+    public NTCredentials(String usernamePassword) {
         super();
+        if (usernamePassword == null) {
+            throw new IllegalArgumentException("Username:password string may not be null");
           
+        }
+        String username;
+        int atColon = usernamePassword.indexOf(':');
+        if (atColon >= 0) {
+            username = usernamePassword.substring(0, atColon);
+            this.password = usernamePassword.substring(atColon + 1);
+        } else {
+            username = usernamePassword;
+            this.password = null;
+        }
+        int atSlash = username.indexOf('/');
+        if (atSlash >= 0) {
+            this.domain = username.substring(0, atSlash).toUpperCase(Locale.ENGLISH);
+            this.userName = username.substring(atSlash + 1);
+        } else {
+            this.domain = null;
+            this.userName = username;
+        }
+        this.workstation = null;
     }
 
     /**
@@ -69,124 +92,106 @@
      * @param userName The user name.  This should not include the domain to authenticate
with.
      * For example: "user" is correct whereas "DOMAIN\\user" is not.
      * @param password The password.
-     * @param host The host the authentication request is originating from.  Essentially,
the
-     * computer name for this machine.
+     * @param workstation The workstation the authentication request is originating from.

+     * Essentially, the computer name for this machine.
      * @param domain The domain to authenticate within.
      */
-    public NTCredentials(String userName, String password, String host,
-            String domain) {
-        super(userName, password);
-        if (domain == null) {
-            throw new IllegalArgumentException("Domain may not be null");
-        }
-        this.domain = domain;
-        if (host == null) {
-            throw new IllegalArgumentException("Host may not be null");
+    public NTCredentials(
+            final String userName, 
+            final String password, 
+            final String workstation,
+            final String domain) {
+        super();
+        if (userName == null) {
+            throw new IllegalArgumentException("User name may not be null");
+        }
+        this.userName = userName;
+        this.password = password;
+        if (workstation != null) {
+            this.workstation = workstation.toUpperCase(Locale.ENGLISH);
+        } else {
+            this.workstation = null;
+        }
+        if (domain != null) {
+            this.domain = domain.toUpperCase(Locale.ENGLISH);
+        } else {
+            this.domain = null;
         }
-        this.host = host;
     }
-    // ------------------------------------------------------- Instance Methods
-
 
-    /**
-     * Sets the domain to authenticate with. The domain may not be null.
-     *
-     * @param domain the NT domain to authenticate in.
-     * 
-     * @see #getDomain()
-     * 
-     * @deprecated Do not use. The NTCredentials objects should be immutable
-     */
-    public void setDomain(String domain) {
-        if (domain == null) {
-            throw new IllegalArgumentException("Domain may not be null");
+    public String getUserName() {
+        return this.userName;
+    }
+    
+    public String getPrincipalName() {
+        if (this.domain != null && this.domain.length() > 0) {
+            StringBuilder buffer = new StringBuilder();
+            buffer.append(this.domain);
+            buffer.append('/');
+            buffer.append(this.userName);
+            return buffer.toString();
+        } else {
+            return this.userName;
         }
-        this.domain = domain;
+    }
+    
+    public String getPassword() {
+        return this.password;
     }
 
     /**
      * Retrieves the name to authenticate with.
      *
      * @return String the domain these credentials are intended to authenticate with.
-     * 
-     * @see #setDomain(String)
-     * 
      */
     public String getDomain() {
         return domain;
     }
 
-    /** 
-     * Sets the host name of the computer originating the request. The host name may
-     * not be null.
-     *
-     * @param host the Host the user is logged into.
-     * 
-     * @deprecated Do not use. The NTCredentials objects should be immutable
-     */
-    public void setHost(String host) {
-        if (host == null) {
-            throw new IllegalArgumentException("Host may not be null");
-        }
-        this.host = host;
-    }
-
     /**
-     * Retrieves the host name of the computer originating the request.
+     * Retrieves the workstation name of the computer originating the request.
      *
-     * @return String the host the user is logged into.
+     * @return String the workstation the user is logged into.
      */
-    public String getHost() {
-        return this.host;
+    public String getWorkstation() {
+        return this.workstation;
     }
     
-    /**
-     * Return a string representation of this object.
-     * @return A string represenation of this object.
-     */
-    public String toString() {
-        final StringBuffer sbResult = new StringBuffer(super.toString());
-        
-        sbResult.append("@");
-        sbResult.append(this.host);
-        sbResult.append(".");
-        sbResult.append(this.domain);
-
-        return sbResult.toString();
-    }
-
-    /**
-     * Computes a hash code based on all the case-sensitive parts of the credentials object.
-     *
-     * @return  The hash code for the credentials.
-     */
+    @Override
     public int hashCode() {
-        int hash = super.hashCode();
-        hash = LangUtils.hashCode(hash, this.host);
+        int hash = LangUtils.HASH_SEED;
+        hash = LangUtils.hashCode(hash, this.userName);
+        hash = LangUtils.hashCode(hash, this.workstation);
         hash = LangUtils.hashCode(hash, this.domain);
         return hash;
     }
 
-    /**
-     * Performs a case-sensitive check to see if the components of the credentials
-     * are the same.
-     *
-     * @param o  The object to match.
-     *
-     * @return <code>true</code> if all of the credentials match.
-     */
+    @Override
     public boolean equals(Object o) {
         if (o == null) return false;
         if (this == o) return true;
-        if (super.equals(o) ) {
-            if (o instanceof NTCredentials) {
-                NTCredentials that = (NTCredentials) o;
-
-                return LangUtils.equals(this.domain, that.domain)
-                    && LangUtils.equals(this.host, that.host);
+        if (o instanceof NTCredentials) {
+            NTCredentials that = (NTCredentials) o;
+            if (LangUtils.equals(this.userName, that.userName)
+                    && LangUtils.equals(this.workstation, that.workstation)
+                    && LangUtils.equals(this.domain, that.domain)) {
+                return true;
             }
         }
-
         return false;
     }
+
+    @Override
+    public String toString() {
+        StringBuilder buffer = new StringBuilder();
+        buffer.append("[username: ");
+        buffer.append(this.userName);
+        buffer.append("][workstation: ");
+        buffer.append(this.workstation);
+        buffer.append("][domain: ");
+        buffer.append(this.domain);
+        buffer.append("]");
+        return buffer.toString();
+    }
+
 }

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/UsernamePasswordCredentials.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/UsernamePasswordCredentials.java?rev=653864&r1=653863&r2=653864&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/UsernamePasswordCredentials.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/auth/UsernamePasswordCredentials.java
Tue May  6 11:12:39 2008
@@ -33,7 +33,7 @@
 import org.apache.http.util.LangUtils;
 
 /**
- * <p>Username and password {@link Credentials}.</p>
+ * Username and password {@link Credentials}
  *
  * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  * @author Sean C. Sullivan
@@ -45,8 +45,9 @@
  */
 public class UsernamePasswordCredentials implements Credentials {
 
-    // ----------------------------------------------------------- Constructors
-
+    private final String userName;
+    private final String password;
+     
     /**
      * The constructor with the username and password combined string argument.
      *
@@ -84,99 +85,46 @@
         this.password = password;
     }
 
-    // ----------------------------------------------------- Instance Variables
-
-    /**
-     * User name.
-     */
-    private final String userName;
-
-
-    /**
-     * Password.
-     */
-    private final String password;
-
-
-    // ------------------------------------------------------------- Properties
-
-
-    /**
-     * User name property getter.
-     *
-     * @return the userName
-     */
     public String getPrincipalName() {
         return userName;
     }
 
+    public String getUserName() {
+        return userName;
+    }
 
-    /**
-     * Password property getter.
-     *
-     * @return the password
-     */
     public String getPassword() {
         return password;
     }
 
-    
-    public String toText() {
-        return toString();
-    }
-
-
-    /**
-     * Get this object string.
-     *
-     * @return the username:password formed string
-     */
-    @Override
-    public String toString() {
-        StringBuilder result = new StringBuilder();
-        result.append(this.userName);
-        result.append(':');
-        result.append((this.password == null) ? "null" : this.password);
-        return result.toString();
-    }
-
-    /**
-     * Does a hash of both user name and password.
-     *
-     * @return The hash code including user name and password.
-     */
     @Override
     public int hashCode() {
         int hash = LangUtils.HASH_SEED;
         hash = LangUtils.hashCode(hash, this.userName);
-        hash = LangUtils.hashCode(hash, this.password);
         return hash;
     }
 
-    /**
-     * These credentials are assumed equal if the username and password are the
-     * same.
-     *
-     * @param o The other object to compare with.
-     *
-     * @return  <code>true</code> if the object is equivalent.
-     */
     @Override
     public boolean equals(Object o) {
         if (o == null) return false;
         if (this == o) return true;
-        // note - to allow for sub-classing, this checks that class is the same
-        // rather than do "instanceof".
-        if (this.getClass().equals(o.getClass())) {
+        if (o instanceof UsernamePasswordCredentials) {
             UsernamePasswordCredentials that = (UsernamePasswordCredentials) o;
-
-            if (LangUtils.equals(this.userName, that.userName)
-                    && LangUtils.equals(this.password, that.password) ) {
+            if (LangUtils.equals(this.userName, that.userName)) {
                 return true;
             }
         }
         return false;
     }
 
+    @Override
+    public String toString() {
+        StringBuilder buffer = new StringBuilder();
+        buffer.append("[username: ");
+        buffer.append(this.userName);
+        buffer.append("]");
+        return buffer.toString();
+    }
+
 }
 

Added: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/auth/TestAllAuth.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/auth/TestAllAuth.java?rev=653864&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/auth/TestAllAuth.java
(added)
+++ httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/auth/TestAllAuth.java
Tue May  6 11:12:39 2008
@@ -0,0 +1,54 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TestAllAuth extends TestCase {
+
+    public TestAllAuth(String testName) {
+        super(testName);
+    }
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite();
+        suite.addTest(TestCredentials.suite());
+        return suite;
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestAllAuth.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/auth/TestAllAuth.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/auth/TestAllAuth.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/auth/TestAllAuth.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/auth/TestCredentials.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/auth/TestCredentials.java?rev=653864&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/auth/TestCredentials.java
(added)
+++ httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/auth/TestCredentials.java
Tue May  6 11:12:39 2008
@@ -0,0 +1,203 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.auth;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TestCredentials extends TestCase {
+
+    // ------------------------------------------------------------ Constructor
+    public TestCredentials(final String testName) {
+        super(testName);
+    }
+
+    // ------------------------------------------------------------------- Main
+    public static void main(String args[]) {
+        String[] testCaseName = { TestCredentials.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    // ------------------------------------------------------- TestCase Methods
+
+    public static Test suite() {
+        return new TestSuite(TestCredentials.class);
+    }
+
+    public void testUsernamePasswordCredentialsBasics() {
+        UsernamePasswordCredentials creds1 = new UsernamePasswordCredentials(
+                "name", "pwd"); 
+        assertEquals("name", creds1.getUserName());
+        assertEquals("name", creds1.getPrincipalName());
+        assertEquals("pwd", creds1.getPassword());
+        assertEquals("[username: name]", creds1.toString());
+        UsernamePasswordCredentials creds2 = new UsernamePasswordCredentials(
+                "name:pwd"); 
+        assertEquals("name", creds2.getUserName());
+        assertEquals("name", creds2.getPrincipalName());
+        assertEquals("pwd", creds2.getPassword());
+        assertEquals("[username: name]", creds2.toString());
+        UsernamePasswordCredentials creds3 = new UsernamePasswordCredentials(
+            "name"); 
+        assertEquals("name", creds3.getUserName());
+        assertEquals("name", creds3.getPrincipalName());
+        assertEquals(null, creds3.getPassword());
+        assertEquals("[username: name]", creds3.toString());
+    }
+    
+    public void testNTCredentialsBasics() {
+        NTCredentials creds1 = new NTCredentials(
+                "name", "pwd", "localhost", "domain"); 
+        assertEquals("name", creds1.getUserName());
+        assertEquals("DOMAIN/name", creds1.getPrincipalName());
+        assertEquals("pwd", creds1.getPassword());
+        assertEquals("[username: name][workstation: LOCALHOST]" +
+                "[domain: DOMAIN]", creds1.toString());
+        NTCredentials creds2 = new NTCredentials(
+                "name", null, null, null); 
+        assertEquals("name", creds2.getUserName());
+        assertEquals("name", creds2.getPrincipalName());
+        assertEquals(null, creds2.getPassword());
+        assertEquals("[username: name][workstation: null]" +
+                "[domain: null]", creds2.toString());
+        NTCredentials creds3 = new NTCredentials(
+                "domain/name:pwd"); 
+        assertEquals("name", creds3.getUserName());
+        assertEquals("DOMAIN/name", creds3.getPrincipalName());
+        assertEquals("pwd", creds3.getPassword());
+        assertEquals("[username: name][workstation: null]" +
+                "[domain: DOMAIN]", creds3.toString());
+        NTCredentials creds4 = new NTCredentials(
+            "domain/name"); 
+        assertEquals("name", creds4.getUserName());
+        assertEquals("DOMAIN/name", creds4.getPrincipalName());
+        assertEquals(null, creds4.getPassword());
+        assertEquals("[username: name][workstation: null]" +
+                "[domain: DOMAIN]", creds4.toString());
+        NTCredentials creds5 = new NTCredentials(
+            "name"); 
+        assertEquals("name", creds5.getUserName());
+        assertEquals("name", creds5.getPrincipalName());
+        assertEquals(null, creds5.getPassword());
+        assertEquals("[username: name][workstation: null]" +
+                "[domain: null]", creds5.toString());
+    }
+ 
+    public void testUsernamePasswordCredentialsHashCode() {
+        UsernamePasswordCredentials creds1 = new UsernamePasswordCredentials(
+                "name", "pwd"); 
+        UsernamePasswordCredentials creds2 = new UsernamePasswordCredentials(
+                "othername", "pwd"); 
+        UsernamePasswordCredentials creds3 = new UsernamePasswordCredentials(
+                "name", "otherpwd"); 
+
+        assertTrue(creds1.hashCode() == creds1.hashCode());
+        assertTrue(creds1.hashCode() != creds2.hashCode());
+        assertTrue(creds1.hashCode() == creds3.hashCode());
+    }
+    
+    public void testUsernamePasswordCredentialsEquals() {
+        UsernamePasswordCredentials creds1 = new UsernamePasswordCredentials(
+                "name", "pwd"); 
+        UsernamePasswordCredentials creds2 = new UsernamePasswordCredentials(
+                "othername", "pwd"); 
+        UsernamePasswordCredentials creds3 = new UsernamePasswordCredentials(
+                "name", "otherpwd"); 
+
+        assertTrue(creds1.equals(creds1));
+        assertFalse(creds1.equals(creds2));
+        assertTrue(creds1.equals(creds3));
+    }
+    
+    public void testNTCredentialsHashCode() {
+        NTCredentials creds1 = new NTCredentials(
+                "name", "pwd", "somehost", "domain"); 
+        NTCredentials creds2 = new NTCredentials(
+                "othername", "pwd", "somehost", "domain"); 
+        NTCredentials creds3 = new NTCredentials(
+                "name", "otherpwd", "SomeHost", "Domain"); 
+        NTCredentials creds4 = new NTCredentials(
+                "name", "pwd", "otherhost", "domain"); 
+        NTCredentials creds5 = new NTCredentials(
+                "name", "pwd", null, "domain"); 
+        NTCredentials creds6 = new NTCredentials(
+                "name", "pwd", "somehost", "ms"); 
+        NTCredentials creds7 = new NTCredentials(
+                "name", "pwd", "somehost", null); 
+        NTCredentials creds8 = new NTCredentials(
+                "name", "pwd", null, "domain"); 
+        NTCredentials creds9 = new NTCredentials(
+                "name", "pwd", "somehost", null); 
+
+        assertTrue(creds1.hashCode() == creds1.hashCode());
+        assertTrue(creds1.hashCode() != creds2.hashCode());
+        assertTrue(creds1.hashCode() == creds3.hashCode());
+        assertFalse(creds1.hashCode() == creds4.hashCode());
+        assertFalse(creds1.hashCode() == creds5.hashCode());
+        assertFalse(creds1.hashCode() == creds6.hashCode());
+        assertFalse(creds1.hashCode() == creds7.hashCode());
+        assertTrue(creds8.hashCode() == creds5.hashCode());
+        assertTrue(creds9.hashCode() == creds7.hashCode());
+    }
+    
+    public void testNTCredentialsEquals() {
+        NTCredentials creds1 = new NTCredentials(
+                "name", "pwd", "somehost", "domain"); 
+        NTCredentials creds2 = new NTCredentials(
+                "othername", "pwd", "somehost", "domain"); 
+        NTCredentials creds3 = new NTCredentials(
+                "name", "otherpwd", "SomeHost", "Domain"); 
+        NTCredentials creds4 = new NTCredentials(
+                "name", "pwd", "otherhost", "domain"); 
+        NTCredentials creds5 = new NTCredentials(
+                "name", "pwd", null, "domain"); 
+        NTCredentials creds6 = new NTCredentials(
+                "name", "pwd", "somehost", "ms"); 
+        NTCredentials creds7 = new NTCredentials(
+                "name", "pwd", "somehost", null); 
+        NTCredentials creds8 = new NTCredentials(
+                "name", "pwd", null, "domain"); 
+        NTCredentials creds9 = new NTCredentials(
+                "name", "pwd", "somehost", null); 
+
+        assertTrue(creds1.equals(creds1));
+        assertFalse(creds1.equals(creds2));
+        assertTrue(creds1.equals(creds3));
+        assertFalse(creds1.equals(creds4));
+        assertFalse(creds1.equals(creds5));
+        assertFalse(creds1.equals(creds6));
+        assertFalse(creds1.equals(creds7));
+        assertTrue(creds8.equals(creds5));
+        assertTrue(creds9.equals(creds7));
+        
+    }
+}

Propchange: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/auth/TestCredentials.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/auth/TestCredentials.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/auth/TestCredentials.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/TestAll.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/TestAll.java?rev=653864&r1=653863&r2=653864&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/TestAll.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/TestAll.java
Tue May  6 11:12:39 2008
@@ -34,10 +34,12 @@
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
+import org.apache.http.auth.TestAllAuth;
 import org.apache.http.client.methods.TestAllMethods;
 import org.apache.http.client.protocol.TestAllProtocol;
 import org.apache.http.conn.TestAllConn;
 import org.apache.http.cookie.TestAllCookie;
+import org.apache.http.impl.auth.TestAllAuthImpl;
 import org.apache.http.impl.client.TestAllHttpClientImpl;
 import org.apache.http.impl.conn.TestAllConnImpl;
 import org.apache.http.impl.conn.tsccm.TestAllTSCCM;
@@ -53,12 +55,14 @@
         TestSuite suite = new TestSuite();
         suite.addTest(TestAllCookie.suite());
         suite.addTest(TestAllCookieImpl.suite());
-        suite.addTest(TestAllHttpClientImpl.suite());
+        suite.addTest(TestAllAuth.suite());
+        suite.addTest(TestAllAuthImpl.suite());
         suite.addTest(TestAllConn.suite());
         suite.addTest(TestAllConnImpl.suite());
         suite.addTest(TestAllTSCCM.suite());
         suite.addTest(TestAllProtocol.suite());        
         suite.addTest(TestAllMethods.suite());        
+        suite.addTest(TestAllHttpClientImpl.suite());
         return suite;
     }
 



Mime
View raw message