hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r418609 - in /jakarta/httpcomponents/httpcore/trunk/src: java/org/apache/http/message/ test/org/apache/http/message/
Date Sun, 02 Jul 2006 15:57:47 GMT
Author: olegk
Date: Sun Jul  2 08:57:46 2006
New Revision: 418609

URL: http://svn.apache.org/viewvc?rev=418609&view=rev
Log:
[HTTPCORE-1] 100% test coverage in the o.a.http.message package

Added:
    jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestAbstractMessage.java
  (with props)
    jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestBasicMessages.java
  (with props)
Modified:
    jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/message/AbstractHttpMessage.java
    jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestAllMessage.java

Modified: jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/message/AbstractHttpMessage.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/message/AbstractHttpMessage.java?rev=418609&r1=418608&r2=418609&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/message/AbstractHttpMessage.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/message/AbstractHttpMessage.java
Sun Jul  2 08:57:46 2006
@@ -90,9 +90,6 @@
     }
 
     public void setHeader(final Header header) {
-        if (header == null) {
-            return;
-        }
         this.headergroup.updateHeader(header);
     }
 

Added: jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestAbstractMessage.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestAbstractMessage.java?rev=418609&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestAbstractMessage.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestAbstractMessage.java
Sun Jul  2 08:57:46 2006
@@ -0,0 +1,160 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * 
+ * ====================================================================
+ *
+ *  Copyright 1999-2006 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.message;
+
+import org.apache.http.Header;
+import org.apache.http.HttpMessage;
+import org.apache.http.impl.DefaultHttpParams;
+import org.apache.http.mockup.HttpMessageMockup;
+import org.apache.http.params.HttpParams;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit tests for {@link Header}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public class TestAbstractMessage extends TestCase {
+
+    public TestAbstractMessage(String testName) {
+        super(testName);
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestAbstractMessage.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestAbstractMessage.class);
+    }
+
+    public void testBasicProperties() {
+        HttpMessage message = new HttpMessageMockup();
+        assertNotNull(message.getParams());
+        assertNotNull(message.headerIterator());
+        Header[] headers = message.getAllHeaders();
+        assertNotNull(headers);
+        assertEquals(0, headers.length);
+    }
+
+    public void testBasicHeaderOps() {
+        HttpMessage message = new HttpMessageMockup();
+        assertFalse(message.containsHeader("whatever"));
+        
+        message.addHeader("name", "1");
+        message.addHeader("name", "2");
+        
+        Header[] headers = message.getAllHeaders();
+        assertNotNull(headers);
+        assertEquals(2, headers.length);
+        
+        Header h = message.getFirstHeader("name");
+        assertNotNull(h);
+        assertEquals("1", h.getValue());
+
+        message.setHeader("name", "3");
+        h = message.getFirstHeader("name");
+        assertNotNull(h);
+        assertEquals("3", h.getValue());
+        h = message.getLastHeader("name");
+        assertNotNull(h);
+        assertEquals("2", h.getValue());
+        
+        // Should have no effect
+        message.addHeader(null);
+        message.setHeader(null);
+        
+        headers = message.getHeaders("name");
+        assertNotNull(headers);
+        assertEquals(2, headers.length);
+        assertEquals("3", headers[0].getValue());
+        assertEquals("2", headers[1].getValue());
+
+        message.addHeader("name", "4");
+        
+        headers[1] = new BasicHeader("name", "5");
+        message.setHeaders(headers);
+        
+        headers = message.getHeaders("name");
+        assertNotNull(headers);
+        assertEquals(2, headers.length);
+        assertEquals("3", headers[0].getValue());
+        assertEquals("5", headers[1].getValue());
+        
+        message.setHeader("whatever", null);
+        message.removeHeaders("name");
+        message.removeHeaders(null);
+        headers = message.getAllHeaders();
+        assertNotNull(headers);
+        assertEquals(1, headers.length);
+        assertEquals(null, headers[0].getValue());
+
+        message.removeHeader(message.getFirstHeader("whatever"));
+        headers = message.getAllHeaders();
+        assertNotNull(headers);
+        assertEquals(0, headers.length);
+    }
+
+    public void testParameters() {
+        HttpMessage message = new HttpMessageMockup();
+        assertNotNull(message.getParams());
+        HttpParams params = new DefaultHttpParams();
+        message.setParams(params);
+        assertTrue(params == message.getParams());
+    }
+
+    public void testInvalidInput() {
+        HttpMessage message = new HttpMessageMockup();
+        try {
+            message.setParams(null);
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            message.addHeader(null, null);
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            message.setHeader(null, null);
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+    }
+    
+}
+

