hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r157297 - in jakarta/httpclient/trunk/http-common/src: java/org/apache/http/HeaderGroup.java test/org/apache/http/TestAll.java test/org/apache/http/TestHeaderGroup.java
Date Sat, 12 Mar 2005 23:35:28 GMT
Author: olegk
Date: Sat Mar 12 15:35:25 2005
New Revision: 157297

URL: http://svn.apache.org/viewcvs?view=rev&rev=157297
Log:
More test coverage

Added:
    jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHeaderGroup.java   (with
props)
Modified:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HeaderGroup.java
    jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestAll.java

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HeaderGroup.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HeaderGroup.java?view=diff&r1=157296&r2=157297
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HeaderGroup.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HeaderGroup.java Sat Mar
12 15:35:25 2005
@@ -112,7 +112,7 @@
         if (headers.length == 0) {
             return null;   
         } else if (headers.length == 1) {
-            return new Header(headers[0].getName(), headers[0].getValue());
+            return headers[0];
         } else {
             StringBuffer valueBuffer = new StringBuffer(headers[0].getValue());
             
@@ -221,9 +221,9 @@
      * 
      * @return iterator over this group of headers.
      * 
-     * @since 3.0
+     * @since 4.0
      */
-    public Iterator getIterator() {
+    public Iterator iterator() {
         return this.headers.iterator(); 
     }
 }

Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestAll.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestAll.java?view=diff&r1=157296&r2=157297
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestAll.java (original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestAll.java Sat Mar 12
15:35:25 2005
@@ -44,6 +44,7 @@
         suite.addTest(TestNameValuePair.suite());
         suite.addTest(TestHeader.suite());
         suite.addTest(TestHeaderElement.suite());
+        suite.addTest(TestHeaderGroup.suite());
         suite.addTest(TestHttpStatus.suite());
         suite.addTest(TestHttpVersion.suite());
         return suite;

Added: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHeaderGroup.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHeaderGroup.java?view=auto&rev=157297
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHeaderGroup.java (added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHeaderGroup.java Sat
Mar 12 15:35:25 2005
@@ -0,0 +1,132 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * 
+ * ====================================================================
+ *
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http;
+
+import java.util.Iterator;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit tests for {@link HeaderGroup}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public class TestHeaderGroup extends TestCase {
+
+    public TestHeaderGroup(String testName) {
+        super(testName);
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestHeaderGroup.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestHeaderGroup.class);
+    }
+
+    public void testConstructor() {
+        HeaderGroup headergroup = new HeaderGroup();
+        assertNotNull(headergroup.getAllHeaders());
+        assertEquals(0, headergroup.getAllHeaders().length);
+    }
+    
+    public void testClear() {
+        HeaderGroup headergroup = new HeaderGroup();
+        headergroup.addHeader(new Header("name", "value"));
+        assertEquals(1, headergroup.getAllHeaders().length);
+        headergroup.clear();
+        assertEquals(0, headergroup.getAllHeaders().length);
+    }
+    
+    public void testAddRemoveHeader() {
+        HeaderGroup headergroup = new HeaderGroup();
+        Header header = new Header("name", "value");
+        headergroup.addHeader(header);
+        assertEquals(1, headergroup.getAllHeaders().length);
+        headergroup.removeHeader(header);
+        assertEquals(0, headergroup.getAllHeaders().length);
+    }
+
+    public void testSetHeaders() {
+        HeaderGroup headergroup = new HeaderGroup();
+        Header header1 = new Header("name1", "value1");
+        Header header2 = new Header("name2", "value2");
+        Header header3 = new Header("name3", "value3");
+        headergroup.addHeader(header1);
+        headergroup.setHeaders(new Header[] { header2, header3 });
+        assertEquals(2, headergroup.getAllHeaders().length);
+        assertEquals(0, headergroup.getHeaders("name1").length);
+        assertFalse(headergroup.containsHeader("name1"));
+        assertEquals(1, headergroup.getHeaders("name2").length);
+        assertTrue(headergroup.containsHeader("name2"));
+        assertEquals(1, headergroup.getHeaders("name3").length);
+        assertTrue(headergroup.containsHeader("name3"));
+    }
+
+    public void testFirstLastHeaders() {
+        HeaderGroup headergroup = new HeaderGroup();
+        Header header1 = new Header("name", "value1");
+        Header header2 = new Header("name", "value2");
+        Header header3 = new Header("name", "value3");
+        headergroup.setHeaders(new Header[] { header1, header2, header3 });
+        
+        assertNull(headergroup.getFirstHeader("whatever"));
+        assertNull(headergroup.getLastHeader("whatever"));
+        
+        assertEquals("value1", headergroup.getFirstHeader("name").getValue());
+        assertEquals("value3", headergroup.getLastHeader("name").getValue());
+    }
+
+    public void testCondensedHeader() {
+        HeaderGroup headergroup = new HeaderGroup();
+        assertNull(headergroup.getCondensedHeader("name"));
+        
+        Header header1 = new Header("name", "value1");
+        Header header2 = new Header("name", "value2");
+        Header header3 = new Header("name", "value3");
+        headergroup.setHeaders(new Header[] { header1, header2, header3 });
+        
+        assertEquals("value1, value2, value3", headergroup.getCondensedHeader("name").getValue());
+
+        headergroup.setHeaders(new Header[] { header1 });
+        assertEquals(header1, headergroup.getCondensedHeader("name"));
+    }
+
+    public void testIterator() {
+        HeaderGroup headergroup = new HeaderGroup();
+        Iterator i = headergroup.iterator();
+        assertNotNull(i);
+        assertFalse(i.hasNext());
+    }
+}

Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHeaderGroup.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHeaderGroup.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHeaderGroup.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message