Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vertx-web-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<!-- Testing -->
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-unit</artifactId>
<artifactId>vertx-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,52 @@
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.client.HttpRequest;
import io.vertx.ext.web.client.HttpResponse;
import io.vertx.ext.web.client.tests.WebClientTestBase;
import io.vertx.ext.web.client.tests.jackson.WineAndCheese;
import io.vertx.ext.web.codec.BodyCodec;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

/**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/
public class WebClientDatabindTest extends WebClientTestBase {

@Test
public void testResponseBodyAsJsonMapped() throws Exception {
public void testResponseBodyAsJsonMapped() {
JsonObject expected = new JsonObject().put("cheese", "Goat Cheese").put("wine", "Condrieu");
server.requestHandler(req -> req.response().end(expected.encode()));
startServer();
HttpRequest<Buffer> get = webClient.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
get
HttpResponse<WineAndCheese> resp = get
.as(BodyCodec.json(WineAndCheese.class))
.send().onComplete(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
assertEquals(new WineAndCheese().setCheese("Goat Cheese").setWine("Condrieu"), resp.body());
testComplete();
}));
await();
.send().await();
assertEquals(200, resp.statusCode());
assertEquals(new WineAndCheese().setCheese("Goat Cheese").setWine("Condrieu"), resp.body());
}

@Test
public void testResponseUnknownContentTypeBodyAsJsonMapped() throws Exception {
public void testResponseUnknownContentTypeBodyAsJsonMapped() {
JsonObject expected = new JsonObject().put("cheese", "Goat Cheese").put("wine", "Condrieu");
testResponseBody(expected.encode(), onSuccess(resp -> {
assertEquals(200, resp.statusCode());
assertEquals(new WineAndCheese().setCheese("Goat Cheese").setWine("Condrieu"), resp.bodyAsJson(WineAndCheese.class));
testComplete();
}));
server.requestHandler(req -> req.response().end(expected.encode()));
startServer();
HttpRequest<Buffer> get = webClient.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
HttpResponse<Buffer> resp = get.send().await();
assertEquals(200, resp.statusCode());
assertEquals(new WineAndCheese().setCheese("Goat Cheese").setWine("Condrieu"), resp.bodyAsJson(WineAndCheese.class));
}

@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());
});
public void testSendJsonPojoBody() {
server.requestHandler(req -> req.bodyHandler(buff -> {
assertEquals("application/json", req.getHeader("content-type"));
assertEquals(new JsonObject().put("wine", "Chateauneuf Du Pape").put("cheese", "roquefort"), buff.toJsonObject());
req.response().end();
}));
startServer();
HttpRequest<Buffer> post = webClient.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
post.sendJson(new WineAndCheese().setCheese("roquefort").setWine("Chateauneuf Du Pape")).await();
}
}
Loading
Loading