forked from quarkus-qe/quarkus-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part of test development to QUARKUS-1075. Covers one of the advanced topics of the test plan. https://github.com/quarkus-qe/quarkus-test-plans/blob/main/QUARKUS-1075.md
- Loading branch information
Showing
8 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
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
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
42 changes: 42 additions & 0 deletions
42
http/jaxrs-reactive/src/main/java/io/quarkus/ts/jaxrs/reactive/json/JsonResource.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,42 @@ | ||
package io.quarkus.ts.jaxrs.reactive.json; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import com.fasterxml.jackson.annotation.JsonView; | ||
|
||
import io.quarkus.resteasy.reactive.jackson.CustomSerialization; | ||
|
||
@Path("/json") | ||
public class JsonResource { | ||
public static final Integer USER_ID = 1; | ||
public static final String USER_NAME = "testUser"; | ||
|
||
@JsonView(Views.Public.class) | ||
@GET | ||
@Path("/public") | ||
public User userPublic() { | ||
return testUser(); | ||
} | ||
|
||
@JsonView(Views.Private.class) | ||
@GET | ||
@Path("/private") | ||
public User userPrivate() { | ||
return testUser(); | ||
} | ||
|
||
@CustomSerialization(UnquotedFields.class) | ||
@GET | ||
@Path("/custom") | ||
public User userCustom() { | ||
return testUser(); | ||
} | ||
|
||
private User testUser() { | ||
User user = new User(); | ||
user.id = USER_ID; | ||
user.name = USER_NAME; | ||
return user; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
http/jaxrs-reactive/src/main/java/io/quarkus/ts/jaxrs/reactive/json/UnquotedFields.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,18 @@ | ||
package io.quarkus.ts.jaxrs.reactive.json; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.function.BiFunction; | ||
|
||
import com.fasterxml.jackson.core.json.JsonWriteFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.ObjectWriter; | ||
|
||
import io.quarkus.runtime.annotations.RegisterForReflection; | ||
|
||
@RegisterForReflection | ||
public class UnquotedFields implements BiFunction<ObjectMapper, Type, ObjectWriter> { | ||
@Override | ||
public ObjectWriter apply(ObjectMapper objectMapper, Type type) { | ||
return objectMapper.writer().without(JsonWriteFeature.QUOTE_FIELD_NAMES); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
http/jaxrs-reactive/src/main/java/io/quarkus/ts/jaxrs/reactive/json/User.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,12 @@ | ||
package io.quarkus.ts.jaxrs.reactive.json; | ||
|
||
import com.fasterxml.jackson.annotation.JsonView; | ||
|
||
public class User { | ||
|
||
@JsonView(Views.Private.class) | ||
public Integer id; | ||
|
||
@JsonView(Views.Public.class) | ||
public String name; | ||
} |
10 changes: 10 additions & 0 deletions
10
http/jaxrs-reactive/src/main/java/io/quarkus/ts/jaxrs/reactive/json/Views.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,10 @@ | ||
package io.quarkus.ts.jaxrs.reactive.json; | ||
|
||
public class Views { | ||
|
||
public static class Public { | ||
} | ||
|
||
public static class Private extends Public { | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
http/jaxrs-reactive/src/test/java/io/quarkus/ts/jaxrs/reactive/json/JsonResourceIT.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,54 @@ | ||
package io.quarkus.ts.jaxrs.reactive.json; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.scenarios.QuarkusScenario; | ||
import io.restassured.http.ContentType; | ||
import io.restassured.response.ValidatableResponse; | ||
|
||
@Tag("QUARKUS-1075") | ||
@QuarkusScenario | ||
public class JsonResourceIT { | ||
private static final String BASE_PATH = "/json"; | ||
private static final String CUSTOM_JSON = String.format("{id:%d,name:\"%s\"}", JsonResource.USER_ID, | ||
JsonResource.USER_NAME); | ||
|
||
@Test | ||
public void shouldGetUserPublic() { | ||
final User user = getUser("/public"); | ||
assertNull(user.id); | ||
} | ||
|
||
@Test | ||
public void shouldGetUserPrivate() { | ||
final User user = getUser("/private"); | ||
assertNotNull(user.id); | ||
} | ||
|
||
@Test | ||
public void shouldGetCustomJson() { | ||
final String stringBody = whenGet("/custom").extract().body().asString(); | ||
assertEquals(CUSTOM_JSON, stringBody); | ||
} | ||
|
||
private User getUser(String path) { | ||
final User user = whenGet(path).extract().body().as(User.class); | ||
assertNotNull(user.name); | ||
return user; | ||
} | ||
|
||
private ValidatableResponse whenGet(String path) { | ||
return given() | ||
.get(BASE_PATH + path) | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.contentType(ContentType.JSON); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...xrs-reactive/src/test/java/io/quarkus/ts/jaxrs/reactive/json/OpenShiftJsonResourceIT.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,7 @@ | ||
package io.quarkus.ts.jaxrs.reactive.json; | ||
|
||
import io.quarkus.test.scenarios.OpenShiftScenario; | ||
|
||
@OpenShiftScenario | ||
public class OpenShiftJsonResourceIT extends JsonResourceIT { | ||
} |