use of javax.ws.rs.core.GenericType in project jersey by jersey.
the class GenericResponseTest method testPost.
@Test
public void testPost() {
GenericType<Response> generic = new GenericType<Response>(Response.class);
Entity entity = Entity.entity("entity", MediaType.WILDCARD_TYPE);
WebTarget target = target("resource");
SyncInvoker sync = target.request();
Response response = sync.post(entity, generic);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals("entity", response.readEntity(String.class));
}
use of javax.ws.rs.core.GenericType in project jersey by jersey.
the class GenericResponseTest method testGetGenericString.
@Test
public void testGetGenericString() {
GenericType<String> generic = new GenericType<String>(String.class);
WebTarget target = target("resource");
SyncInvoker sync = target.request();
final String entity = sync.get(generic);
Assert.assertEquals("get", entity);
}
use of javax.ws.rs.core.GenericType in project jersey by jersey.
the class BasicClientTest method testAsyncClientInvocation.
@Test
public void testAsyncClientInvocation() throws InterruptedException, ExecutionException {
final WebTarget resource = target().path("resource");
Future<Response> f1 = resource.request().async().post(text("post1"));
final Response response = f1.get();
assertEquals("post1", response.readEntity(String.class));
Future<String> f2 = resource.request().async().post(text("post2"), String.class);
assertEquals("post2", f2.get());
Future<List<JaxbString>> f3 = resource.request().async().get(new GenericType<List<JaxbString>>() {
});
assertEquals(Arrays.asList("a", "b", "c").toString(), f3.get().stream().map(input -> input.value).collect(Collectors.toList()).toString());
CompletableFuture<String> future1 = new CompletableFuture<>();
final TestCallback<Response> c1 = new TestCallback<Response>(future1) {
@Override
protected String process(Response result) {
return result.readEntity(String.class);
}
};
resource.request().async().post(text("post"), c1);
assertEquals("post", future1.get());
CompletableFuture<String> future2 = new CompletableFuture<>();
final TestCallback<String> c2 = new TestCallback<String>(future2) {
@Override
protected String process(String result) {
return result;
}
};
resource.request().async().post(text("post"), c2);
assertEquals("post", future2.get());
CompletableFuture<String> future3 = new CompletableFuture<>();
final TestCallback<List<JaxbString>> c3 = new TestCallback<List<JaxbString>>(future3) {
@Override
protected String process(List<JaxbString> result) {
return result.stream().map(jaxbString -> jaxbString.value).collect(Collectors.toList()).toString();
}
};
resource.request().async().get(c3);
assertEquals(Arrays.asList("a", "b", "c").toString(), future3.get());
}
use of javax.ws.rs.core.GenericType in project jersey by jersey.
the class ContactCardTest method testSearchByName.
@Test
public void testSearchByName() throws Exception {
final WebTarget target = target().path("contact");
target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.entity(CARD_1, MediaType.APPLICATION_JSON_TYPE));
target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.entity(CARD_2, MediaType.APPLICATION_JSON_TYPE));
Response response = target.path("search/name").queryParam("q", "er").request(MediaType.APPLICATION_JSON_TYPE).get();
List<ContactCard> contactCards = response.readEntity(new GenericType<List<ContactCard>>() {
});
assertEquals(200, response.getStatus());
assertEquals(2, contactCards.size());
for (final ContactCard contactCard : contactCards) {
assertTrue(contactCard.getFullName().contains("er"));
}
response = target.path("search/name").queryParam("q", "Foo").request(MediaType.APPLICATION_JSON_TYPE).get();
contactCards = response.readEntity(new GenericType<List<ContactCard>>() {
});
assertEquals(200, response.getStatus());
assertEquals(1, contactCards.size());
assertTrue(contactCards.get(0).getFullName().contains("Foo"));
assertEquals(200, target.request(MediaType.APPLICATION_JSON_TYPE).delete().getStatus());
}
use of javax.ws.rs.core.GenericType in project jersey by jersey.
the class AsyncContentAndEntityTypeTest method testAsyncContentType.
@Test
public void testAsyncContentType() throws Exception {
final ApplicationHandler app = createApplication(AsyncResource.class);
MediaType foo = MediaType.valueOf("application/foo");
Future<ContainerResponse> responseFuture = Executors.newFixedThreadPool(1).submit(new Callable<ContainerResponse>() {
@Override
public ContainerResponse call() throws Exception {
return app.apply(RequestContextBuilder.from("/", "GET").accept("*/*").build()).get();
}
});
ContainerResponse response;
// making sure the JVM optimization does not swap the order of the calls.
synchronized (this) {
app.apply(RequestContextBuilder.from("/", "POST").entity("Foo").build());
response = responseFuture.get();
}
assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
assertEquals("Foo", response.getEntity());
assertEquals(foo, response.getMediaType());
final GenericType stringType = new GenericType(String.class);
assertEquals(stringType.getRawType(), response.getEntityClass());
assertEquals(stringType.getType(), response.getEntityType());
}
Aggregations