2
* ====================================================================
4
* Copyright 1999-2004 The Apache Software Foundation
6
* Licensed under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
17
* ====================================================================
19
* This software consists of voluntary contributions made by many
20
* individuals on behalf of the Apache Software Foundation. For more
21
* information on the Apache Software Foundation, please see
22
* <http://www.apache.org/>.
24
* [Additional notices, if required by prior licensing conditions]
28
package org.apache.commons.httpclient;
30
import junit.framework.Test;
31
import junit.framework.TestCase;
32
import junit.framework.TestSuite;
34
import org.apache.commons.httpclient.auth.AuthChallengeParser;
35
import org.apache.commons.httpclient.auth.MalformedChallengeException;
38
* Unit tests for {@link AuthChallengeParser}.
40
* @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
42
public class TestChallengeParser extends TestCase {
44
// ------------------------------------------------------------ Constructor
45
public TestChallengeParser(String testName) {
49
// ------------------------------------------------------------------- Main
50
public static void main(String args[]) {
51
String[] testCaseName = { TestChallengeParser.class.getName() };
52
junit.textui.TestRunner.main(testCaseName);
55
// ------------------------------------------------------- TestCase Methods
57
public static Test suite() {
58
return new TestSuite(TestChallengeParser.class);
62
public void testParsingChallenge() {
64
"Basic realm=\"realm1\", test, test1 = stuff, test2 = \"stuff, stuff\", test3=\"crap";
68
scheme = AuthChallengeParser.extractScheme(challenge);
69
elements = AuthChallengeParser.extractParams(challenge);
70
} catch (MalformedChallengeException e) {
71
fail("Unexpected exception: " + e.toString());
73
assertEquals("basic", scheme);
74
assertEquals("realm1", elements.get("realm"));
75
assertEquals(null, elements.get("test"));
76
assertEquals("stuff", elements.get("test1"));
77
assertEquals("stuff, stuff", elements.get("test2"));
78
assertEquals("\"crap", elements.get("test3"));