21
21
import com .ning .http .client .generators .InputStreamBodyGenerator ;
22
22
import com .ning .http .client .simple .HeaderMap ;
23
23
import com .ning .http .client .simple .SimpleAHCTransferListener ;
24
+
24
25
import org .testng .annotations .Test ;
25
26
26
27
import java .io .ByteArrayInputStream ;
38
39
public abstract class SimpleAsyncHttpClientTest extends AbstractBasicTest {
39
40
40
41
private final static String MY_MESSAGE = "my message" ;
42
+
43
+ public abstract String getProviderClass ();
41
44
42
45
@ Test (groups = { "standalone" , "default_provider" })
43
46
public void inputStreamBodyConsumerTest () throws Throwable {
44
47
45
- SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setIdleConnectionInPoolTimeoutInMs (100 ).setMaximumConnectionsTotal (50 ).setRequestTimeoutInMs (5 * 60 * 1000 ).setUrl (getTargetUrl ()).setHeader ("Content-Type" , "text/html" ).build ();
48
+ SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setProviderClass ( getProviderClass ()). setIdleConnectionInPoolTimeoutInMs (100 ).setMaximumConnectionsTotal (50 ).setRequestTimeoutInMs (5 * 60 * 1000 ).setUrl (getTargetUrl ()).setHeader ("Content-Type" , "text/html" ).build ();
46
49
try {
47
50
Future <Response > future = client .post (new InputStreamBodyGenerator (new ByteArrayInputStream (MY_MESSAGE .getBytes ())));
48
51
@@ -58,7 +61,7 @@ public void inputStreamBodyConsumerTest() throws Throwable {
58
61
@ Test (groups = { "standalone" , "default_provider" })
59
62
public void stringBuilderBodyConsumerTest () throws Throwable {
60
63
61
- SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setIdleConnectionInPoolTimeoutInMs (100 ).setMaximumConnectionsTotal (50 ).setRequestTimeoutInMs (5 * 60 * 1000 ).setUrl (getTargetUrl ()).setHeader ("Content-Type" , "text/html" ).build ();
64
+ SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setProviderClass ( getProviderClass ()). setIdleConnectionInPoolTimeoutInMs (100 ).setMaximumConnectionsTotal (50 ).setRequestTimeoutInMs (5 * 60 * 1000 ).setUrl (getTargetUrl ()).setHeader ("Content-Type" , "text/html" ).build ();
62
65
try {
63
66
StringBuilder s = new StringBuilder ();
64
67
Future <Response > future = client .post (new InputStreamBodyGenerator (new ByteArrayInputStream (MY_MESSAGE .getBytes ())), new AppendableBodyConsumer (s ));
@@ -75,7 +78,7 @@ public void stringBuilderBodyConsumerTest() throws Throwable {
75
78
@ Test (groups = { "standalone" , "default_provider" })
76
79
public void byteArrayOutputStreamBodyConsumerTest () throws Throwable {
77
80
78
- SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setIdleConnectionInPoolTimeoutInMs (100 ).setMaximumConnectionsTotal (50 ).setRequestTimeoutInMs (5 * 60 * 1000 ).setUrl (getTargetUrl ()).setHeader ("Content-Type" , "text/html" ).build ();
81
+ SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setProviderClass ( getProviderClass ()). setIdleConnectionInPoolTimeoutInMs (100 ).setMaximumConnectionsTotal (50 ).setRequestTimeoutInMs (5 * 60 * 1000 ).setUrl (getTargetUrl ()).setHeader ("Content-Type" , "text/html" ).build ();
79
82
try {
80
83
ByteArrayOutputStream o = new ByteArrayOutputStream (10 );
81
84
Future <Response > future = client .post (new InputStreamBodyGenerator (new ByteArrayInputStream (MY_MESSAGE .getBytes ())), new OutputStreamBodyConsumer (o ));
@@ -92,7 +95,7 @@ public void byteArrayOutputStreamBodyConsumerTest() throws Throwable {
92
95
@ Test (groups = { "standalone" , "default_provider" })
93
96
public void requestByteArrayOutputStreamBodyConsumerTest () throws Throwable {
94
97
95
- SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setUrl (getTargetUrl ()).build ();
98
+ SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setProviderClass ( getProviderClass ()). setUrl (getTargetUrl ()).build ();
96
99
try {
97
100
ByteArrayOutputStream o = new ByteArrayOutputStream (10 );
98
101
Future <Response > future = client .post (new InputStreamBodyGenerator (new ByteArrayInputStream (MY_MESSAGE .getBytes ())), new OutputStreamBodyConsumer (o ));
@@ -111,7 +114,7 @@ public void requestByteArrayOutputStreamBodyConsumerTest() throws Throwable {
111
114
*/
112
115
@ Test (groups = { "standalone" , "default_provider" }, enabled = true )
113
116
public void testPutZeroBytesFileTest () throws Throwable {
114
- SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setIdleConnectionInPoolTimeoutInMs (100 ).setMaximumConnectionsTotal (50 ).setRequestTimeoutInMs (5 * 1000 ).setUrl (getTargetUrl () + "/testPutZeroBytesFileTest.txt" ).setHeader ("Content-Type" , "text/plain" )
117
+ SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setProviderClass ( getProviderClass ()). setIdleConnectionInPoolTimeoutInMs (100 ).setMaximumConnectionsTotal (50 ).setRequestTimeoutInMs (5 * 1000 ).setUrl (getTargetUrl () + "/testPutZeroBytesFileTest.txt" ).setHeader ("Content-Type" , "text/plain" )
115
118
.build ();
116
119
try {
117
120
File tmpfile = File .createTempFile ("testPutZeroBytesFile" , ".tmp" );
@@ -131,7 +134,7 @@ public void testPutZeroBytesFileTest() throws Throwable {
131
134
132
135
@ Test (groups = { "standalone" , "default_provider" })
133
136
public void testDerive () throws Exception {
134
- SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().build ();
137
+ SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setProviderClass ( getProviderClass ()). build ();
135
138
SimpleAsyncHttpClient derived = client .derive ().build ();
136
139
try {
137
140
assertNotSame (derived , client );
@@ -143,7 +146,7 @@ public void testDerive() throws Exception {
143
146
144
147
@ Test (groups = { "standalone" , "default_provider" })
145
148
public void testDeriveOverrideURL () throws Exception {
146
- SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setUrl ("http://invalid.url/" ).build ();
149
+ SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setProviderClass ( getProviderClass ()). setUrl ("http://invalid.url/" ).build ();
147
150
SimpleAsyncHttpClient derived = client .derive ().setUrl (getTargetUrl ()).build ();
148
151
try {
149
152
ByteArrayOutputStream o = new ByteArrayOutputStream (10 );
@@ -214,7 +217,7 @@ public void onBytesReceived(String url, long amount, long current, long total) {
214
217
215
218
@ Test (groups = { "standalone" , "default_provider" })
216
219
public void testNullUrl () throws Exception {
217
- SimpleAsyncHttpClient c = new SimpleAsyncHttpClient .Builder ().build ().derive ().build ();
220
+ SimpleAsyncHttpClient c = new SimpleAsyncHttpClient .Builder ().setProviderClass ( getProviderClass ()). build ().derive ().build ();
218
221
try {
219
222
assertTrue (true );
220
223
} finally {
@@ -224,7 +227,7 @@ public void testNullUrl() throws Exception {
224
227
225
228
@ Test (groups = { "standalone" , "default_provider" })
226
229
public void testCloseDerivedValidMaster () throws Exception {
227
- SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setUrl (getTargetUrl ()).build ();
230
+ SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setProviderClass ( getProviderClass ()). setUrl (getTargetUrl ()).build ();
228
231
try {
229
232
SimpleAsyncHttpClient derived = client .derive ().build ();
230
233
derived .get ().get ();
@@ -241,7 +244,7 @@ public void testCloseDerivedValidMaster() throws Exception {
241
244
242
245
@ Test (groups = { "standalone" , "default_provider" })
243
246
public void testCloseMasterInvalidDerived () throws Exception {
244
- SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setUrl (getTargetUrl ()).build ();
247
+ SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setProviderClass ( getProviderClass ()). setUrl (getTargetUrl ()).build ();
245
248
SimpleAsyncHttpClient derived = client .derive ().build ();
246
249
247
250
client .close ();
@@ -256,7 +259,7 @@ public void testCloseMasterInvalidDerived() throws Exception {
256
259
257
260
@ Test (groups = { "standalone" , "default_provider" })
258
261
public void testMultiPartPut () throws Exception {
259
- SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setUrl (getTargetUrl () + "/multipart" ).build ();
262
+ SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setProviderClass ( getProviderClass ()). setUrl (getTargetUrl () + "/multipart" ).build ();
260
263
try {
261
264
Response response = client .put (new ByteArrayPart ("baPart" , "fileName" , "testMultiPart" .getBytes ("utf-8" ), "application/test" , "utf-8" )).get ();
262
265
@@ -280,7 +283,7 @@ public void testMultiPartPut() throws Exception {
280
283
281
284
@ Test (groups = { "standalone" , "default_provider" })
282
285
public void testMultiPartPost () throws Exception {
283
- SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setUrl (getTargetUrl () + "/multipart" ).build ();
286
+ SimpleAsyncHttpClient client = new SimpleAsyncHttpClient .Builder ().setProviderClass ( getProviderClass ()). setUrl (getTargetUrl () + "/multipart" ).build ();
284
287
try {
285
288
Response response = client .post (new ByteArrayPart ("baPart" , "fileName" , "testMultiPart" .getBytes ("utf-8" ), "application/test" , "utf-8" )).get ();
286
289
0 commit comments