Skip to content

Commit

Permalink
Merge pull request #19340 from gsmet/json-view-test
Browse files Browse the repository at this point in the history
Add test for @JSONVIEW support in RESTEasy Jackson
  • Loading branch information
Sanne authored Aug 17, 2021
2 parents 057935e + 3ac2305 commit 39b9cf6
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
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 {
}
}
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"));
}
}

0 comments on commit 39b9cf6

Please sign in to comment.