+
+ @Test
+ void shouldUpdateEndpointReturnDataAboutCsrBaseOnEncodedParameters()
+ throws DecryptionException, CertificateDecryptionException {
+ // Given
+ CertificationModel testCertificationModel = new CertificationModel(
+ Arrays.asList("ENTITY_CERT", "INTERMEDIATE_CERT"),
+ Arrays.asList("CA_CERT", "EXTRA_CA_CERT")
+ );
+ when(certificationModelFactory.createCertificationModel(TEST_CERTIFICATE_UPDATE_MODEL)).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);
+ }
+
+ @Test
+ void shouldThrowCertificateDecryptionExceptionWhenCreatingPemModelFails()
+ throws DecryptionException, CertificateDecryptionException {
+ // Given
+ String expectedMessage = "Incorrect certificate, decryption failed";
+ when(certificationModelFactory.createCertificationModel(TEST_CERTIFICATE_UPDATE_MODEL))
+ .thenThrow(new CertificateDecryptionException(expectedMessage));
+
+ // When
+ Exception exception = assertThrows(
+ CertificateDecryptionException.class, () ->
+ certificationController.updateCertificate(TEST_CA_NAME, TEST_ENCODED_CSR,
+ TEST_ENCODED_PK, TEST_ENCODED_OLD_CERT, TEST_ENCODED_OLD_PK)
+ );
+
+ String actualMessage = exception.getMessage();
+
+ // Then
+ assertEquals(expectedMessage, actualMessage);
+ }
+