|
7 | 7 | import static org.assertj.core.api.Assertions.assertThat; |
8 | 8 |
|
9 | 9 | import fr.istic.web.rest.vm.LoginVM; |
| 10 | +import io.restassured.internal.mapping.Jackson2Mapper; |
10 | 11 | import io.restassured.mapper.ObjectMapper; |
11 | | -import io.restassured.mapper.ObjectMapperDeserializationContext; |
12 | | -import io.restassured.mapper.ObjectMapperSerializationContext; |
13 | | -import jakarta.json.JsonConfig; |
14 | 12 | import jakarta.ws.rs.core.HttpHeaders; |
15 | 13 | import jakarta.ws.rs.core.MediaType; |
16 | 14 | import java.time.ZoneId; |
17 | 15 | import java.time.format.DateTimeFormatter; |
18 | 16 | import java.time.temporal.Temporal; |
19 | 17 |
|
| 18 | +import com.fasterxml.jackson.databind.DeserializationFeature; |
| 19 | + |
20 | 20 | /** |
21 | 21 | * Utility class for testing REST controllers. |
22 | 22 | */ |
23 | 23 | public final class TestUtil { |
24 | 24 |
|
25 | 25 | private static DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter |
26 | | - .ofPattern(DATE_TIME_FORMAT) |
27 | | - .withZone(ZoneId.of("UTC")); |
| 26 | + .ofPattern(DATE_TIME_FORMAT) |
| 27 | + .withZone(ZoneId.of("UTC")); |
28 | 28 |
|
29 | 29 | public static String formatDateTime(Temporal temporal) { |
30 | 30 | return DATE_TIME_FORMATTER.format(temporal); |
@@ -54,42 +54,38 @@ public static String getAdminToken() { |
54 | 54 | } |
55 | 55 |
|
56 | 56 | public static String getToken(String username, String password) { |
57 | | - //Authenticating user |
| 57 | + // Authenticating user |
58 | 58 | var login = new LoginVM(); |
59 | 59 | login.username = username; |
60 | 60 | login.password = password; |
61 | 61 |
|
62 | 62 | return given() |
63 | | - .body(login) |
64 | | - .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) |
65 | | - .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON) |
66 | | - .when() |
67 | | - .post("/api/authenticate") |
68 | | - .then() |
69 | | - .statusCode(OK.getStatusCode()) |
70 | | - .body("id_token", instanceOf(String.class)) |
71 | | - .body("id_token", notNullValue()) |
72 | | - .header(HttpHeaders.AUTHORIZATION, not(blankOrNullString())) |
73 | | - .extract() |
74 | | - .path("id_token"); |
| 63 | + .body(login) |
| 64 | + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) |
| 65 | + .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON) |
| 66 | + .when() |
| 67 | + .post("/api/authenticate") |
| 68 | + .then() |
| 69 | + .statusCode(OK.getStatusCode()) |
| 70 | + .body("id_token", instanceOf(String.class)) |
| 71 | + .body("id_token", notNullValue()) |
| 72 | + .header(HttpHeaders.AUTHORIZATION, not(blankOrNullString())) |
| 73 | + .extract() |
| 74 | + .path("id_token"); |
75 | 75 | } |
76 | 76 |
|
77 | 77 | public static ObjectMapper jsonbObjectMapper() { |
78 | | - final var config = new JsonConfig().withDateFormat(DATE_TIME_FORMAT, null); |
79 | | - final Jsonb jsonb = JsonbBuilder.create(config); |
80 | | - return new ObjectMapper() { |
81 | 78 |
|
82 | | - @Override |
83 | | - public Object deserialize(ObjectMapperDeserializationContext context) { |
84 | | - return jsonb.fromJson(context.getDataToDeserialize().asString(), context.getType()); |
85 | | - } |
| 79 | + io.restassured.mapper.ObjectMapper objectMapper = new Jackson2Mapper(((type, charset) -> { |
| 80 | + com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper() |
| 81 | + .findAndRegisterModules(); |
| 82 | + om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); |
| 83 | + return om; |
| 84 | + })); |
86 | 85 |
|
87 | | - @Override |
88 | | - public Object serialize(ObjectMapperSerializationContext context) { |
89 | | - return jsonb.toJson(context.getObjectToSerialize()); |
90 | | - } |
91 | | - }; |
| 86 | + return objectMapper; |
92 | 87 | } |
93 | 88 |
|
94 | | - private TestUtil() {} |
| 89 | + private TestUtil() { |
| 90 | + } |
95 | 91 | } |
0 commit comments