1 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 ; 34 import org.apache.commons.httpclient.auth.AuthChallengeParser; 35 import org.apache.commons.httpclient.auth.MalformedChallengeException; 36 37 42 public class TestChallengeParser extends TestCase { 43 44 public TestChallengeParser(String testName) { 46 super(testName); 47 } 48 49 public static void main(String args[]) { 51 String [] testCaseName = { TestChallengeParser.class.getName() }; 52 junit.textui.TestRunner.main(testCaseName); 53 } 54 55 57 public static Test suite() { 58 return new TestSuite(TestChallengeParser.class); 59 } 60 61 62 public void testParsingChallenge() { 63 String challenge = 64 "Basic realm=\"realm1\", test, test1 = stuff, test2 = \"stuff, stuff\", test3=\"crap"; 65 String scheme = null; 66 Map 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 |