You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2005/10/16 15:11:33 UTC

svn commit: r322470 - in /jakarta/httpclient/trunk/http-common/src/test/org/apache/http: TestAll.java entity/ entity/TestAllEntity.java entity/TestHttpEntities.java

Author: olegk
Date: Sun Oct 16 06:11:25 2005
New Revision: 322470

URL: http://svn.apache.org/viewcvs?rev=322470&view=rev
Log:
Test cases for HTTP entity classes

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

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?rev=322470&r1=322469&r2=322470&view=diff
==============================================================================
--- 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 Sun Oct 16 06:11:25 2005
@@ -28,6 +28,7 @@
 
 package org.apache.http;
 
+import org.apache.http.entity.TestAllEntity;
 import org.apache.http.impl.TestAllImpl;
 import org.apache.http.io.TestAllIO;
 import org.apache.http.util.TestAllUtil;
@@ -57,7 +58,7 @@
         suite.addTest(TestHttpHost.suite());
 
         suite.addTest(TestAllIO.suite());
-        
+        suite.addTest(TestAllEntity.suite());
         suite.addTest(TestAllImpl.suite());
         
         return suite;

Added: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/entity/TestAllEntity.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/entity/TestAllEntity.java?rev=322470&view=auto
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/entity/TestAllEntity.java (added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/entity/TestAllEntity.java Sun Oct 16 06:11:25 2005
@@ -0,0 +1,50 @@
+/*
+ * $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.entity;
+
+import junit.framework.*;
+
+public class TestAllEntity extends TestCase {
+
+    public TestAllEntity(String testName) {
+        super(testName);
+    }
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite();
+        suite.addTest(TestHttpEntities.suite());
+        return suite;
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestAllEntity.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+}

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

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

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

Added: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/entity/TestHttpEntities.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/entity/TestHttpEntities.java?rev=322470&view=auto
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/entity/TestHttpEntities.java (added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/entity/TestHttpEntities.java Sun Oct 16 06:11:25 2005
@@ -0,0 +1,169 @@
+/*
+ * $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.entity;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit tests for {@link NameValuePair}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public class TestHttpEntities extends TestCase {
+
+    public TestHttpEntities(String testName) {
+        super(testName);
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestHttpEntities.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestHttpEntities.class);
+    }
+
+    public void testBasicHttpEntity() throws Exception {
+    	
+    	byte[] bytes = "Message content".getBytes("US-ASCII");
+    	InputStream content = new ByteArrayInputStream(bytes);
+    	BasicHttpEntity httpentity = new BasicHttpEntity();
+    	httpentity.setContent(content);
+    	httpentity.setContentLength(bytes.length);
+    	httpentity.setContentType("text/plain");
+    	httpentity.setContentEncoding("identity");
+    	httpentity.setChunked(false);
+    	
+    	assertEquals(content, httpentity.getContent());
+    	assertEquals(bytes.length, httpentity.getContentLength());
+    	assertEquals("text/plain", httpentity.getContentType());
+    	assertEquals("identity", httpentity.getContentEncoding());
+    	assertFalse(httpentity.isChunked());
+    	assertFalse(httpentity.isRepeatable());
+    }
+    
+    public void testBasicHttpEntityWriteTo() throws Exception {
+    	byte[] bytes = "Message content".getBytes("US-ASCII");
+    	InputStream content = new ByteArrayInputStream(bytes);
+    	BasicHttpEntity httpentity = new BasicHttpEntity();
+    	httpentity.setContent(content);
+    	
+    	ByteArrayOutputStream out = new ByteArrayOutputStream();
+    	assertTrue(httpentity.writeTo(out));
+    	byte[] bytes2 = out.toByteArray();
+    	assertNotNull(bytes2);
+    	assertEquals(bytes.length, bytes2.length);
+    	for (int i = 0; i < bytes.length; i++) {
+    		assertEquals(bytes[i], bytes2[i]);
+    	}
+
+    	out = new ByteArrayOutputStream();
+    	assertTrue(httpentity.writeTo(out));
+    	bytes2 = out.toByteArray();
+    	assertNotNull(bytes2);
+    	assertEquals(0, bytes2.length);
+    	
+    	httpentity.setContent(null);
+    	out = new ByteArrayOutputStream();
+    	assertTrue(httpentity.writeTo(out));
+    	bytes2 = out.toByteArray();
+    	assertNotNull(bytes2);
+    	assertEquals(0, bytes2.length);
+
+    	try {
+    		httpentity.writeTo(null);
+    		fail("IllegalArgumentException should have been thrown");
+    	} catch (IllegalArgumentException ex) {
+    		// expected
+    	}
+    }
+    
+    public void testByteArrayEntity() throws Exception {
+    	byte[] bytes = "Message content".getBytes("US-ASCII");
+    	ByteArrayEntity httpentity = new ByteArrayEntity(bytes);
+    	httpentity.setContentType("application/octet-stream");
+    	httpentity.setContentEncoding("identity");
+    	httpentity.setChunked(false);
+    	
+    	assertEquals(bytes.length, httpentity.getContentLength());
+    	assertEquals("application/octet-stream", httpentity.getContentType());
+    	assertEquals("identity", httpentity.getContentEncoding());
+    	assertNotNull(httpentity.getContent());
+    	assertFalse(httpentity.isChunked());
+    	assertTrue(httpentity.isRepeatable());
+    }
+        
+    public void testByteArrayEntityIllegalConstructor() throws Exception {
+    	try {
+    		new ByteArrayEntity(null);
+    		fail("IllegalArgumentException should have been thrown");
+    	} catch (IllegalArgumentException ex) {
+    		// expected
+    	}
+    }
+
+    public void testByteArrayEntityWriteTo() throws Exception {
+    	byte[] bytes = "Message content".getBytes("US-ASCII");
+    	ByteArrayEntity httpentity = new ByteArrayEntity(bytes);
+    	
+    	ByteArrayOutputStream out = new ByteArrayOutputStream();
+    	assertTrue(httpentity.writeTo(out));
+    	byte[] bytes2 = out.toByteArray();
+    	assertNotNull(bytes2);
+    	assertEquals(bytes.length, bytes2.length);
+    	for (int i = 0; i < bytes.length; i++) {
+    		assertEquals(bytes[i], bytes2[i]);
+    	}
+
+    	out = new ByteArrayOutputStream();
+    	assertTrue(httpentity.writeTo(out));
+    	bytes2 = out.toByteArray();
+    	assertNotNull(bytes2);
+    	assertEquals(bytes.length, bytes2.length);
+    	for (int i = 0; i < bytes.length; i++) {
+    		assertEquals(bytes[i], bytes2[i]);
+    	}
+    	
+    	try {
+    		httpentity.writeTo(null);
+    		fail("IllegalArgumentException should have been thrown");
+    	} catch (IllegalArgumentException ex) {
+    		// expected
+    	}
+    }
+    
+}

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

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

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