-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19340 from gsmet/json-view-test
Add test for @JSONVIEW support in RESTEasy Jackson
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...steasy-jackson/deployment/src/test/java/io/quarkus/resteasy/jackson/JsonViewResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...c/resteasy-jackson/deployment/src/test/java/io/quarkus/resteasy/jackson/JsonViewTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")); | ||
} | ||
} |