diff options
author | 2021-01-19 08:16:19 +0100 | |
---|---|---|
committer | 2021-01-19 15:26:01 +0100 | |
commit | 26ef1a575d819de4e1dae9f9044b1ab715f41b13 (patch) | |
tree | ac9199ecff2bd255c0fa30b966df06d414b82de2 /certService/src/test/java | |
parent | d25b1cabc9185e9dc65a4a5f8b51bb3a67d7cace (diff) |
[CMPV2] Fix NPE & enhance error messages
Fix NPE.
Include error messages returned by CMP server in API response.
Issue-ID: OOM-2657
Signed-off-by: Jan Malkiewicz <jan.malkiewicz@nokia.com>
Change-Id: I6ec46b14ba04b5be10de5994236efd8fc14c5d2e
Diffstat (limited to 'certService/src/test/java')
2 files changed, 23 insertions, 7 deletions
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 081a01a0..9e6a6ced 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 @@ -3,6 +3,7 @@ * PROJECT * ================================================================================ * Copyright (C) 2020 Nokia. All rights reserved. + * Copyright (C) 2021 Nokia. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +21,10 @@ package org.onap.oom.certservice.api.advice; -import com.google.gson.Gson; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +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.Cmpv2ClientAdapterException; @@ -29,12 +33,10 @@ import org.onap.oom.certservice.certification.exception.CsrDecryptionException; import org.onap.oom.certservice.certification.exception.ErrorResponseModel; import org.onap.oom.certservice.certification.exception.KeyDecryptionException; import org.onap.oom.certservice.cmpv2client.exceptions.CmpClientException; +import org.onap.oom.certservice.cmpv2client.exceptions.CmpServerException; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - class CertificationExceptionAdviceTest { private CertificationExceptionAdvice certificationExceptionAdvice; @@ -98,7 +100,7 @@ class CertificationExceptionAdviceTest { // Then assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); - assertEquals(expectedMessage, response.getBody().getErrorMessage()); + assertTrue(response.getBody().getErrorMessage().startsWith(expectedMessage)); } @Test @@ -112,7 +114,7 @@ class CertificationExceptionAdviceTest { // Then assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); - assertEquals(expectedMessage, response.getBody().getErrorMessage()); + assertTrue(response.getBody().getErrorMessage().startsWith(expectedMessage)); } @Test @@ -131,4 +133,17 @@ class CertificationExceptionAdviceTest { assertEquals(expectedMessage, exception.getMessage()); } + @Test + void shouldReturnResponseEntityWithCmpErrorMessage() { + // Given + String expectedMessage = "CMPv2 server returned following error: EJBCA fault"; + CmpServerException exception = new CmpServerException("EJBCA fault"); + + // When + ResponseEntity<ErrorResponseModel> response = certificationExceptionAdvice.handle(exception); + + // Then + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + assertTrue(response.getBody().getErrorMessage().startsWith(expectedMessage)); + } } diff --git a/certService/src/test/java/org/onap/oom/certservice/cmpv2client/Cmpv2ClientTest.java b/certService/src/test/java/org/onap/oom/certservice/cmpv2client/Cmpv2ClientTest.java index b09025b2..df9699ae 100644 --- a/certService/src/test/java/org/onap/oom/certservice/cmpv2client/Cmpv2ClientTest.java +++ b/certService/src/test/java/org/onap/oom/certservice/cmpv2client/Cmpv2ClientTest.java @@ -62,6 +62,7 @@ import org.onap.oom.certservice.certification.configuration.model.Authentication import org.onap.oom.certservice.certification.configuration.model.Cmpv2Server; import org.onap.oom.certservice.certification.model.CsrModel; import org.onap.oom.certservice.cmpv2client.exceptions.CmpClientException; +import org.onap.oom.certservice.cmpv2client.exceptions.CmpServerException; import org.onap.oom.certservice.cmpv2client.impl.CmpClientImpl; import org.onap.oom.certservice.cmpv2client.model.Cmpv2CertificationModel; @@ -230,7 +231,7 @@ class Cmpv2ClientTest { // then Assertions.assertThrows( - CmpClientException.class, + CmpServerException.class, () -> cmpClient.createCertificate(csrModel, server, notBefore, notAfter)); } |