2
* $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 $
4
* $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
5
* ====================================================================
7
* Licensed to the Apache Software Foundation (ASF) under one or more
8
* contributor license agreements. See the NOTICE file distributed with
9
* this work for additional information regarding copyright ownership.
10
* The ASF licenses this file to You under the Apache License, Version 2.0
11
* (the "License"); you may not use this file except in compliance with
12
* the License. You may obtain a copy of the License at
14
* http://www.apache.org/licenses/LICENSE-2.0
16
* Unless required by applicable law or agreed to in writing, software
17
* distributed under the License is distributed on an "AS IS" BASIS,
18
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
* See the License for the specific language governing permissions and
20
* limitations under the License.
21
* ====================================================================
23
* This software consists of voluntary contributions made by many
24
* individuals on behalf of the Apache Software Foundation. For more
25
* information on the Apache Software Foundation, please see
26
* <http://www.apache.org/>.
28
* [Additional notices, if required by prior licensing conditions]
32
package org.apache.commons.httpclient;
34
import junit.framework.Test;
35
import junit.framework.TestCase;
36
import junit.framework.TestSuite;
39
* Unit tests for {@link Credentials}.
41
* @author Rodney Waldhoff
42
* @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
43
* @version $Id: TestCredentials.java 480424 2006-11-29 05:56:49Z bayard $
45
public class TestCredentials extends TestCase {
47
// ------------------------------------------------------------ Constructor
48
public TestCredentials(String testName) {
52
// ------------------------------------------------------------------- Main
53
public static void main(String args[]) {
54
String[] testCaseName = { TestCredentials.class.getName() };
55
junit.textui.TestRunner.main(testCaseName);
58
// ------------------------------------------------------- TestCase Methods
60
public static Test suite() {
61
return new TestSuite(TestCredentials.class);
64
public void testCredentialConstructors() {
66
new UsernamePasswordCredentials(null, null);
67
fail("IllegalArgumentException should have been thrown");
68
} catch (IllegalArgumentException e) {
72
new NTCredentials("user", "password", null, null);
73
fail("IllegalArgumentException should have been thrown");
74
} catch (IllegalArgumentException e) {
78
new NTCredentials("user", "password", "host", null);
79
fail("IllegalArgumentException should have been thrown");
80
} catch (IllegalArgumentException e) {
83
NTCredentials creds = new NTCredentials("user", null, "host", "domain");
84
assertNotNull(creds.getUserName());
85
assertNull(creds.getPassword());
86
assertNotNull(creds.getDomain());
87
assertNotNull(creds.getHost());
91
* Verifies that credentials report equal when they should.
93
public void testCredentialEquals() {
95
Credentials creds1 = new UsernamePasswordCredentials("user1", "password1");
96
Credentials creds1Again = new UsernamePasswordCredentials("user1", "password1");
97
Credentials creds2 = new UsernamePasswordCredentials("user2", "password2");
98
Credentials creds3 = new UsernamePasswordCredentials("user3", null);
99
Credentials creds3Again = new UsernamePasswordCredentials("user3", null);
101
assertEquals(creds1, creds1Again);
102
assertNotSame(creds1, creds2);
103
assertEquals(creds3, creds3Again);
105
Credentials ntCreds1 = new NTCredentials("user1", "password1", "host1", "domain1");
106
Credentials ntCreds1Again = new NTCredentials("user1", "password1", "host1", "domain1");
107
Credentials ntCreds2 = new NTCredentials("user1", "password2", "host1", "domain1");
108
Credentials ntCreds3 = new NTCredentials("user1", "password1", "host2", "domain1");
109
Credentials ntCreds4 = new NTCredentials("user1", "password1", "host1", "domain2");
111
assertEquals(ntCreds1, ntCreds1Again);
112
assertNotSame(ntCreds1, creds1);
113
assertNotSame(creds1, ntCreds1);
114
assertNotSame(ntCreds1, ntCreds2);
115
assertNotSame(ntCreds1, ntCreds3);
116
assertNotSame(ntCreds1, ntCreds4);