From 50001f671a9756a365f61764d6546f7f4bae6e4d Mon Sep 17 00:00:00 2001 From: nikhilT-d11 Date: Thu, 28 Mar 2024 16:36:00 +0530 Subject: [PATCH] chore: add test for extra keys in request body --- src/test/java/com/dream11/rest/RestApiIT.java | 12 ++++++++++++ .../java/com/dream11/rest/verticle/RestVerticle.java | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/src/test/java/com/dream11/rest/RestApiIT.java b/src/test/java/com/dream11/rest/RestApiIT.java index 4cb8f97..9d41ec5 100644 --- a/src/test/java/com/dream11/rest/RestApiIT.java +++ b/src/test/java/com/dream11/rest/RestApiIT.java @@ -108,6 +108,18 @@ void positiveBodyTest() { assertThat(response.statusCode()).isEqualTo(200); } + @Test + void extraFieldsTest() { + // arrange + String path = String.format("%s", Constants.VALIDATION_ROUTE_PATH); + JsonObject body = new JsonObject().put("resourceId", "1").put("extraKey", "extraValue"); + // act + HttpResponse response = this.makePostRequest(path, body) + .blockingGet(); + // assert + assertThat(response.statusCode()).isEqualTo(200); + } + @Test void routeNotFoundTest() { // arrange diff --git a/src/test/java/com/dream11/rest/verticle/RestVerticle.java b/src/test/java/com/dream11/rest/verticle/RestVerticle.java index b7392cc..a049d59 100644 --- a/src/test/java/com/dream11/rest/verticle/RestVerticle.java +++ b/src/test/java/com/dream11/rest/verticle/RestVerticle.java @@ -6,7 +6,10 @@ import com.dream11.rest.Constants; import com.dream11.rest.injector.GuiceInjector; import com.dream11.rest.util.SharedDataUtil; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import io.vertx.core.http.HttpServerOptions; +import io.vertx.core.json.jackson.DatabindCodec; public class RestVerticle extends AbstractRestVerticle { @@ -18,4 +21,9 @@ public RestVerticle() { protected ClassInjector getInjector() { return SharedDataUtil.getInstance(this.vertx.getDelegate(), GuiceInjector.class); } + + @Override + protected ObjectMapper getMapper() { + return DatabindCodec.mapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + } }