diff --git a/libs/SharedLib/src/main/java/com/bottega/sharedlib/vo/error/ErrorExceptionMapper.java b/libs/SharedLib/src/main/java/com/bottega/sharedlib/vo/error/ErrorExceptionMapper.java index b50fadab..d899b31b 100644 --- a/libs/SharedLib/src/main/java/com/bottega/sharedlib/vo/error/ErrorExceptionMapper.java +++ b/libs/SharedLib/src/main/java/com/bottega/sharedlib/vo/error/ErrorExceptionMapper.java @@ -2,10 +2,9 @@ import com.bottega.sharedlib.dto.ErrorDto; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.*; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; import static org.springframework.http.MediaType.APPLICATION_JSON; @ControllerAdvice @@ -18,8 +17,7 @@ public ResponseEntity convertToResponse(ErrorException exception) { ErrorResult error = exception.getError(); log.info("Mapping Error to HTTP code: {}, error: {}", error.getType().getHttpStatus(), error); return ResponseEntity - //TODO should it return 500 always? - .status(INTERNAL_SERVER_ERROR) + .status(error.getType().getHttpStatus()) .contentType(APPLICATION_JSON) .body(ErrorDto.from(error)); } diff --git a/libs/SharedLib/src/test/java/com/bottega/sharedlib/fixtures/ErrorJsonAssert.java b/libs/SharedLib/src/test/java/com/bottega/sharedlib/fixtures/ErrorJsonAssert.java index ab0cdddf..ba01a852 100644 --- a/libs/SharedLib/src/test/java/com/bottega/sharedlib/fixtures/ErrorJsonAssert.java +++ b/libs/SharedLib/src/test/java/com/bottega/sharedlib/fixtures/ErrorJsonAssert.java @@ -41,7 +41,9 @@ public ErrorJsonAssert isNotFound(String expectedDescription) { } public ErrorJsonAssert isBadRequest(String expectedDesc) { - //TODO implement - return null; + errorResponse.statusCode(SC_BAD_REQUEST); + return hasType(BAD_REQUEST) + .hasCode(invalid_request) + .hasDescription(expectedDesc); } } diff --git a/services/Promoter/src/test/java/com/bottega/promoter/concert/api/rest/CreateConcertRestController_createConcert_restApiTest.java b/services/Promoter/src/test/java/com/bottega/promoter/concert/api/rest/CreateConcertRestController_createConcert_restApiTest.java index a62e1ee6..b86a9c61 100644 --- a/services/Promoter/src/test/java/com/bottega/promoter/concert/api/rest/CreateConcertRestController_createConcert_restApiTest.java +++ b/services/Promoter/src/test/java/com/bottega/promoter/concert/api/rest/CreateConcertRestController_createConcert_restApiTest.java @@ -43,13 +43,15 @@ public void createConcert_OK_onValidRequest() { @Test public void createConcert_returnsBadRequest_onDateTooSoon() { - //TODO implement //given + ConcertHttpClient.ConcertRequest concertRequest = ConcertHttpClient.ConcertRequest.builder().date(TEST_TIME).build(); //when + ValidatableResponse response = concertFixtures.concertHttpClient.createConcert(concertRequest); //then - + assertThatError(response) + .isBadRequest("invalid_date"); }