Skip to content

Commit d0e6703

Browse files
committed
(chore) new async test
1 parent 61b199f commit d0e6703

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

ms-common-impl/src/test/java/net/trajano/ms/sample/Hello.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
package net.trajano.ms.sample;
22

3+
import java.util.concurrent.ExecutionException;
4+
import java.util.concurrent.Future;
5+
36
import javax.annotation.security.PermitAll;
47
import javax.ws.rs.GET;
58
import javax.ws.rs.Path;
69
import javax.ws.rs.Produces;
10+
import javax.ws.rs.client.Client;
11+
import javax.ws.rs.container.AsyncResponse;
12+
import javax.ws.rs.container.Suspended;
713
import javax.ws.rs.core.Context;
814
import javax.ws.rs.core.MediaType;
15+
import javax.ws.rs.core.Response;
916

1017
import org.springframework.beans.factory.annotation.Autowired;
1118

1219
import io.swagger.annotations.Api;
20+
import io.swagger.annotations.ApiOperation;
1321
import io.vertx.ext.web.RoutingContext;
1422

1523
@Api
@@ -18,12 +26,35 @@ public class Hello {
1826

1927
private int count;
2028

29+
@Context
30+
private Client jaxrsClient;
31+
2132
@Autowired
2233
SomeRequestScope req;
2334

2435
@Autowired
2536
ISomeAppScope scope;
2637

38+
@ApiOperation(value = "displays openid config of google async",
39+
hidden = true)
40+
@GET
41+
@Produces(MediaType.APPLICATION_JSON)
42+
@Path("/async")
43+
@PermitAll
44+
public void async(@Suspended final AsyncResponse asyncResponse) throws InterruptedException,
45+
ExecutionException {
46+
47+
final Future<Response> futureResponseFromClient = jaxrsClient.target("https://accounts.google.com/.well-known/openid-configuration").request().header(javax.ws.rs.core.HttpHeaders.USER_AGENT, "curl/7.55.1").async().get();
48+
49+
final Response responseFromClient = futureResponseFromClient.get();
50+
try {
51+
final String object = responseFromClient.readEntity(String.class);
52+
asyncResponse.resume(object);
53+
} finally {
54+
responseFromClient.close();
55+
}
56+
}
57+
2758
@GET
2859
@Path("/cough")
2960
public String cough() {

ms-common-impl/src/test/java/net/trajano/ms/vertx/test/SpringJaxrsHandlerTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ public static void setApplication() {
5959
@Autowired
6060
private HttpClientOptions httpClientOptions;
6161

62+
@Test
63+
public void testAsync() {
64+
65+
assertNotNull(engine);
66+
final Response response = ClientBuilder.newClient().target(baseUri).path("/api/hello/async").request().get();
67+
assertEquals(200, response.getStatus());
68+
assertTrue(response.readEntity(String.class).startsWith("{"));
69+
70+
}
71+
6272
@Test
6373
public void testEngine() {
6474

0 commit comments

Comments
 (0)