diff options
author | Bogumil Zebek <bogumil.zebek@nokia.com> | 2021-07-19 08:04:05 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-07-19 08:04:05 +0000 |
commit | 62cacd0f91bca52fcdce37b1f46a13757dc1dbd8 (patch) | |
tree | 927fd5a13d4b2144a39ca5114d46fcf0ee11d331 | |
parent | 42211b22e5f1febbd3973308b4a262bf732b688f (diff) | |
parent | 59d3b4a3351a8146a562bbda2ebb9e8b4b5f0e3e (diff) |
Merge "[OOM-CERT-SERVICE] Add CertificateDecriptionException handler"
2 files changed, 26 insertions, 0 deletions
diff --git a/certService/src/main/java/org/onap/oom/certservice/api/advice/CertificationExceptionAdvice.java b/certService/src/main/java/org/onap/oom/certservice/api/advice/CertificationExceptionAdvice.java index 1c6c3a0a..e3fa1cb2 100644 --- a/certService/src/main/java/org/onap/oom/certservice/api/advice/CertificationExceptionAdvice.java +++ b/certService/src/main/java/org/onap/oom/certservice/api/advice/CertificationExceptionAdvice.java @@ -22,6 +22,7 @@ package org.onap.oom.certservice.api.advice; import org.onap.oom.certservice.api.CertificationController; +import org.onap.oom.certservice.certification.exception.CertificateDecryptionException; import org.onap.oom.certservice.certification.exception.Cmpv2ClientAdapterException; import org.onap.oom.certservice.certification.exception.Cmpv2ServerNotFoundException; import org.onap.oom.certservice.certification.exception.CsrDecryptionException; @@ -59,6 +60,15 @@ public final class CertificationExceptionAdvice { ); } + @ExceptionHandler(value = CertificateDecryptionException.class) + public ResponseEntity<ErrorResponseModel> handle(CertificateDecryptionException exception) { + LOGGER.error("Exception occurred decoding certificate:", exception); + return getErrorResponseEntity( + "Wrong certificate format", + HttpStatus.BAD_REQUEST + ); + } + @ExceptionHandler(value = Cmpv2ServerNotFoundException.class) public ResponseEntity<ErrorResponseModel> handle(Cmpv2ServerNotFoundException exception) { LOGGER.error("Exception occurred selecting CMPv2 server:", exception); diff --git a/certService/src/test/java/org/onap/oom/certservice/api/advice/CertificationExceptionAdviceTest.java b/certService/src/test/java/org/onap/oom/certservice/api/advice/CertificationExceptionAdviceTest.java index 9e6a6ced..698ded80 100644 --- a/certService/src/test/java/org/onap/oom/certservice/api/advice/CertificationExceptionAdviceTest.java +++ b/certService/src/test/java/org/onap/oom/certservice/api/advice/CertificationExceptionAdviceTest.java @@ -27,6 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.onap.oom.certservice.certification.exception.CertificateDecryptionException; import org.onap.oom.certservice.certification.exception.Cmpv2ClientAdapterException; import org.onap.oom.certservice.certification.exception.Cmpv2ServerNotFoundException; import org.onap.oom.certservice.certification.exception.CsrDecryptionException; @@ -146,4 +147,19 @@ class CertificationExceptionAdviceTest { assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); assertTrue(response.getBody().getErrorMessage().startsWith(expectedMessage)); } + + @Test + void shouldReturnResponseEntityWithCertificateDecryptionMessage() { + // Given + String expectedMessage = "Wrong certificate format"; + CertificateDecryptionException exception = new CertificateDecryptionException("Incorrect certificate, decryption failed"); + + // When + ResponseEntity<ErrorResponseModel> response = certificationExceptionAdvice.handle(exception); + + // Then + assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode()); + assertEquals(expectedMessage, response.getBody().getErrorMessage()); + } + } |