001: /*
002: * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/test/java/org/apache/http/entity/TestAbstractHttpEntity.java $
003: * $Revision: 496069 $
004: * $Date: 2007-01-14 13:03:05 +0100 (Sun, 14 Jan 2007) $
005: *
006: * ====================================================================
007: * Licensed to the Apache Software Foundation (ASF) under one
008: * or more contributor license agreements. See the NOTICE file
009: * distributed with this work for additional information
010: * regarding copyright ownership. The ASF licenses this file
011: * to you under the Apache License, Version 2.0 (the
012: * "License"); you may not use this file except in compliance
013: * with the License. You may obtain a copy of the License at
014: *
015: * http://www.apache.org/licenses/LICENSE-2.0
016: *
017: * Unless required by applicable law or agreed to in writing,
018: * software distributed under the License is distributed on an
019: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
020: * KIND, either express or implied. See the License for the
021: * specific language governing permissions and limitations
022: * under the License.
023: * ====================================================================
024: *
025: * This software consists of voluntary contributions made by many
026: * individuals on behalf of the Apache Software Foundation. For more
027: * information on the Apache Software Foundation, please see
028: * <http://www.apache.org/>.
029: *
030: */
031:
032: package org.apache.http.entity;
033:
034: import org.apache.http.Header;
035: import org.apache.http.message.BasicHeader;
036: import org.apache.http.mockup.HttpEntityMockup;
037: import org.apache.http.protocol.HTTP;
038:
039: import junit.framework.Test;
040: import junit.framework.TestCase;
041: import junit.framework.TestSuite;
042:
043: /**
044: * Unit tests for {@link AbstractHttpEntity}.
045: *
046: * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
047: */
048: public class TestAbstractHttpEntity extends TestCase {
049:
050: public TestAbstractHttpEntity(String testName) {
051: super (testName);
052: }
053:
054: public static void main(String args[]) {
055: String[] testCaseName = { TestAbstractHttpEntity.class
056: .getName() };
057: junit.textui.TestRunner.main(testCaseName);
058: }
059:
060: public static Test suite() {
061: return new TestSuite(TestAbstractHttpEntity.class);
062: }
063:
064: public void testContentType() throws Exception {
065: HttpEntityMockup httpentity = new HttpEntityMockup();
066: httpentity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
067: HTTP.PLAIN_TEXT_TYPE));
068: assertEquals(HTTP.CONTENT_TYPE, httpentity.getContentType()
069: .getName());
070: assertEquals(HTTP.PLAIN_TEXT_TYPE, httpentity.getContentType()
071: .getValue());
072:
073: httpentity.setContentType(HTTP.PLAIN_TEXT_TYPE);
074: assertEquals(HTTP.CONTENT_TYPE, httpentity.getContentType()
075: .getName());
076: assertEquals(HTTP.PLAIN_TEXT_TYPE, httpentity.getContentType()
077: .getValue());
078:
079: httpentity.setContentType((Header) null);
080: assertNull(httpentity.getContentType());
081: httpentity.setContentType((String) null);
082: assertNull(httpentity.getContentType());
083: }
084:
085: public void testContentEncoding() throws Exception {
086: HttpEntityMockup httpentity = new HttpEntityMockup();
087: httpentity.setContentEncoding(new BasicHeader(
088: HTTP.CONTENT_ENCODING, "gzip"));
089: assertEquals(HTTP.CONTENT_ENCODING, httpentity
090: .getContentEncoding().getName());
091: assertEquals("gzip", httpentity.getContentEncoding().getValue());
092:
093: httpentity.setContentEncoding("gzip");
094: assertEquals(HTTP.CONTENT_ENCODING, httpentity
095: .getContentEncoding().getName());
096: assertEquals("gzip", httpentity.getContentEncoding().getValue());
097:
098: httpentity.setContentEncoding((Header) null);
099: assertNull(httpentity.getContentEncoding());
100: httpentity.setContentEncoding((String) null);
101: assertNull(httpentity.getContentEncoding());
102: }
103:
104: public void testChunkingFlag() throws Exception {
105: HttpEntityMockup httpentity = new HttpEntityMockup();
106: assertFalse(httpentity.isChunked());
107: httpentity.setChunked(true);
108: assertTrue(httpentity.isChunked());
109: }
110:
111: public void testConsumeContent() throws Exception {
112: HttpEntityMockup httpentity = new HttpEntityMockup();
113: httpentity.setStreaming(true);
114: try {
115: httpentity.consumeContent();
116: } catch (UnsupportedOperationException ex) {
117: // expected
118: }
119: httpentity.setStreaming(false);
120: httpentity.consumeContent();
121: }
122:
123: }
|