Skip to content

Commit a3aab72

Browse files
committed
RR Jackson: add JsonView test for Uni<T> resources; ensure Accept q stripped and order preserved
1 parent e51e83c commit a3aab72

File tree

2 files changed

+83
-0
lines changed
  • independent-projects/resteasy-reactive/server/vertx

2 files changed

+83
-0
lines changed

independent-projects/resteasy-reactive/server/vertx/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@
110110
<scope>test</scope>
111111
</dependency>
112112

113+
<!-- Jackson runtime to exercise JsonView behavior in tests -->
114+
<dependency>
115+
<groupId>io.quarkus.resteasy.reactive</groupId>
116+
<artifactId>resteasy-reactive-jackson</artifactId>
117+
<scope>test</scope>
118+
</dependency>
119+
113120
</dependencies>
114121

115122
<build>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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

Comments
 (0)