|
| 1 | +package org.jboss.resteasy.reactive.server.vertx.test.jackson; |
| 2 | + |
| 3 | +import static io.restassured.RestAssured.given; |
| 4 | +import static org.hamcrest.Matchers.equalTo; |
| 5 | + |
| 6 | +import jakarta.ws.rs.GET; |
| 7 | +import jakarta.ws.rs.Path; |
| 8 | +import jakarta.ws.rs.Produces; |
| 9 | +import jakarta.ws.rs.core.MediaType; |
| 10 | + |
| 11 | +import org.jboss.resteasy.reactive.server.vertx.test.framework.ResteasyReactiveUnitTest; |
| 12 | +import org.jboss.shrinkwrap.api.ShrinkWrap; |
| 13 | +import org.jboss.shrinkwrap.api.asset.EmptyAsset; |
| 14 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; |
| 15 | +import org.junit.jupiter.api.Test; |
| 16 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 17 | + |
| 18 | +import com.fasterxml.jackson.annotation.JsonView; |
| 19 | + |
| 20 | +import io.smallrye.mutiny.Uni; |
| 21 | + |
| 22 | +public class JsonViewUniTest { |
| 23 | + |
| 24 | + public static class Views { |
| 25 | + public static class Public { |
| 26 | + } |
| 27 | + |
| 28 | + public static class Internal extends Public { |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + public static class User { |
| 33 | + @JsonView(Views.Public.class) |
| 34 | + public String id; |
| 35 | + |
| 36 | + @JsonView(Views.Internal.class) |
| 37 | + public String secret; |
| 38 | + |
| 39 | + public User() { |
| 40 | + } |
| 41 | + |
| 42 | + public User(String id, String secret) { |
| 43 | + this.id = id; |
| 44 | + this.secret = secret; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + @Path("/u") |
| 49 | + public static class Resource { |
| 50 | + @GET |
| 51 | + @Path("/user") |
| 52 | + @Produces(MediaType.APPLICATION_JSON) |
| 53 | + @JsonView(Views.Public.class) |
| 54 | + public Uni<User> get() { |
| 55 | + return Uni.createFrom().item(new User("42", "top-secret")); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + @RegisterExtension |
| 60 | + static ResteasyReactiveUnitTest rr = new ResteasyReactiveUnitTest() |
| 61 | + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) |
| 62 | + .addClasses(Resource.class, User.class, Views.class) |
| 63 | + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")); |
| 64 | + |
| 65 | + @Test |
| 66 | + public void jsonViewWithUni() { |
| 67 | + given() |
| 68 | + .accept(MediaType.APPLICATION_JSON) |
| 69 | + .when().get("/u/user") |
| 70 | + .then() |
| 71 | + .statusCode(200) |
| 72 | + .contentType(MediaType.APPLICATION_JSON) |
| 73 | + .body("id", equalTo("42")) |
| 74 | + .body("secret", equalTo(null)); |
| 75 | + } |
| 76 | +} |
0 commit comments