aboutsummaryrefslogtreecommitdiffstats
path: root/certService/src/test/java/org/onap/oom/certservice/api/CertificationControllerTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'certService/src/test/java/org/onap/oom/certservice/api/CertificationControllerTest.java')
-rw-r--r--certService/src/test/java/org/onap/oom/certservice/api/CertificationControllerTest.java41
1 files changed, 35 insertions, 6 deletions
diff --git a/certService/src/test/java/org/onap/oom/certservice/api/CertificationControllerTest.java b/certService/src/test/java/org/onap/oom/certservice/api/CertificationControllerTest.java
index abd950e8..0bf37901 100644
--- a/certService/src/test/java/org/onap/oom/certservice/api/CertificationControllerTest.java
+++ b/certService/src/test/java/org/onap/oom/certservice/api/CertificationControllerTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* PROJECT
* ================================================================================
- * Copyright (C) 2020 Nokia. All rights reserved.
+ * Copyright (C) 2020-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.
@@ -32,8 +32,8 @@ 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.oom.certservice.certification.model.CertificateUpdateModel;
import org.onap.oom.certservice.certification.CertificationModelFactory;
-import org.onap.oom.certservice.certification.exception.Cmpv2ClientAdapterException;
import org.onap.oom.certservice.certification.exception.Cmpv2ServerNotFoundException;
import org.onap.oom.certservice.certification.exception.CsrDecryptionException;
import org.onap.oom.certservice.certification.exception.DecryptionException;
@@ -52,6 +52,8 @@ class CertificationControllerTest {
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 static final String TEST_ENCODED_OLD_PK = "encodedOldPK";
+ private static final String TEST_ENCODED_OLD_CERT = "encodedOldCert";
private CertificationController certificationController;
@@ -65,7 +67,7 @@ class CertificationControllerTest {
@Test
void shouldReturnDataAboutCsrBaseOnEncodedParameters()
- throws DecryptionException, CmpClientException, Cmpv2ClientAdapterException {
+ throws DecryptionException, CmpClientException {
// Given
CertificationModel testCertificationModel = new CertificationModel(
Arrays.asList("ENTITY_CERT", "INTERMEDIATE_CERT"),
@@ -87,7 +89,7 @@ class CertificationControllerTest {
@Test
void shouldThrowCsrDecryptionExceptionWhenCreatingCsrModelFails()
- throws DecryptionException, CmpClientException, Cmpv2ClientAdapterException {
+ throws DecryptionException, CmpClientException {
// Given
String expectedMessage = "Incorrect CSR, decryption failed";
when(certificationModelFactory.createCertificationModel(TEST_WRONG_ENCODED_CSR, TEST_ENCODED_PK, TEST_CA_NAME))
@@ -107,7 +109,7 @@ class CertificationControllerTest {
@Test
void shouldThrowPemDecryptionExceptionWhenCreatingPemModelFails()
- throws DecryptionException, CmpClientException, Cmpv2ClientAdapterException {
+ throws DecryptionException, CmpClientException {
// Given
String expectedMessage = "Incorrect PEM, decryption failed";
when(certificationModelFactory.createCertificationModel(TEST_ENCODED_CSR, TEST_WRONG_ENCODED_PK, TEST_CA_NAME))
@@ -127,7 +129,7 @@ class CertificationControllerTest {
@Test
void shouldThrowCmpv2ServerNotFoundWhenGivenWrongCaName()
- throws DecryptionException, CmpClientException, Cmpv2ClientAdapterException {
+ throws DecryptionException, CmpClientException {
// Given
String expectedMessage = "No server found for given CA name";
when(certificationModelFactory.createCertificationModel(TEST_ENCODED_CSR, TEST_ENCODED_PK, TEST_WRONG_CA_NAME))
@@ -144,4 +146,31 @@ class CertificationControllerTest {
// Then
assertEquals(expectedMessage, actualMessage);
}
+
+ @Test
+ void shouldUpdateEndpointReturnDataAboutCsrBaseOnEncodedParameters() {
+ // Given
+ CertificationModel testCertificationModel = new CertificationModel(
+ Arrays.asList("ENTITY_CERT", "INTERMEDIATE_CERT"),
+ Arrays.asList("CA_CERT", "EXTRA_CA_CERT")
+ );
+ CertificateUpdateModel certificateUpdateModel = new CertificateUpdateModel.CertificateUpdateModelBuilder()
+ .setEncodedCsr(TEST_ENCODED_CSR)
+ .setEncodedPrivateKey(TEST_ENCODED_PK)
+ .setEncodedOldCert(TEST_ENCODED_OLD_CERT)
+ .setEncodedOldPrivateKey(TEST_ENCODED_OLD_PK)
+ .setCaName(TEST_CA_NAME)
+ .build();
+ when(certificationModelFactory.createCertificationModel(certificateUpdateModel)).thenReturn(testCertificationModel);
+
+ // When
+ ResponseEntity<CertificationModel> responseCertificationModel =
+ certificationController.updateCertificate(TEST_CA_NAME, TEST_ENCODED_CSR,
+ TEST_ENCODED_PK, TEST_ENCODED_OLD_CERT, TEST_ENCODED_OLD_PK);
+
+ // Then
+ assertEquals(HttpStatus.OK, responseCertificationModel.getStatusCode());
+ assertThat(responseCertificationModel.getBody()).isEqualToComparingFieldByField(testCertificationModel);
+ }
+
}