From 3ac230518a4d7dd9c19ebcc224b51a6b24011857 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Wed, 11 Aug 2021 12:04:34 +0200 Subject: [PATCH] Add test for @JsonView support in RESTEasy Jackson Related to #7293 --- .../resteasy/jackson/JsonViewResource.java | 50 +++++++++++++++++++ .../resteasy/jackson/JsonViewTest.java | 39 +++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 extensions/resteasy-classic/resteasy-jackson/deployment/src/test/java/io/quarkus/resteasy/jackson/JsonViewResource.java create mode 100644 extensions/resteasy-classic/resteasy-jackson/deployment/src/test/java/io/quarkus/resteasy/jackson/JsonViewTest.java diff --git a/extensions/resteasy-classic/resteasy-jackson/deployment/src/test/java/io/quarkus/resteasy/jackson/JsonViewResource.java b/extensions/resteasy-classic/resteasy-jackson/deployment/src/test/java/io/quarkus/resteasy/jackson/JsonViewResource.java new file mode 100644 index 0000000000000..512cd210283d9 --- /dev/null +++ b/extensions/resteasy-classic/resteasy-jackson/deployment/src/test/java/io/quarkus/resteasy/jackson/JsonViewResource.java @@ -0,0 +1,50 @@ +package io.quarkus.resteasy.jackson; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import com.fasterxml.jackson.annotation.JsonView; + +@Produces(MediaType.APPLICATION_JSON) +@Path("/json-view") +public class JsonViewResource { + + @GET + @JsonView(View1.class) + @Path("/view1") + public MyObject view1() { + return new MyObject("value1", "value2"); + } + + @GET + @JsonView(View2.class) + @Path("/view2") + public MyObject view2() { + return new MyObject("value1", "value2"); + } + + public static class MyObject { + + @JsonView(View1.class) + private String property1; + + @JsonView(View2.class) + private String property2; + + MyObject() { + } + + MyObject(String property1, String property2) { + this.property1 = property1; + this.property2 = property2; + } + } + + public static class View1 { + } + + public static class View2 { + } +} diff --git a/extensions/resteasy-classic/resteasy-jackson/deployment/src/test/java/io/quarkus/resteasy/jackson/JsonViewTest.java b/extensions/resteasy-classic/resteasy-jackson/deployment/src/test/java/io/quarkus/resteasy/jackson/JsonViewTest.java new file mode 100644 index 0000000000000..6287f4aa8791d --- /dev/null +++ b/extensions/resteasy-classic/resteasy-jackson/deployment/src/test/java/io/quarkus/resteasy/jackson/JsonViewTest.java @@ -0,0 +1,39 @@ +package io.quarkus.resteasy.jackson; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.Matchers.equalTo; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class JsonViewTest { + + @RegisterExtension + static QuarkusUnitTest TEST = new QuarkusUnitTest() + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) + .addClasses(JsonViewResource.class)); + + @Test + public void testView1() { + RestAssured.get("/json-view/view1").then() + .statusCode(200) + .body("property1", equalTo("value1")) + .and() + .body("property2", is(nullValue())); + } + + @Test + public void testView2() { + RestAssured.get("/json-view/view2").then() + .statusCode(200) + .body("property1", is(nullValue())) + .and() + .body("property2", equalTo("value2")); + } +}