KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > httpclient > TestChallengeParser


1 /*
2  * ====================================================================
3  *
4  * Copyright 1999-2004 The Apache Software Foundation
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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  * ====================================================================
18  *
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/>.
23  *
24  * [Additional notices, if required by prior licensing conditions]
25  *
26  */

27
28 package org.apache.commons.httpclient;
29
30 import junit.framework.Test;
31 import junit.framework.TestCase;
32 import junit.framework.TestSuite;
33 import java.util.Map JavaDoc;
34 import org.apache.commons.httpclient.auth.AuthChallengeParser;
35 import org.apache.commons.httpclient.auth.MalformedChallengeException;
36
37 /**
38  * Unit tests for {@link AuthChallengeParser}.
39  *
40  * @author <a HREF="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
41  */

42 public class TestChallengeParser extends TestCase {
43
44     // ------------------------------------------------------------ Constructor
45
public TestChallengeParser(String JavaDoc testName) {
46         super(testName);
47     }
48
49     // ------------------------------------------------------------------- Main
50
public static void main(String JavaDoc args[]) {
51         String JavaDoc[] testCaseName = { TestChallengeParser.class.getName() };
52         junit.textui.TestRunner.main(testCaseName);
53     }
54
55     // ------------------------------------------------------- TestCase Methods
56

57     public static Test suite() {
58         return new TestSuite(TestChallengeParser.class);
59     }
60
61
62     public void testParsingChallenge() {
63         String JavaDoc challenge =
64           "Basic realm=\"realm1\", test, test1 = stuff, test2 = \"stuff, stuff\", test3=\"crap";
65         String JavaDoc scheme = null;
66         Map JavaDoc elements = null;
67         try {
68             scheme = AuthChallengeParser.extractScheme(challenge);
69             elements = AuthChallengeParser.extractParams(challenge);
70         } catch (MalformedChallengeException e) {
71             fail("Unexpected exception: " + e.toString());
72         }
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"));
79     }
80 }
81
Popular Tags