16
16
17
17
package org .springframework .http .client ;
18
18
19
+ import static org .junit .Assert .assertEquals ;
20
+ import static org .junit .Assert .assertTrue ;
21
+ import static org .junit .Assert .fail ;
22
+
19
23
import java .io .IOException ;
20
24
import java .net .URI ;
21
25
import java .util .Arrays ;
22
26
import java .util .Locale ;
23
27
import java .util .concurrent .Future ;
24
28
25
29
import org .junit .After ;
26
- import static org .junit .Assert .*;
27
30
import org .junit .Before ;
28
31
import org .junit .Test ;
29
-
30
32
import org .springframework .beans .factory .DisposableBean ;
31
33
import org .springframework .beans .factory .InitializingBean ;
32
34
import org .springframework .http .HttpMethod ;
@@ -44,16 +46,16 @@ public abstract class AbstractAsyncHttpRequestFactoryTestCase extends AbstractJe
44
46
45
47
@ Before
46
48
public final void createFactory () throws Exception {
47
- factory = createRequestFactory ();
48
- if (factory instanceof InitializingBean ) {
49
- ((InitializingBean ) factory ).afterPropertiesSet ();
49
+ this . factory = createRequestFactory ();
50
+ if (this . factory instanceof InitializingBean ) {
51
+ ((InitializingBean ) this . factory ).afterPropertiesSet ();
50
52
}
51
53
}
52
54
53
55
@ After
54
56
public final void destroyFactory () throws Exception {
55
- if (factory instanceof DisposableBean ) {
56
- ((DisposableBean ) factory ).destroy ();
57
+ if (this . factory instanceof DisposableBean ) {
58
+ ((DisposableBean ) this . factory ).destroy ();
57
59
}
58
60
}
59
61
@@ -63,22 +65,23 @@ public final void destroyFactory() throws Exception {
63
65
@ Test
64
66
public void status () throws Exception {
65
67
URI uri = new URI (baseUrl + "/status/notfound" );
66
- AsyncClientHttpRequest request = factory .createAsyncRequest (uri , HttpMethod .GET );
68
+ AsyncClientHttpRequest request = this . factory .createAsyncRequest (uri , HttpMethod .GET );
67
69
assertEquals ("Invalid HTTP method" , HttpMethod .GET , request .getMethod ());
68
70
assertEquals ("Invalid HTTP URI" , uri , request .getURI ());
69
71
Future <ClientHttpResponse > futureResponse = request .executeAsync ();
70
72
ClientHttpResponse response = futureResponse .get ();
71
73
try {
72
74
assertEquals ("Invalid status code" , HttpStatus .NOT_FOUND , response .getStatusCode ());
73
- } finally {
75
+ }
76
+ finally {
74
77
response .close ();
75
78
}
76
79
}
77
80
78
81
@ Test
79
82
public void statusCallback () throws Exception {
80
83
URI uri = new URI (baseUrl + "/status/notfound" );
81
- AsyncClientHttpRequest request = factory .createAsyncRequest (uri , HttpMethod .GET );
84
+ AsyncClientHttpRequest request = this . factory .createAsyncRequest (uri , HttpMethod .GET );
82
85
assertEquals ("Invalid HTTP method" , HttpMethod .GET , request .getMethod ());
83
86
assertEquals ("Invalid HTTP URI" , uri , request .getURI ());
84
87
ListenableFuture <ClientHttpResponse > listenableFuture = request .executeAsync ();
@@ -108,7 +111,7 @@ public void onFailure(Throwable ex) {
108
111
109
112
@ Test
110
113
public void echo () throws Exception {
111
- AsyncClientHttpRequest request = factory .createAsyncRequest (new URI (baseUrl + "/echo" ), HttpMethod .PUT );
114
+ AsyncClientHttpRequest request = this . factory .createAsyncRequest (new URI (baseUrl + "/echo" ), HttpMethod .PUT );
112
115
assertEquals ("Invalid HTTP method" , HttpMethod .PUT , request .getMethod ());
113
116
String headerName = "MyHeader" ;
114
117
String headerValue1 = "value1" ;
@@ -143,7 +146,7 @@ public void echo() throws Exception {
143
146
144
147
@ Test
145
148
public void multipleWrites () throws Exception {
146
- AsyncClientHttpRequest request = factory .createAsyncRequest (new URI (baseUrl + "/echo" ), HttpMethod .POST );
149
+ AsyncClientHttpRequest request = this . factory .createAsyncRequest (new URI (baseUrl + "/echo" ), HttpMethod .POST );
147
150
final byte [] body = "Hello World" .getBytes ("UTF-8" );
148
151
149
152
if (request instanceof StreamingHttpOutputMessage ) {
@@ -170,7 +173,7 @@ public void multipleWrites() throws Exception {
170
173
171
174
@ Test
172
175
public void headersAfterExecute () throws Exception {
173
- AsyncClientHttpRequest request = factory .createAsyncRequest (new URI (baseUrl + "/echo" ), HttpMethod .POST );
176
+ AsyncClientHttpRequest request = this . factory .createAsyncRequest (new URI (baseUrl + "/echo" ), HttpMethod .POST );
174
177
request .getHeaders ().add ("MyHeader" , "value" );
175
178
byte [] body = "Hello World" .getBytes ("UTF-8" );
176
179
FileCopyUtils .copy (body , request .getBody ());
@@ -202,7 +205,7 @@ public void httpMethods() throws Exception {
202
205
protected void assertHttpMethod (String path , HttpMethod method ) throws Exception {
203
206
ClientHttpResponse response = null ;
204
207
try {
205
- AsyncClientHttpRequest request = factory .createAsyncRequest (new URI (baseUrl + "/methods/" + path ), method );
208
+ AsyncClientHttpRequest request = this . factory .createAsyncRequest (new URI (baseUrl + "/methods/" + path ), method );
206
209
Future <ClientHttpResponse > futureResponse = request .executeAsync ();
207
210
response = futureResponse .get ();
208
211
assertEquals ("Invalid response status" , HttpStatus .OK , response .getStatusCode ());
0 commit comments