001: /*
002: * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/TestCredentials.java,v 1.1 2004/10/31 13:46:54 olegk Exp $
003: * $Revision: 480424 $
004: * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
005: * ====================================================================
006: *
007: * Licensed to the Apache Software Foundation (ASF) under one or more
008: * contributor license agreements. See the NOTICE file distributed with
009: * this work for additional information regarding copyright ownership.
010: * The ASF licenses this file to You under the Apache License, Version 2.0
011: * (the "License"); you may not use this file except in compliance with
012: * the License. You may obtain a copy of the License at
013: *
014: * http://www.apache.org/licenses/LICENSE-2.0
015: *
016: * Unless required by applicable law or agreed to in writing, software
017: * distributed under the License is distributed on an "AS IS" BASIS,
018: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019: * See the License for the specific language governing permissions and
020: * limitations under the License.
021: * ====================================================================
022: *
023: * This software consists of voluntary contributions made by many
024: * individuals on behalf of the Apache Software Foundation. For more
025: * information on the Apache Software Foundation, please see
026: * <http://www.apache.org/>.
027: *
028: * [Additional notices, if required by prior licensing conditions]
029: *
030: */
031:
032: package org.apache.commons.httpclient;
033:
034: import junit.framework.Test;
035: import junit.framework.TestCase;
036: import junit.framework.TestSuite;
037:
038: /**
039: * Unit tests for {@link Credentials}.
040: *
041: * @author Rodney Waldhoff
042: * @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
043: * @version $Id: TestCredentials.java 480424 2006-11-29 05:56:49Z bayard $
044: */
045: public class TestCredentials extends TestCase {
046:
047: // ------------------------------------------------------------ Constructor
048: public TestCredentials(String testName) {
049: super (testName);
050: }
051:
052: // ------------------------------------------------------------------- Main
053: public static void main(String args[]) {
054: String[] testCaseName = { TestCredentials.class.getName() };
055: junit.textui.TestRunner.main(testCaseName);
056: }
057:
058: // ------------------------------------------------------- TestCase Methods
059:
060: public static Test suite() {
061: return new TestSuite(TestCredentials.class);
062: }
063:
064: public void testCredentialConstructors() {
065: try {
066: new UsernamePasswordCredentials(null, null);
067: fail("IllegalArgumentException should have been thrown");
068: } catch (IllegalArgumentException e) {
069: // expected
070: }
071: try {
072: new NTCredentials("user", "password", null, null);
073: fail("IllegalArgumentException should have been thrown");
074: } catch (IllegalArgumentException e) {
075: // expected
076: }
077: try {
078: new NTCredentials("user", "password", "host", null);
079: fail("IllegalArgumentException should have been thrown");
080: } catch (IllegalArgumentException e) {
081: // expected
082: }
083: NTCredentials creds = new NTCredentials("user", null, "host",
084: "domain");
085: assertNotNull(creds.getUserName());
086: assertNull(creds.getPassword());
087: assertNotNull(creds.getDomain());
088: assertNotNull(creds.getHost());
089: }
090:
091: /**
092: * Verifies that credentials report equal when they should.
093: */
094: public void testCredentialEquals() {
095:
096: Credentials creds1 = new UsernamePasswordCredentials("user1",
097: "password1");
098: Credentials creds1Again = new UsernamePasswordCredentials(
099: "user1", "password1");
100: Credentials creds2 = new UsernamePasswordCredentials("user2",
101: "password2");
102: Credentials creds3 = new UsernamePasswordCredentials("user3",
103: null);
104: Credentials creds3Again = new UsernamePasswordCredentials(
105: "user3", null);
106:
107: assertEquals(creds1, creds1Again);
108: assertNotSame(creds1, creds2);
109: assertEquals(creds3, creds3Again);
110:
111: Credentials ntCreds1 = new NTCredentials("user1", "password1",
112: "host1", "domain1");
113: Credentials ntCreds1Again = new NTCredentials("user1",
114: "password1", "host1", "domain1");
115: Credentials ntCreds2 = new NTCredentials("user1", "password2",
116: "host1", "domain1");
117: Credentials ntCreds3 = new NTCredentials("user1", "password1",
118: "host2", "domain1");
119: Credentials ntCreds4 = new NTCredentials("user1", "password1",
120: "host1", "domain2");
121:
122: assertEquals(ntCreds1, ntCreds1Again);
123: assertNotSame(ntCreds1, creds1);
124: assertNotSame(creds1, ntCreds1);
125: assertNotSame(ntCreds1, ntCreds2);
126: assertNotSame(ntCreds1, ntCreds3);
127: assertNotSame(ntCreds1, ntCreds4);
128: }
129: }
|