TSK-1676: Fixed REST Exception Mapping for *InUseExceptions.

This commit is contained in:
Holger Hagen 2021-08-02 14:43:22 +02:00 committed by holgerhagen
parent 6f344c9363
commit 0ebdb3095b
2 changed files with 29 additions and 5 deletions

View File

@ -36,7 +36,6 @@ import pro.taskana.common.api.exceptions.DomainNotFoundException;
import pro.taskana.common.api.exceptions.ErrorCode; import pro.taskana.common.api.exceptions.ErrorCode;
import pro.taskana.common.api.exceptions.InvalidArgumentException; import pro.taskana.common.api.exceptions.InvalidArgumentException;
import pro.taskana.common.api.exceptions.MismatchedRoleException; import pro.taskana.common.api.exceptions.MismatchedRoleException;
import pro.taskana.common.api.exceptions.NotFoundException;
import pro.taskana.common.api.exceptions.TaskanaException; import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.api.exceptions.TaskanaRuntimeException; import pro.taskana.common.api.exceptions.TaskanaRuntimeException;
import pro.taskana.common.api.exceptions.WrongCustomHolidayFormatException; import pro.taskana.common.api.exceptions.WrongCustomHolidayFormatException;
@ -84,7 +83,7 @@ public class TaskanaRestExceptionHandler extends ResponseEntityExceptionHandler
TaskanaHistoryEventNotFoundException.class, TaskanaHistoryEventNotFoundException.class,
WorkbasketNotFoundException.class WorkbasketNotFoundException.class
}) })
protected ResponseEntity<Object> handleNotFound(NotFoundException ex, WebRequest req) { protected ResponseEntity<Object> handleNotFound(TaskanaException ex, WebRequest req) {
return buildResponse(ex.getErrorCode(), ex, req, HttpStatus.NOT_FOUND); return buildResponse(ex.getErrorCode(), ex, req, HttpStatus.NOT_FOUND);
} }
@ -102,8 +101,7 @@ public class TaskanaRestExceptionHandler extends ResponseEntityExceptionHandler
} }
@ExceptionHandler({WorkbasketInUseException.class, ClassificationInUseException.class}) @ExceptionHandler({WorkbasketInUseException.class, ClassificationInUseException.class})
protected ResponseEntity<Object> handleWorkbasketInUse( protected ResponseEntity<Object> handleWorkbasketInUse(TaskanaException ex, WebRequest req) {
WorkbasketInUseException ex, WebRequest req) {
return buildResponse(ex.getErrorCode(), ex, req, HttpStatus.LOCKED); return buildResponse(ex.getErrorCode(), ex, req, HttpStatus.LOCKED);
} }

View File

@ -425,7 +425,33 @@ class ClassificationControllerIntTest {
auth, auth,
ParameterizedTypeReference.<ClassificationSummaryRepresentationModel>forType( ParameterizedTypeReference.<ClassificationSummaryRepresentationModel>forType(
ClassificationSummaryRepresentationModel.class)); ClassificationSummaryRepresentationModel.class));
assertThatThrownBy(httpCall).isInstanceOf(HttpStatusCodeException.class); assertThatThrownBy(httpCall)
.isInstanceOf(HttpStatusCodeException.class)
.extracting(HttpStatusCodeException.class::cast)
.extracting(HttpStatusCodeException::getStatusCode)
.isEqualTo(HttpStatus.NOT_FOUND);
}
@Test
@DirtiesContext
void should_ReturnStatusCodeLocked_When_DeletingClassificationInUse() {
String url =
restHelper.toUrl(
RestEndpoints.URL_CLASSIFICATIONS_ID, "CLI:000000000000000000000000000000000003");
HttpEntity<?> auth = new HttpEntity<>(RestHelper.generateHeadersForUser("businessadmin"));
ThrowingCallable httpCall =
() ->
TEMPLATE.exchange(
url,
HttpMethod.DELETE,
auth,
ParameterizedTypeReference.forType(ClassificationSummaryRepresentationModel.class));
assertThatThrownBy(httpCall)
.isInstanceOf(HttpStatusCodeException.class)
.extracting(HttpStatusCodeException.class::cast)
.extracting(HttpStatusCodeException::getStatusCode)
.isEqualTo(HttpStatus.LOCKED);
} }
@Test @Test