Search in sources :

Example 1 with WineAndCheese

use of io.vertx.ext.web.client.jackson.WineAndCheese in project vertx-web by vert-x3.

the class WebClientTest method testResponseUnknownContentTypeBodyAsJsonMapped.

@Test
public void testResponseUnknownContentTypeBodyAsJsonMapped() throws Exception {
    JsonObject expected = new JsonObject().put("cheese", "Goat Cheese").put("wine", "Condrieu");
    server.requestHandler(req -> req.response().end(expected.encode()));
    startServer();
    HttpRequest<Buffer> get = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
    get.send(onSuccess(resp -> {
        assertEquals(200, resp.statusCode());
        assertEquals(new WineAndCheese().setCheese("Goat Cheese").setWine("Condrieu"), resp.bodyAsJson(WineAndCheese.class));
        testComplete();
    }));
    await();
}
Also used : Buffer(io.vertx.core.buffer.Buffer) VertxException(io.vertx.core.VertxException) AsyncFile(io.vertx.core.file.AsyncFile) HttpServerRequest(io.vertx.core.http.HttpServerRequest) Arrays(java.util.Arrays) DecodeException(io.vertx.core.json.DecodeException) HttpServer(io.vertx.core.http.HttpServer) MultiMap(io.vertx.core.MultiMap) BodyCodec(io.vertx.ext.web.codec.BodyCodec) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) Cert(io.vertx.test.core.tls.Cert) AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) HttpTestBase(io.vertx.test.core.HttpTestBase) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WriteStream(io.vertx.core.streams.WriteStream) ReadStream(io.vertx.core.streams.ReadStream) BiConsumer(java.util.function.BiConsumer) JsonObject(io.vertx.core.json.JsonObject) ConnectException(java.net.ConnectException) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpConnection(io.vertx.core.http.HttpConnection) ProxyOptions(io.vertx.core.net.ProxyOptions) OpenOptions(io.vertx.core.file.OpenOptions) Files(java.nio.file.Files) VertxOptions(io.vertx.core.VertxOptions) HttpHeaders(io.vertx.core.http.HttpHeaders) Test(org.junit.Test) File(java.io.File) Consumer(java.util.function.Consumer) JsonArray(io.vertx.core.json.JsonArray) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) ProxyType(io.vertx.core.net.ProxyType) HttpMethod(io.vertx.core.http.HttpMethod) HttpServerResponse(io.vertx.core.http.HttpServerResponse) WineAndCheese(io.vertx.ext.web.client.jackson.WineAndCheese) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Handler(io.vertx.core.Handler) Collections(java.util.Collections) WineAndCheese(io.vertx.ext.web.client.jackson.WineAndCheese) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 2 with WineAndCheese

use of io.vertx.ext.web.client.jackson.WineAndCheese in project vertx-web by vert-x3.

the class WebClientTest method testResponseBodyAsAsJsonMapped.

@Test
public void testResponseBodyAsAsJsonMapped() throws Exception {
    JsonObject expected = new JsonObject().put("cheese", "Goat Cheese").put("wine", "Condrieu");
    server.requestHandler(req -> req.response().end(expected.encode()));
    startServer();
    HttpRequest<Buffer> get = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
    get.as(BodyCodec.json(WineAndCheese.class)).send(onSuccess(resp -> {
        assertEquals(200, resp.statusCode());
        assertEquals(new WineAndCheese().setCheese("Goat Cheese").setWine("Condrieu"), resp.body());
        testComplete();
    }));
    await();
}
Also used : Buffer(io.vertx.core.buffer.Buffer) VertxException(io.vertx.core.VertxException) AsyncFile(io.vertx.core.file.AsyncFile) HttpServerRequest(io.vertx.core.http.HttpServerRequest) Arrays(java.util.Arrays) DecodeException(io.vertx.core.json.DecodeException) HttpServer(io.vertx.core.http.HttpServer) MultiMap(io.vertx.core.MultiMap) BodyCodec(io.vertx.ext.web.codec.BodyCodec) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) Cert(io.vertx.test.core.tls.Cert) AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) HttpTestBase(io.vertx.test.core.HttpTestBase) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WriteStream(io.vertx.core.streams.WriteStream) ReadStream(io.vertx.core.streams.ReadStream) BiConsumer(java.util.function.BiConsumer) JsonObject(io.vertx.core.json.JsonObject) ConnectException(java.net.ConnectException) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpConnection(io.vertx.core.http.HttpConnection) ProxyOptions(io.vertx.core.net.ProxyOptions) OpenOptions(io.vertx.core.file.OpenOptions) Files(java.nio.file.Files) VertxOptions(io.vertx.core.VertxOptions) HttpHeaders(io.vertx.core.http.HttpHeaders) Test(org.junit.Test) File(java.io.File) Consumer(java.util.function.Consumer) JsonArray(io.vertx.core.json.JsonArray) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) ProxyType(io.vertx.core.net.ProxyType) HttpMethod(io.vertx.core.http.HttpMethod) HttpServerResponse(io.vertx.core.http.HttpServerResponse) WineAndCheese(io.vertx.ext.web.client.jackson.WineAndCheese) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Handler(io.vertx.core.Handler) Collections(java.util.Collections) WineAndCheese(io.vertx.ext.web.client.jackson.WineAndCheese) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 3 with WineAndCheese

use of io.vertx.ext.web.client.jackson.WineAndCheese in project vertx-web by vert-x3.

the class WebClientTest method testSendJsonPojoBody.

@Test
public void testSendJsonPojoBody() throws Exception {
    testSendBody(new WineAndCheese().setCheese("roquefort").setWine("Chateauneuf Du Pape"), (contentType, buff) -> {
        assertEquals("application/json", contentType);
        assertEquals(new JsonObject().put("wine", "Chateauneuf Du Pape").put("cheese", "roquefort"), buff.toJsonObject());
    });
}
Also used : WineAndCheese(io.vertx.ext.web.client.jackson.WineAndCheese) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)3 WineAndCheese (io.vertx.ext.web.client.jackson.WineAndCheese)3 Handler (io.vertx.core.Handler)2 MultiMap (io.vertx.core.MultiMap)2 VertxException (io.vertx.core.VertxException)2 VertxOptions (io.vertx.core.VertxOptions)2 Buffer (io.vertx.core.buffer.Buffer)2 AddressResolverOptions (io.vertx.core.dns.AddressResolverOptions)2 AsyncFile (io.vertx.core.file.AsyncFile)2 OpenOptions (io.vertx.core.file.OpenOptions)2 HttpClientOptions (io.vertx.core.http.HttpClientOptions)2 HttpConnection (io.vertx.core.http.HttpConnection)2 HttpHeaders (io.vertx.core.http.HttpHeaders)2 HttpMethod (io.vertx.core.http.HttpMethod)2 HttpServer (io.vertx.core.http.HttpServer)2 HttpServerOptions (io.vertx.core.http.HttpServerOptions)2 HttpServerRequest (io.vertx.core.http.HttpServerRequest)2 HttpServerResponse (io.vertx.core.http.HttpServerResponse)2 DecodeException (io.vertx.core.json.DecodeException)2 JsonArray (io.vertx.core.json.JsonArray)2