X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=certService%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Foom%2Fcertservice%2Fapi%2Fadvice%2FCertificationExceptionAdviceTest.java;fp=certService%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Foom%2Fcertservice%2Fapi%2Fadvice%2FCertificationExceptionAdviceTest.java;h=9e6a6ced486f52ccd1a2f5c9c36db74c37b41939;hb=26ef1a575d819de4e1dae9f9044b1ab715f41b13;hp=081a01a0b6782165d140c85cde857b44ed1a1c99;hpb=d25b1cabc9185e9dc65a4a5f8b51bb3a67d7cace;p=oom%2Fplatform%2Fcert-service.git 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 response = certificationExceptionAdvice.handle(exception); + + // Then + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); + assertTrue(response.getBody().getErrorMessage().startsWith(expectedMessage)); + } }