001: /***
002: * Retrotranslator: a Java bytecode transformer that translates Java classes
003: * compiled with JDK 5.0 into classes that can be run on JVM 1.4.
004: *
005: * Copyright (c) 2005 - 2008 Taras Puchko
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * 3. Neither the name of the copyright holders nor the names of its
017: * contributors may be used to endorse or promote products derived from
018: * this software without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
021: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
022: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
023: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
024: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
025: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
026: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
027: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
028: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
029: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
030: * THE POSSIBILITY OF SUCH DAMAGE.
031: */package net.sf.retrotranslator.runtime.java.net;
032:
033: import java.net.*;
034: import junit.framework.TestCase;
035:
036: /**
037: * @author Taras Puchko
038: */
039: public class _HttpURLConnectionTestCase extends TestCase {
040:
041: public void testGetConnectTimeout() throws Exception {
042: MockHttpURLConnection mockHttpURLConnection = new MockHttpURLConnection();
043: mockHttpURLConnection.setConnectTimeout(1234);
044: HttpURLConnection httpURLConnection = mockHttpURLConnection
045: .toHttpURLConnection();
046: assertEquals(1234, httpURLConnection.getConnectTimeout());
047: }
048:
049: public void testGetConnectTimeout_2() throws Exception {
050: HttpURLConnection httpURLConnection = new DummyHttpURLConnection()
051: .toHttpURLConnection();
052: assertEquals(0, httpURLConnection.getConnectTimeout());
053: }
054:
055: public void testGetConnectTimeout_3() throws Exception {
056: HttpURLConnection httpURLConnection = new MockHttpURLConnection(
057: new IllegalStateException()).toHttpURLConnection();
058: try {
059: httpURLConnection.getConnectTimeout();
060: fail();
061: } catch (IllegalStateException e) {
062: //ok
063: }
064: }
065:
066: public void testGetReadTimeout() throws Exception {
067: MockHttpURLConnection mockHttpURLConnection = new MockHttpURLConnection();
068: mockHttpURLConnection.setReadTimeout(2345);
069: HttpURLConnection httpURLConnection = mockHttpURLConnection
070: .toHttpURLConnection();
071: assertEquals(2345, httpURLConnection.getReadTimeout());
072: }
073:
074: public void testGetReadTimeout_2() throws Exception {
075: HttpURLConnection httpURLConnection = new DummyHttpURLConnection()
076: .toHttpURLConnection();
077: assertEquals(0, httpURLConnection.getReadTimeout());
078: }
079:
080: public void testGetReadTimeout_3() throws Exception {
081: HttpURLConnection httpURLConnection = new MockHttpURLConnection(
082: new IllegalStateException()).toHttpURLConnection();
083: try {
084: httpURLConnection.getReadTimeout();
085: fail();
086: } catch (IllegalStateException e) {
087: //ok
088: }
089: }
090:
091: public void testSetChunkedStreamingMode() throws Exception {
092: MockHttpURLConnection mockHttpURLConnection = new MockHttpURLConnection();
093: HttpURLConnection httpURLConnection = mockHttpURLConnection
094: .toHttpURLConnection();
095: httpURLConnection.setChunkedStreamingMode(3456);
096: assertEquals(3456, mockHttpURLConnection
097: .getChunkedStreamingModeLength());
098: }
099:
100: public void testSetChunkedStreamingMode_2() throws Exception {
101: HttpURLConnection httpURLConnection = new DummyHttpURLConnection()
102: .toHttpURLConnection();
103: httpURLConnection.setChunkedStreamingMode(12345);
104: }
105:
106: public void testSetChunkedStreamingMode_3() throws Exception {
107: HttpURLConnection httpURLConnection = new MockHttpURLConnection(
108: new IllegalStateException()).toHttpURLConnection();
109: try {
110: httpURLConnection.setChunkedStreamingMode(23456);
111: fail();
112: } catch (IllegalStateException e) {
113: //ok
114: }
115: }
116:
117: public void testSetConnectTimeout() throws Exception {
118: MockHttpURLConnection mockHttpURLConnection = new MockHttpURLConnection();
119: HttpURLConnection httpURLConnection = mockHttpURLConnection
120: .toHttpURLConnection();
121: httpURLConnection.setConnectTimeout(4567);
122: assertEquals(4567, mockHttpURLConnection.getConnectTimeout());
123: }
124:
125: public void testSetConnectTimeout_2() throws Exception {
126: HttpURLConnection httpURLConnection = new DummyHttpURLConnection()
127: .toHttpURLConnection();
128: httpURLConnection.setConnectTimeout(12345);
129: }
130:
131: public void testSetConnectTimeout_3() throws Exception {
132: HttpURLConnection httpURLConnection = new MockHttpURLConnection(
133: new IllegalStateException()).toHttpURLConnection();
134: try {
135: httpURLConnection.setConnectTimeout(34567);
136: fail();
137: } catch (IllegalStateException e) {
138: //ok
139: }
140: }
141:
142: public void testSetFixedLengthStreamingMode() throws Exception {
143: MockHttpURLConnection mockHttpURLConnection = new MockHttpURLConnection();
144: HttpURLConnection httpURLConnection = mockHttpURLConnection
145: .toHttpURLConnection();
146: httpURLConnection.setFixedLengthStreamingMode(5678);
147: assertEquals(5678, mockHttpURLConnection
148: .getFixedLengthStreamingModeLength());
149: }
150:
151: public void testSetFixedLengthStreamingMode_2() throws Exception {
152: DummyHttpURLConnection dummyHttpURLConnection = new DummyHttpURLConnection();
153: HttpURLConnection httpURLConnection = dummyHttpURLConnection
154: .toHttpURLConnection();
155: httpURLConnection.setFixedLengthStreamingMode(67890);
156: try {
157: httpURLConnection.setChunkedStreamingMode(12345);
158: // Java 1.4
159: assertEquals("67890", dummyHttpURLConnection
160: .getPropertyMap().get("Content-Length"));
161: } catch (IllegalStateException e) {
162: // Java 5
163: }
164: }
165:
166: public void testSetFixedLengthStreamingMode_3() throws Exception {
167: HttpURLConnection httpURLConnection = new MockHttpURLConnection(
168: new IllegalStateException()).toHttpURLConnection();
169: try {
170: httpURLConnection.setFixedLengthStreamingMode(45678);
171: fail();
172: } catch (IllegalStateException e) {
173: //ok
174: }
175: }
176:
177: public void testSetReadTimeout() throws Exception {
178: MockHttpURLConnection mockHttpURLConnection = new MockHttpURLConnection();
179: HttpURLConnection httpURLConnection = mockHttpURLConnection
180: .toHttpURLConnection();
181: httpURLConnection.setReadTimeout(6789);
182: assertEquals(6789, mockHttpURLConnection.getReadTimeout());
183: }
184:
185: public void testSetReadTimeout_2() throws Exception {
186: HttpURLConnection httpURLConnection = new DummyHttpURLConnection()
187: .toHttpURLConnection();
188: httpURLConnection.setReadTimeout(67890);
189: }
190:
191: public void testSetReadTimeout_3() throws Exception {
192: HttpURLConnection httpURLConnection = new MockHttpURLConnection(
193: new IllegalStateException()).toHttpURLConnection();
194: try {
195: httpURLConnection.setReadTimeout(56789);
196: fail();
197: } catch (IllegalStateException e) {
198: //ok
199: }
200: }
201:
202: }
|