|
23 | 23 | import java.lang.annotation.Annotation;
|
24 | 24 | import java.lang.reflect.Type;
|
25 | 25 | import java.util.List;
|
| 26 | +import java.util.concurrent.ExecutionException; |
| 27 | +import java.util.concurrent.Future; |
26 | 28 | import java.util.concurrent.TimeoutException;
|
27 | 29 | import javax.ws.rs.WebApplicationException;
|
28 | 30 | import javax.ws.rs.client.Client;
|
@@ -69,6 +71,27 @@ public void getJson() throws TimeoutException, InterruptedException {
|
69 | 71 | .request()
|
70 | 72 | .header("test-request-header", "test-header-value")
|
71 | 73 | .get();
|
| 74 | + assertGetJson(response); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + public void getJsonAsync() throws TimeoutException, InterruptedException, ExecutionException { |
| 79 | + ClientBuilder clientBuilder = ClientBuilder.newBuilder(); |
| 80 | + Client client = clientBuilder.build(); |
| 81 | + |
| 82 | + Future<Response> responseFuture = |
| 83 | + client |
| 84 | + .target(String.format("http://localhost:%d/get_json", testHttpServer.port())) |
| 85 | + .request() |
| 86 | + .header("test-request-header", "test-header-value") |
| 87 | + .async() |
| 88 | + .get(); |
| 89 | + |
| 90 | + Response response = responseFuture.get(); |
| 91 | + assertGetJson(response); |
| 92 | + } |
| 93 | + |
| 94 | + public void assertGetJson(Response response) throws TimeoutException, InterruptedException { |
72 | 95 | Assertions.assertEquals(200, response.getStatus());
|
73 | 96 | // read entity has to happen before response.close()
|
74 | 97 | String entity = response.readEntity(String.class);
|
@@ -134,19 +157,21 @@ public void postJson() throws TimeoutException, InterruptedException {
|
134 | 157 | }
|
135 | 158 |
|
136 | 159 | @Test
|
137 |
| - public void postJsonDto() throws TimeoutException, InterruptedException { |
| 160 | + public void postJsonDtoAsync() throws TimeoutException, InterruptedException, ExecutionException { |
138 | 161 | ClientBuilder clientBuilder = ClientBuilder.newBuilder();
|
139 | 162 | Client client = clientBuilder.register(MyDtoMessageBodyWriter.class).build();
|
140 | 163 |
|
141 | 164 | MyDto myDto = new MyDto();
|
142 | 165 | myDto.name = "name";
|
143 | 166 |
|
144 |
| - Response response = |
| 167 | + Future<Response> post = |
145 | 168 | client
|
146 | 169 | .target(String.format("http://localhost:%d/post", testHttpServer.port()))
|
147 | 170 | .request()
|
148 | 171 | .header("test-request-header", "test-header-value")
|
| 172 | + .async() |
149 | 173 | .post(Entity.json(myDto));
|
| 174 | + Response response = post.get(); |
150 | 175 | Assertions.assertEquals(204, response.getStatus());
|
151 | 176 |
|
152 | 177 | TEST_WRITER.waitForTraces(1);
|
|
0 commit comments