Propchange: jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestAbstractMessage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestAbstractMessage.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestAbstractMessage.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestAllMessage.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestAllMessage.java?rev=418609&r1=418608&r2=418609&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestAllMessage.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestAllMessage.java
Sun Jul  2 08:57:46 2006
@@ -44,6 +44,8 @@
         suite.addTest(TestStatusLine.suite());
         suite.addTest(TestRequestLine.suite());
         suite.addTest(TestHttpVersion.suite());
+        suite.addTest(TestAbstractMessage.suite());
+        suite.addTest(TestBasicMessages.suite());
 
         return suite;
     }

Added: jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestBasicMessages.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestBasicMessages.java?rev=418609&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestBasicMessages.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestBasicMessages.java
Sun Jul  2 08:57:46 2006
@@ -0,0 +1,221 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * 
+ * ====================================================================
+ *
+ *  Copyright 1999-2006 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.message;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.HttpVersion;
+import org.apache.http.entity.BasicHttpEntity;
+import org.apache.http.params.HttpProtocolParams;
+
+/**
+ * Unit tests for {@link Header}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public class TestBasicMessages extends TestCase {
+
+    public TestBasicMessages(String testName) {
+        super(testName);
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestBasicMessages.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestBasicMessages.class);
+    }
+
+    public void testDefaultResponseConstructors() {
+        HttpResponse response = new BasicHttpResponse();
+        assertNotNull(response.getHttpVersion());
+        assertNotNull(response.getStatusLine());
+        assertEquals(200, response.getStatusLine().getStatusCode());
+        
+        response = new BasicHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_BAD_REQUEST);
+        assertNotNull(response.getHttpVersion());
+        assertEquals(HttpVersion.HTTP_1_0, response.getHttpVersion());
+        assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusLine().getStatusCode());
+        
+        response = new BasicHttpResponse(new BasicStatusLine(
+                HttpVersion.HTTP_1_1, HttpStatus.SC_INTERNAL_SERVER_ERROR, "whatever"));
+        assertNotNull(response.getHttpVersion());
+        assertEquals(HttpVersion.HTTP_1_1, response.getHttpVersion());
+        assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatusLine().getStatusCode());
+        assertEquals("whatever", response.getStatusLine().getReasonPhrase());
+    }
+
+    public void testSetResponseStatus() {
+        HttpResponse response = new BasicHttpResponse();
+        response.setStatusCode(200);
+        assertNotNull(response.getHttpVersion());
+        assertNotNull(response.getStatusLine());
+        assertEquals(200, response.getStatusLine().getStatusCode());
+        
+        response = new BasicHttpResponse();
+        response.setStatusLine(HttpVersion.HTTP_1_0, HttpStatus.SC_BAD_REQUEST);
+        assertNotNull(response.getHttpVersion());
+        assertEquals(HttpVersion.HTTP_1_0, response.getHttpVersion());
+        assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusLine().getStatusCode());
+        
+        response = new BasicHttpResponse();
+        response.setStatusLine(new BasicStatusLine(
+                HttpVersion.HTTP_1_1, HttpStatus.SC_INTERNAL_SERVER_ERROR, "whatever"));
+        assertNotNull(response.getHttpVersion());
+        assertEquals(HttpVersion.HTTP_1_1, response.getHttpVersion());
+        assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatusLine().getStatusCode());
+        assertEquals("whatever", response.getStatusLine().getReasonPhrase());
+        
+        response = new BasicHttpResponse();
+        try {
+            response.setStatusCode(-23);
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        response = new BasicHttpResponse();
+        try {
+            response.setStatusLine(null, 200);
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        response = new BasicHttpResponse();
+        try {
+            response.setStatusLine(null);
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+    }
+    
+    public void testSetResponseEntity() {
+        BasicHttpResponse response = new BasicHttpResponse();
+        assertNull(response.getEntity());
+        
+        HttpEntity entity = new BasicHttpEntity();
+        response.setEntity(entity);
+        assertTrue(entity == response.getEntity());
+    }
+
+    public void testDefaultRequestConstructors() {
+        HttpRequest request = new BasicHttpRequest("WHATEVER", "/");
+        assertNotNull(request.getHttpVersion());
+        assertEquals("WHATEVER", request.getRequestLine().getMethod());
+        assertEquals("/", request.getRequestLine().getUri());
+
+        request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_0);
+        assertEquals(HttpVersion.HTTP_1_0, request.getHttpVersion());
+        assertEquals("GET", request.getRequestLine().getMethod());
+        assertEquals("/", request.getRequestLine().getUri());
+
+        try {
+            new BasicHttpRequest(null, null);
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            new BasicHttpRequest("GET", null);
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            new BasicHttpRequest(null);
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+    }
+    
+    public void testDefaultEntityEnclosingRequestConstructors() {
+        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("GET",
"/");
+        assertNotNull(request.getHttpVersion());
+        assertEquals("GET", request.getRequestLine().getMethod());
+        assertEquals("/", request.getRequestLine().getUri());
+
+        request = new BasicHttpEntityEnclosingRequest("GET", "/", HttpVersion.HTTP_1_0);
+        assertEquals(HttpVersion.HTTP_1_0, request.getHttpVersion());
+        assertEquals("GET", request.getRequestLine().getMethod());
+        assertEquals("/", request.getRequestLine().getUri());
+    }
+    
+    public void testSetRequestEntity() {
+        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("GET",
"/");
+        assertNull(request.getEntity());
+        
+        HttpEntity entity = new BasicHttpEntity();
+        request.setEntity(entity);
+        assertTrue(entity == request.getEntity());
+    }
+
+    public void testExpectContinue() {
+        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("GET",
"/");
+        assertFalse(request.expectContinue()); 
+        request.getParams().setBooleanParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, true);
+        assertFalse(request.expectContinue());
+        request.addHeader("Expect", "100-Continue");
+        assertTrue(request.expectContinue()); 
+    }
+
+    public void testDefaultGetMethodConstructor() {
+        HttpRequest request = new HttpGet("/");
+        assertEquals("/", request.getRequestLine().getUri());
+        assertEquals("GET", request.getRequestLine().getMethod());
+        assertFalse(request instanceof HttpEntityEnclosingRequest);
+    }
+    
+    public void testDefaultPostMethodConstructor() {
+        HttpRequest request = new HttpPost("/");
+        assertEquals("/", request.getRequestLine().getUri());
+        assertEquals("POST", request.getRequestLine().getMethod());
+        assertTrue(request instanceof HttpEntityEnclosingRequest);
+    }
+
+    public void testDefaultHeadMethodConstructor() {
+        HttpRequest request = new HttpHead("/");
+        assertEquals("/", request.getRequestLine().getUri());
+        assertEquals("HEAD", request.getRequestLine().getMethod());
+        assertFalse(request instanceof HttpEntityEnclosingRequest);
+    }
+
+}
+

Propchange: jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestBasicMessages.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestBasicMessages.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/message/TestBasicMessages.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message