aboutsummaryrefslogtreecommitdiffstats
path: root/certService/src/test/java/org/onap/aaf/certservice/api
diff options
context:
space:
mode:
authorbaniewsk <pawel.baniewski@nokia.com>2020-07-29 16:01:27 +0200
committerPawel <pawel.kasperkiewicz@nokia.com>2020-08-05 14:18:54 +0200
commitb8c4e6867d6b26652f4382e93665c220769cdc9f (patch)
treebb60a44b012731e3ee6fdffe2466f5ed7d6b5c7b /certService/src/test/java/org/onap/aaf/certservice/api
parentfc31c9e47b3e08f8914dcd1f0c5b6d18aa625567 (diff)
Removing AAF references from Cert-Service in OOM repo.
Certificates regenerated External files (from legacy AAF) removed Still left: * Sonar link, * Link to documentation, * Names of K8s resources in RTD documentation, * Link to CSITs Issue-ID: OOM-2526 Signed-off-by: Pawel Baniewski <pawel.baniewski@nokia.com> Change-Id: I675f7485160b9b8e46e9ea573550e62ed28ca607
Diffstat (limited to 'certService/src/test/java/org/onap/aaf/certservice/api')
-rw-r--r--certService/src/test/java/org/onap/aaf/certservice/api/CertificationControllerTest.java147
-rw-r--r--certService/src/test/java/org/onap/aaf/certservice/api/ReadinessControllerTest.java59
-rw-r--r--certService/src/test/java/org/onap/aaf/certservice/api/ReloadConfigControllerTest.java77
-rw-r--r--certService/src/test/java/org/onap/aaf/certservice/api/advice/CertificationExceptionAdviceTest.java134
-rw-r--r--certService/src/test/java/org/onap/aaf/certservice/api/advice/ReloadConfigExceptionAdviceTest.java56
5 files changed, 0 insertions, 473 deletions
diff --git a/certService/src/test/java/org/onap/aaf/certservice/api/CertificationControllerTest.java b/certService/src/test/java/org/onap/aaf/certservice/api/CertificationControllerTest.java
deleted file mode 100644
index 449670c3..00000000
--- a/certService/src/test/java/org/onap/aaf/certservice/api/CertificationControllerTest.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PROJECT
- * ================================================================================
- * Copyright (C) 2020 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.aaf.certservice.api;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.Mockito.when;
-
-import java.util.Arrays;
-
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-import org.onap.aaf.certservice.certification.CertificationModelFactory;
-import org.onap.aaf.certservice.certification.exception.Cmpv2ClientAdapterException;
-import org.onap.aaf.certservice.certification.exception.Cmpv2ServerNotFoundException;
-import org.onap.aaf.certservice.certification.exception.CsrDecryptionException;
-import org.onap.aaf.certservice.certification.exception.DecryptionException;
-import org.onap.aaf.certservice.certification.exception.KeyDecryptionException;
-import org.onap.aaf.certservice.certification.model.CertificationModel;
-import org.onap.aaf.certservice.cmpv2client.exceptions.CmpClientException;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-
-@ExtendWith(MockitoExtension.class)
-class CertificationControllerTest {
-
- private static final String TEST_CA_NAME = "TestCa";
- private static final String TEST_ENCODED_CSR = "encodedCSR";
- private static final String TEST_ENCODED_PK = "encodedPK";
- private static final String TEST_WRONG_ENCODED_CSR = "wrongEncodedCSR";
- private static final String TEST_WRONG_ENCODED_PK = "wrongEncodedPK";
- private static final String TEST_WRONG_CA_NAME = "wrongTestCa";
-
- private CertificationController certificationController;
-
- @Mock
- private CertificationModelFactory certificationModelFactory;
-
- @BeforeEach
- void serUp() {
- certificationController = new CertificationController(certificationModelFactory);
- }
-
- @Test
- void shouldReturnDataAboutCsrBaseOnEncodedParameters()
- throws DecryptionException, CmpClientException, Cmpv2ClientAdapterException {
- // Given
- CertificationModel testCertificationModel = new CertificationModel(
- Arrays.asList("ENTITY_CERT", "INTERMEDIATE_CERT"),
- Arrays.asList("CA_CERT", "EXTRA_CA_CERT")
- );
- when(certificationModelFactory.createCertificationModel(TEST_ENCODED_CSR, TEST_ENCODED_PK, TEST_CA_NAME))
- .thenReturn(testCertificationModel);
-
- // When
- ResponseEntity<CertificationModel> responseCertificationModel =
- certificationController.signCertificate(TEST_CA_NAME, TEST_ENCODED_CSR, TEST_ENCODED_PK);
-
- // Then
- assertEquals(HttpStatus.OK, responseCertificationModel.getStatusCode());
- assertThat(responseCertificationModel.getBody()
- ).isEqualToComparingFieldByField(testCertificationModel);
-
- }
-
- @Test
- void shouldThrowCsrDecryptionExceptionWhenCreatingCsrModelFails()
- throws DecryptionException, CmpClientException, Cmpv2ClientAdapterException {
- // Given
- String expectedMessage = "Incorrect CSR, decryption failed";
- when(certificationModelFactory.createCertificationModel(TEST_WRONG_ENCODED_CSR, TEST_ENCODED_PK, TEST_CA_NAME))
- .thenThrow(new CsrDecryptionException(expectedMessage));
-
- // When
- Exception exception = assertThrows(
- CsrDecryptionException.class, () ->
- certificationController.signCertificate(TEST_CA_NAME, TEST_WRONG_ENCODED_CSR, TEST_ENCODED_PK)
- );
-
- String actualMessage = exception.getMessage();
-
- // Then
- assertEquals(expectedMessage, actualMessage);
- }
-
- @Test
- void shouldThrowPemDecryptionExceptionWhenCreatingPemModelFails()
- throws DecryptionException, CmpClientException, Cmpv2ClientAdapterException {
- // Given
- String expectedMessage = "Incorrect PEM, decryption failed";
- when(certificationModelFactory.createCertificationModel(TEST_ENCODED_CSR, TEST_WRONG_ENCODED_PK, TEST_CA_NAME))
- .thenThrow(new KeyDecryptionException(expectedMessage));
-
- // When
- Exception exception = assertThrows(
- KeyDecryptionException.class, () ->
- certificationController.signCertificate(TEST_CA_NAME, TEST_ENCODED_CSR, TEST_WRONG_ENCODED_PK)
- );
-
- String actualMessage = exception.getMessage();
-
- // Then
- assertEquals(expectedMessage, actualMessage);
- }
-
- @Test
- void shouldThrowCmpv2ServerNotFoundWhenGivenWrongCaName()
- throws DecryptionException, CmpClientException, Cmpv2ClientAdapterException {
- // Given
- String expectedMessage = "No server found for given CA name";
- when(certificationModelFactory.createCertificationModel(TEST_ENCODED_CSR, TEST_ENCODED_PK, TEST_WRONG_CA_NAME))
- .thenThrow(new Cmpv2ServerNotFoundException(expectedMessage));
-
- // When
- Exception exception = assertThrows(
- Cmpv2ServerNotFoundException.class, () ->
- certificationController.signCertificate(TEST_WRONG_CA_NAME, TEST_ENCODED_CSR, TEST_ENCODED_PK)
- );
-
- String actualMessage = exception.getMessage();
-
- // Then
- assertEquals(expectedMessage, actualMessage);
- }
-}
diff --git a/certService/src/test/java/org/onap/aaf/certservice/api/ReadinessControllerTest.java b/certService/src/test/java/org/onap/aaf/certservice/api/ReadinessControllerTest.java
deleted file mode 100644
index d3ed7301..00000000
--- a/certService/src/test/java/org/onap/aaf/certservice/api/ReadinessControllerTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PROJECT
- * ================================================================================
- * Copyright (C) 2020 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.aaf.certservice.api;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.junit.jupiter.MockitoExtension;
-import org.onap.aaf.certservice.certification.configuration.CmpServersConfig;
-import org.springframework.http.HttpStatus;
-
-@ExtendWith(MockitoExtension.class)
-public class ReadinessControllerTest {
-
- @Mock
- private CmpServersConfig cmpServersConfig;
-
- @Test
- public void shouldReturnStatusOkWhenConfigIsReady() {
- // Given
- Mockito.when(cmpServersConfig.isReady()).thenReturn(true);
-
- // Then
- assertThat(new ReadinessController(cmpServersConfig).checkReady().getStatusCode()).isEqualTo(HttpStatus.OK);
- ;
- }
-
- @Test
- public void shouldReturnStatusServiceUnavailableWhenConfigIsNotReady() {
- // Given
- Mockito.when(cmpServersConfig.isReady()).thenReturn(false);
-
- // Then
- assertThat(new ReadinessController(cmpServersConfig).checkReady().getStatusCode()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE);
- ;
- }
-
-}
diff --git a/certService/src/test/java/org/onap/aaf/certservice/api/ReloadConfigControllerTest.java b/certService/src/test/java/org/onap/aaf/certservice/api/ReloadConfigControllerTest.java
deleted file mode 100644
index 92c18e16..00000000
--- a/certService/src/test/java/org/onap/aaf/certservice/api/ReloadConfigControllerTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PROJECT
- * ================================================================================
- * Copyright (C) 2020 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.aaf.certservice.api;
-
-import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.Mockito.doThrow;
-
-import org.assertj.core.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-import org.onap.aaf.certservice.certification.configuration.CmpServersConfig;
-import org.onap.aaf.certservice.certification.configuration.CmpServersConfigLoadingException;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-
-@ExtendWith(MockitoExtension.class)
-public class ReloadConfigControllerTest {
-
- private static final String ERROR_MESSAGE = "Exception occurred during CMP Servers configuration loading";
-
- private ReloadConfigController reloadConfigController;
-
- @Mock
- public CmpServersConfig cmpServersConfig;
-
- @BeforeEach
- void setUp() {
- this.reloadConfigController = new ReloadConfigController(cmpServersConfig);
- }
-
- @Test
- void shouldReturnStatusOkWhenSuccessfullyReloaded() throws CmpServersConfigLoadingException {
- // When
- ResponseEntity<String> response = reloadConfigController.reloadConfiguration();
-
- // Then
- assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
- }
-
- @Test
- void shouldRethrowSameErrorWhenFailedToReload() throws CmpServersConfigLoadingException {
- // Given
- doThrow(new CmpServersConfigLoadingException(ERROR_MESSAGE)).when(cmpServersConfig).reloadConfiguration();
-
- // When
- Exception exception = assertThrows(
- CmpServersConfigLoadingException.class,
- () -> reloadConfigController.reloadConfiguration());
-
- // Then
- Assertions.assertThat(exception.getMessage()).isEqualTo(ERROR_MESSAGE);
- }
-
-
-}
diff --git a/certService/src/test/java/org/onap/aaf/certservice/api/advice/CertificationExceptionAdviceTest.java b/certService/src/test/java/org/onap/aaf/certservice/api/advice/CertificationExceptionAdviceTest.java
deleted file mode 100644
index f3c4ec7f..00000000
--- a/certService/src/test/java/org/onap/aaf/certservice/api/advice/CertificationExceptionAdviceTest.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PROJECT
- * ================================================================================
- * Copyright (C) 2020 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.aaf.certservice.api.advice;
-
-import com.google.gson.Gson;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.onap.aaf.certservice.certification.exception.Cmpv2ClientAdapterException;
-import org.onap.aaf.certservice.certification.exception.Cmpv2ServerNotFoundException;
-import org.onap.aaf.certservice.certification.exception.CsrDecryptionException;
-import org.onap.aaf.certservice.certification.exception.ErrorResponseModel;
-import org.onap.aaf.certservice.certification.exception.KeyDecryptionException;
-import org.onap.aaf.certservice.cmpv2client.exceptions.CmpClientException;
-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;
-
- @BeforeEach
- void setUp() {
- certificationExceptionAdvice =
- new CertificationExceptionAdvice();
- }
-
- @Test
- void shouldReturnResponseEntityWithAppropriateErrorMessageWhenGivenCsrDecryptionException() {
- // Given
- String expectedMessage = "Wrong certificate signing request (CSR) format";
- CsrDecryptionException csrDecryptionException = new CsrDecryptionException("test csr exception");
-
- // When
- ResponseEntity<ErrorResponseModel> response = certificationExceptionAdvice.handle(csrDecryptionException);
-
- // Then
- assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
- assertEquals(expectedMessage, response.getBody().getErrorMessage());
- }
-
- @Test
- void shouldReturnResponseEntityWithAppropriateErrorMessageWhenGivenKeyDecryptionException() {
- // Given
- String expectedMessage = "Wrong key (PK) format";
- KeyDecryptionException csrDecryptionException = new KeyDecryptionException("test pk exception");
-
- // When
- ResponseEntity<ErrorResponseModel> response = certificationExceptionAdvice.handle(csrDecryptionException);
-
- // Then
- assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
- assertEquals(expectedMessage, response.getBody().getErrorMessage());
- }
-
- @Test
- void shouldReturnResponseEntityWithAppropriateErrorMessageWhenGivenCaNameIsNotPresentInConfig() {
- // Given
- String expectedMessage = "Certification authority not found for given CAName";
- Cmpv2ServerNotFoundException csrDecryptionException = new Cmpv2ServerNotFoundException("test Ca exception");
-
- // When
- ResponseEntity<ErrorResponseModel> response = certificationExceptionAdvice.handle(csrDecryptionException);
-
- // Then
- assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
- assertEquals(expectedMessage, response.getBody().getErrorMessage());
- }
-
- @Test
- void shouldReturnResponseEntityWithAppropriateErrorMessageWhenCallingCmpClientFail() {
- // Given
- String expectedMessage = "Exception occurred during call to cmp client";
- CmpClientException cmpClientException = new CmpClientException("Calling CMPv2 client failed");
-
- // When
- ResponseEntity<ErrorResponseModel> response = certificationExceptionAdvice.handle(cmpClientException);
-
- // Then
- assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
- assertEquals(expectedMessage, response.getBody().getErrorMessage());
- }
-
- @Test
- void shouldReturnResponseEntityWithAppropriateErrorMessageWhenModelTransformationInAdapterFail() {
- // Given
- String expectedMessage = "Exception occurred parsing cmp client response";
- Cmpv2ClientAdapterException cmpv2ClientAdapterException = new Cmpv2ClientAdapterException(new Throwable());
-
- // When
- ResponseEntity<ErrorResponseModel> response = certificationExceptionAdvice.handle(cmpv2ClientAdapterException);
-
- // Then
- assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
- assertEquals(expectedMessage, response.getBody().getErrorMessage());
- }
-
- @Test
- void shouldThrowCmpClientExceptionWhenNotHandledRunTimeExceptionOccur() {
- // Given
- String expectedMessage = "Runtime exception occurred calling cmp client business logic";
- RuntimeException runtimeException = new RuntimeException("Unknown runtime exception");
-
- // When
- Exception exception = assertThrows(
- CmpClientException.class, () ->
- certificationExceptionAdvice.handle(runtimeException)
- );
-
- // Then
- assertEquals(expectedMessage, exception.getMessage());
- }
-
-}
diff --git a/certService/src/test/java/org/onap/aaf/certservice/api/advice/ReloadConfigExceptionAdviceTest.java b/certService/src/test/java/org/onap/aaf/certservice/api/advice/ReloadConfigExceptionAdviceTest.java
deleted file mode 100644
index 9abecec9..00000000
--- a/certService/src/test/java/org/onap/aaf/certservice/api/advice/ReloadConfigExceptionAdviceTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PROJECT
- * ================================================================================
- * Copyright (C) 2020 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.aaf.certservice.api.advice;
-
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.onap.aaf.certservice.certification.configuration.CmpServersConfigLoadingException;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-class ReloadConfigExceptionAdviceTest {
-
- private static final String ERROR_MESSAGE = "Exception occurred during CMP Servers configuration loading";
-
- private ReloadConfigExceptionAdvice reloadConfigExceptionAdvice;
-
- @BeforeEach
- void setUp() {
- reloadConfigExceptionAdvice =
- new ReloadConfigExceptionAdvice();
- }
-
- @Test
- void shouldReturnErrorStatusAndMessageWhenExceptionOccurred() {
- // Given
- CmpServersConfigLoadingException exception = new CmpServersConfigLoadingException(ERROR_MESSAGE);
-
- // When
- ResponseEntity<String> response = reloadConfigExceptionAdvice.handle(exception);
-
- // Then
- assertEquals(ERROR_MESSAGE, response.getBody());
- assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
- }
-
-}