1 /* 2 * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHeaderElement.java,v 1.5 2003/01/28 04:40:23 jsdever Exp $ 3 * $Revision: 1.5 $ 4 * $Date: 2003/01/28 04:40:23 $ 5 * ==================================================================== 6 * 7 * The Apache Software License, Version 1.1 8 * 9 * Copyright (c) 1999-2003 The Apache Software Foundation. All rights 10 * reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in 21 * the documentation and/or other materials provided with the 22 * distribution. 23 * 24 * 3. The end-user documentation included with the redistribution, if 25 * any, must include the following acknowlegement: 26 * "This product includes software developed by the 27 * Apache Software Foundation (http://www.apache.org/)." 28 * Alternately, this acknowlegement may appear in the software itself, 29 * if and wherever such third-party acknowlegements normally appear. 30 * 31 * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software 32 * Foundation" must not be used to endorse or promote products derived 33 * from this software without prior written permission. For written 34 * permission, please contact apache@apache.org. 35 * 36 * 5. Products derived from this software may not be called "Apache" 37 * nor may "Apache" appear in their names without prior written 38 * permission of the Apache Group. 39 * 40 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 41 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 42 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 43 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 47 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 48 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 49 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 50 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 * SUCH DAMAGE. 52 * ==================================================================== 53 * 54 * This software consists of voluntary contributions made by many 55 * individuals on behalf of the Apache Software Foundation. For more 56 * information on the Apache Software Foundation, please see 57 * <http://www.apache.org/>. 58 * 59 * [Additional notices, if required by prior licensing conditions] 60 * 61 */ 62 63 package org.apache.commons.httpclient; 64 65 import junit.framework.*; 66 67 /*** 68 * Simple tests for {@link HeaderElement}. 69 * 70 * @author Rodney Waldhoff 71 * @author <a href="mailto:bcholmes@interlog.com">B.C. Holmes</a> 72 * @author <a href="mailto:jericho@thinkfree.com">Park, Sung-Gu</a> 73 * @version $Id: TestHeaderElement.java,v 1.5 2003/01/28 04:40:23 jsdever Exp $ 74 */ 75 public class TestHeaderElement extends TestNVP { 76 77 // ------------------------------------------------------------ Constructor 78 public TestHeaderElement(String testName) { 79 super(testName); 80 } 81 82 // ------------------------------------------------------------------- Main 83 public static void main(String args[]) { 84 String[] testCaseName = { TestHeaderElement.class.getName() }; 85 junit.textui.TestRunner.main(testCaseName); 86 } 87 88 // ------------------------------------------------------- TestCase Methods 89 90 public static Test suite() { 91 return new TestSuite(TestHeaderElement.class); 92 } 93 94 // ------------------------------------------------------ Protected Methods 95 96 protected NameValuePair makePair() { 97 return new HeaderElement(); 98 } 99 100 protected NameValuePair makePair(String name, String value) { 101 return new HeaderElement(name,value); 102 } 103 104 105 // ----------------------------------------------------------- Test Methods 106 107 public void testOldMain() throws Exception { 108 // this is derived from the old main method in HeaderElement 109 String headerValue = "name1 = value1; name2; name3=\"value3\" , name4=value4; " + 110 "name5=value5, name6= ; name7 = value7; name8 = \" value8\""; 111 HeaderElement[] elements = HeaderElement.parse(headerValue); 112 // there are 3 elements 113 assertEquals(3,elements.length); 114 // 1st element 115 assertEquals("name1",elements[0].getName()); 116 assertEquals("value1",elements[0].getValue()); 117 // 1st element has 2 getParameters() 118 assertEquals(2,elements[0].getParameters().length); 119 assertEquals("name2",elements[0].getParameters()[0].getName()); 120 assertTrue(null == elements[0].getParameters()[0].getValue()); 121 assertEquals("name3",elements[0].getParameters()[1].getName()); 122 assertEquals("value3",elements[0].getParameters()[1].getValue()); 123 // 2nd element 124 assertEquals("name4",elements[1].getName()); 125 assertEquals("value4",elements[1].getValue()); 126 // 2nd element has 1 parameter 127 assertEquals(1,elements[1].getParameters().length); 128 assertEquals("name5",elements[1].getParameters()[0].getName()); 129 assertEquals("value5",elements[1].getParameters()[0].getValue()); 130 // 3rd element 131 assertEquals("name6",elements[2].getName()); 132 assertTrue(null == elements[2].getValue()); 133 // 3rd element has 2 getParameters() 134 assertEquals(2,elements[2].getParameters().length); 135 assertEquals("name7",elements[2].getParameters()[0].getName()); 136 assertEquals("value7",elements[2].getParameters()[0].getValue()); 137 assertEquals("name8",elements[2].getParameters()[1].getName()); 138 assertEquals(" value8",elements[2].getParameters()[1].getValue()); 139 } 140 }

This page was automatically generated by Maven