2
* $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0.1/httpcore/src/test/java/org/apache/http/impl/io/TestContentLengthOutputStream.java $
4
* $Date: 2008-02-03 17:42:22 +0100 (Sun, 03 Feb 2008) $
5
* ====================================================================
6
* Licensed to the Apache Software Foundation (ASF) under one
7
* or more contributor license agreements. See the NOTICE file
8
* distributed with this work for additional information
9
* regarding copyright ownership. The ASF licenses this file
10
* to you under the Apache License, Version 2.0 (the
11
* "License"); you may not use this file except in compliance
12
* with the License. You may obtain a copy of the License at
14
* http://www.apache.org/licenses/LICENSE-2.0
16
* Unless required by applicable law or agreed to in writing,
17
* software distributed under the License is distributed on an
18
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19
* KIND, either express or implied. See the License for the
20
* specific language governing permissions and limitations
22
* ====================================================================
24
* This software consists of voluntary contributions made by many
25
* individuals on behalf of the Apache Software Foundation. For more
26
* information on the Apache Software Foundation, please see
27
* <http://www.apache.org/>.
31
package org.apache.http.impl.io;
33
import java.io.ByteArrayOutputStream;
34
import java.io.IOException;
35
import java.io.OutputStream;
37
import org.apache.http.impl.io.ContentLengthOutputStream;
38
import org.apache.http.mockup.SessionOutputBufferMockup;
40
import junit.framework.Test;
41
import junit.framework.TestCase;
42
import junit.framework.TestSuite;
44
public class TestContentLengthOutputStream extends TestCase {
46
public TestContentLengthOutputStream(String testName) {
50
// ------------------------------------------------------- TestCase Methods
52
public static Test suite() {
53
return new TestSuite(TestContentLengthOutputStream.class);
56
// ------------------------------------------------------------------- Main
57
public static void main(String args[]) {
58
String[] testCaseName = { TestContentLengthOutputStream.class.getName() };
59
junit.textui.TestRunner.main(testCaseName);
62
public void testConstructors() throws Exception {
63
new ContentLengthOutputStream(new SessionOutputBufferMockup(), 10L);
65
new ContentLengthOutputStream(null, 10L);
66
fail("IllegalArgumentException should have been thrown");
67
} catch (IllegalArgumentException ex) {
71
new ContentLengthOutputStream(new SessionOutputBufferMockup(), -10);
72
fail("IllegalArgumentException should have been thrown");
73
} catch (IllegalArgumentException ex) {
78
public void testBasics() throws Exception {
79
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
80
SessionOutputBufferMockup datatransmitter = new SessionOutputBufferMockup(buffer);
81
OutputStream out = new ContentLengthOutputStream(datatransmitter, 15L);
83
byte[] tmp = new byte[10];
84
out.write(tmp, 0, 10);
86
out.write(tmp, 0, 10);
87
out.write(tmp, 0, 10);
93
byte[] data = datatransmitter.getData();
94
assertEquals(15, data.length);
97
public void testClose() throws Exception {
98
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
99
SessionOutputBufferMockup datatransmitter = new SessionOutputBufferMockup(buffer);
100
OutputStream out = new ContentLengthOutputStream(datatransmitter, 15L);
103
byte[] tmp = new byte[10];
106
fail("IOException should have been thrown");
107
} catch (IOException ex) {
112
fail("IOException should have been thrown");
113
} catch (IOException ex) {