1   /*
2    * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/auth/TestChallengeParser.java,v 1.1 2004/03/25 20:37:20 olegk Exp $
3    * $Revision: 155418 $
4    * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
5    * ====================================================================
6    *
7    *  Copyright 1999-2004 The Apache Software Foundation
8    *
9    *  Licensed under the Apache License, Version 2.0 (the "License");
10   *  you may not use this file except in compliance with the License.
11   *  You may obtain a copy of the License at
12   *
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   *
15   *  Unless required by applicable law or agreed to in writing, software
16   *  distributed under the License is distributed on an "AS IS" BASIS,
17   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   *  See the License for the specific language governing permissions and
19   *  limitations under the License.
20   * ====================================================================
21   *
22   * This software consists of voluntary contributions made by many
23   * individuals on behalf of the Apache Software Foundation.  For more
24   * information on the Apache Software Foundation, please see
25   * <http://www.apache.org/>.
26   *
27   * [Additional notices, if required by prior licensing conditions]
28   *
29   */
30  
31  package org.apache.commons.httpclient.auth;
32  
33  import junit.framework.Test;
34  import junit.framework.TestCase;
35  import junit.framework.TestSuite;
36  import java.util.Map;
37  import org.apache.commons.httpclient.auth.AuthChallengeParser;
38  import org.apache.commons.httpclient.auth.MalformedChallengeException; 
39  
40  /***
41   * Unit tests for {@link AuthChallengeParser}.
42   *
43   * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
44   */
45  public class TestChallengeParser extends TestCase {
46  
47      // ------------------------------------------------------------ Constructor
48      public TestChallengeParser(String testName) {
49          super(testName);
50      }
51  
52      // ------------------------------------------------------------------- Main
53      public static void main(String args[]) {
54          String[] testCaseName = { TestChallengeParser.class.getName() };
55          junit.textui.TestRunner.main(testCaseName);
56      }
57  
58      // ------------------------------------------------------- TestCase Methods
59  
60      public static Test suite() {
61          return new TestSuite(TestChallengeParser.class);
62      }
63  
64  
65      public void testParsingChallenge() {
66          String challenge = 
67            "Basic realm=\"realm1\", test, test1 =  stuff, test2 =  \"stuff, stuff\", test3=\"crap";
68          String scheme = null;
69          Map elements = null;
70          try {
71              scheme = AuthChallengeParser.extractScheme(challenge);
72              elements = AuthChallengeParser.extractParams(challenge);
73          } catch (MalformedChallengeException e) {
74              fail("Unexpected exception: " + e.toString());
75          }
76          assertEquals("basic", scheme);
77          assertEquals("realm1", elements.get("realm"));
78          assertEquals(null, elements.get("test"));
79          assertEquals("stuff", elements.get("test1"));
80          assertEquals("stuff, stuff", elements.get("test2"));
81          assertEquals("\"crap", elements.get("test3"));
82      }
83  }