Refactoring - Version stable

This commit is contained in:
dahoud
2026-03-28 14:37:57 +00:00
parent a740c172ef
commit 607d31d2fc
2 changed files with 48 additions and 4 deletions

View File

@@ -13,6 +13,8 @@ import com.fasterxml.jackson.core.JsonParser;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.ForbiddenException;
import jakarta.ws.rs.NotAuthorizedException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
import org.junit.jupiter.api.DisplayName;
@@ -67,7 +69,7 @@ class GlobalExceptionMapperTest {
}
@Test
@DisplayName("NotFoundException → 404")
@DisplayName("NotFoundException → 404 (cas métier attendu : pas de log ERROR, pas de persistance)")
void mapRuntimeException_notFound_returns404() {
Response r = globalExceptionMapper.toResponse(
new jakarta.ws.rs.NotFoundException("Ressource introuvable"));
@@ -77,6 +79,27 @@ class GlobalExceptionMapperTest {
assertThat(body.get("error")).isEqualTo("Ressource introuvable");
}
@Test
@DisplayName("ForbiddenException → 403 (cas métier attendu : pas de log ERROR)")
void mapForbiddenException_returns403() {
Response r = globalExceptionMapper.toResponse(new ForbiddenException("Accès refusé"));
assertThat(r.getStatus()).isEqualTo(403);
@SuppressWarnings("unchecked")
java.util.Map<String, Object> body = (java.util.Map<String, Object>) r.getEntity();
assertThat(body.get("error")).isEqualTo("Accès refusé");
}
@Test
@DisplayName("NotAuthorizedException → 401 (cas métier attendu : pas de log ERROR)")
void mapNotAuthorizedException_returns401() {
Response r = globalExceptionMapper.toResponse(
new NotAuthorizedException("Session expirée", "Bearer"));
assertThat(r.getStatus()).isEqualTo(401);
@SuppressWarnings("unchecked")
java.util.Map<String, Object> body = (java.util.Map<String, Object>) r.getEntity();
assertThat(body.get("error")).isNotNull();
}
@Test
@DisplayName("WebApplicationException 400 avec message non vide → 400")
void mapRuntimeException_webApp4xx_withMessage_returns4xx() {