Skip to content

Commit 943a0e2

Browse files
committed
fix test
1 parent 892cfdc commit 943a0e2

3 files changed

Lines changed: 30 additions & 32 deletions

File tree

src/main/java/fr/istic/config/JsonConfiguration.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public class JsonConfiguration implements ObjectMapperCustomizer {
3333

3434
@Override
3535
public void customize(ObjectMapper objectMapper) {
36-
// TODO Auto-generated method stub
3736
var module = new SimpleModule();
3837
module.addDeserializer(byte[].class, new CustomByteDeserializer());
3938
module.addSerializer(new CustomByteSerializer());

src/main/java/fr/istic/web/rest/AccountResource.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import fr.istic.web.rest.vm.ManagedUserVM;
1515

1616
import io.quarkus.security.Authenticated;
17+
import io.smallrye.common.annotation.Blocking;
18+
1719
import java.security.Principal;
1820
import java.util.Optional;
1921
import java.util.concurrent.CompletionStage;
@@ -107,6 +109,7 @@ public Response saveAccount(@Valid UserDTO userDTO, @Context SecurityContext ctx
107109
*/
108110
@POST
109111
@Path("/register")
112+
@Blocking
110113
@PermitAll
111114
public CompletionStage<Response> registerAccount(@Valid ManagedUserVM managedUserVM) {
112115
if (!checkPasswordLength(managedUserVM.password)) {

src/test/java/fr/istic/TestUtil.java

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@
77
import static org.assertj.core.api.Assertions.assertThat;
88

99
import fr.istic.web.rest.vm.LoginVM;
10+
import io.restassured.internal.mapping.Jackson2Mapper;
1011
import io.restassured.mapper.ObjectMapper;
11-
import io.restassured.mapper.ObjectMapperDeserializationContext;
12-
import io.restassured.mapper.ObjectMapperSerializationContext;
13-
import jakarta.json.JsonConfig;
1412
import jakarta.ws.rs.core.HttpHeaders;
1513
import jakarta.ws.rs.core.MediaType;
1614
import java.time.ZoneId;
1715
import java.time.format.DateTimeFormatter;
1816
import java.time.temporal.Temporal;
1917

18+
import com.fasterxml.jackson.databind.DeserializationFeature;
19+
2020
/**
2121
* Utility class for testing REST controllers.
2222
*/
2323
public final class TestUtil {
2424

2525
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"));
2828

2929
public static String formatDateTime(Temporal temporal) {
3030
return DATE_TIME_FORMATTER.format(temporal);
@@ -54,42 +54,38 @@ public static String getAdminToken() {
5454
}
5555

5656
public static String getToken(String username, String password) {
57-
//Authenticating user
57+
// Authenticating user
5858
var login = new LoginVM();
5959
login.username = username;
6060
login.password = password;
6161

6262
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");
7575
}
7676

7777
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() {
8178

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+
}));
8685

87-
@Override
88-
public Object serialize(ObjectMapperSerializationContext context) {
89-
return jsonb.toJson(context.getObjectToSerialize());
90-
}
91-
};
86+
return objectMapper;
9287
}
9388

94-
private TestUtil() {}
89+
private TestUtil() {
90+
}
9591
}

0 commit comments

Comments
 (0)