generated from ministryofjustice/hmpps-template-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Ewan Donovan <ewan.donovan@digital.justice.com>
- Loading branch information
1 parent
83804cc
commit 451351e
Showing
6 changed files
with
487 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...est/kotlin/uk/gov/justice/digital/hmpps/learnerrecordsapi/config/TestExceptionResource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package uk.gov.justice.digital.hmpps.learnerrecordsapi.config | ||
|
||
import com.google.gson.JsonParseException | ||
import org.mockito.Mockito | ||
import org.springframework.core.MethodParameter | ||
import org.springframework.http.HttpInputMessage | ||
import org.springframework.http.converter.HttpMessageNotReadableException | ||
import org.springframework.validation.BindException | ||
import org.springframework.validation.FieldError | ||
import org.springframework.web.bind.MethodArgumentNotValidException | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.lrsapi.response.exceptions.LRSException | ||
import java.io.File | ||
|
||
// Simply to assist in testing HmppsBoldLrsExceptionHandler, the endpoints are only visible to tests. | ||
|
||
@RestController | ||
class TestExceptionResource { | ||
|
||
@PostMapping("/test/validation") | ||
fun triggerValidationException(): Nothing = throw MethodArgumentNotValidException( | ||
MethodParameter(this::class.java.getMethod("triggerValidationException"), -1), | ||
BindException(Any(), "testObject").apply { | ||
addError(FieldError("testObject", "testField", "Validation failed")) | ||
}, | ||
) | ||
|
||
@PostMapping("/test/missing-mandatory-field") | ||
fun triggerMissingFieldException(): Nothing = throw HttpMessageNotReadableException( | ||
"JSON parse error: Missing Field", | ||
JsonParseException("Missing Field"), | ||
Mockito.mock(HttpInputMessage::class.java), | ||
) | ||
|
||
@PostMapping("/test/lrs-error") | ||
fun triggerLRSException(): Nothing = throw LRSException() | ||
|
||
@PostMapping("/test/forbidden") | ||
fun triggerForbiddenException(): Nothing = throw AccessDeniedException(file = File("")) | ||
|
||
@PostMapping("/test/generic-exception") | ||
fun triggerGenericException(): Nothing = throw Exception() | ||
} |
Oops, something went wrong.