View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.entity;
29  
30  import org.apache.http.Header;
31  import org.apache.http.message.BasicHeader;
32  import org.apache.http.protocol.HTTP;
33  import org.junit.Assert;
34  import org.junit.Test;
35  
36  /**
37   * Unit tests for {@link AbstractHttpEntity}.
38   *
39   */
40  public class TestAbstractHttpEntity {
41  
42      @Test
43      public void testContentType() throws Exception {
44          final BasicHttpEntity httpentity = new BasicHttpEntity();
45          httpentity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "blah"));
46          Assert.assertEquals(HTTP.CONTENT_TYPE, httpentity.getContentType().getName());
47          Assert.assertEquals("blah", httpentity.getContentType().getValue());
48  
49          httpentity.setContentType("blah");
50          Assert.assertEquals(HTTP.CONTENT_TYPE, httpentity.getContentType().getName());
51          Assert.assertEquals("blah", httpentity.getContentType().getValue());
52  
53          httpentity.setContentType((Header)null);
54          Assert.assertNull(httpentity.getContentType());
55          httpentity.setContentType((String)null);
56          Assert.assertNull(httpentity.getContentType());
57      }
58  
59      @Test
60      public void testContentEncoding() throws Exception {
61          final BasicHttpEntity httpentity = new BasicHttpEntity();
62          httpentity.setContentEncoding(new BasicHeader(HTTP.CONTENT_ENCODING, "gzip"));
63          Assert.assertEquals(HTTP.CONTENT_ENCODING, httpentity.getContentEncoding().getName());
64          Assert.assertEquals("gzip", httpentity.getContentEncoding().getValue());
65  
66          httpentity.setContentEncoding("gzip");
67          Assert.assertEquals(HTTP.CONTENT_ENCODING, httpentity.getContentEncoding().getName());
68          Assert.assertEquals("gzip", httpentity.getContentEncoding().getValue());
69  
70          httpentity.setContentEncoding((Header)null);
71          Assert.assertNull(httpentity.getContentEncoding());
72          httpentity.setContentEncoding((String)null);
73          Assert.assertNull(httpentity.getContentEncoding());
74      }
75  
76      @Test
77      public void testChunkingFlag() throws Exception {
78          final BasicHttpEntity httpentity = new BasicHttpEntity();
79          Assert.assertFalse(httpentity.isChunked());
80          httpentity.setChunked(true);
81          Assert.assertTrue(httpentity.isChunked());
82      }
83  
84  }