[OOM-CERT-SERVICE] Code refactor
[oom/platform/cert-service.git] / certService / src / test / java / org / onap / oom / certservice / api / CertificationControllerTest.java
index 4ac0b50..81c2d39 100644 (file)
@@ -34,13 +34,13 @@ import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.onap.oom.certservice.certification.exception.CertificateDecryptionException;
 import org.onap.oom.certservice.certification.model.CertificateUpdateModel;
-import org.onap.oom.certservice.certification.CertificationModelFactory;
+import org.onap.oom.certservice.certification.CertificationResponseModelFactory;
 import org.onap.oom.certservice.certification.exception.Cmpv2ServerNotFoundException;
 import org.onap.oom.certservice.certification.exception.CsrDecryptionException;
 import org.onap.oom.certservice.certification.exception.DecryptionException;
 import org.onap.oom.certservice.certification.exception.KeyDecryptionException;
 import org.onap.oom.certservice.certification.model.CertificateUpdateModel.CertificateUpdateModelBuilder;
-import org.onap.oom.certservice.certification.model.CertificationModel;
+import org.onap.oom.certservice.certification.model.CertificationResponseModel;
 import org.onap.oom.certservice.cmpv2client.exceptions.CmpClientException;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
@@ -67,32 +67,33 @@ class CertificationControllerTest {
     private CertificationController certificationController;
 
     @Mock
-    private CertificationModelFactory certificationModelFactory;
+    private CertificationResponseModelFactory certificationResponseModelFactory;
 
     @BeforeEach
     void serUp() {
-        certificationController = new CertificationController(certificationModelFactory);
+        certificationController = new CertificationController(certificationResponseModelFactory);
     }
 
     @Test
     void shouldReturnDataAboutCsrBaseOnEncodedParameters()
             throws DecryptionException, CmpClientException {
         // Given
-        CertificationModel testCertificationModel = new CertificationModel(
+        CertificationResponseModel testCertificationResponseModel = new CertificationResponseModel(
                 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(certificationResponseModelFactory
+            .provideCertificationModelFromInitialRequest(TEST_ENCODED_CSR, TEST_ENCODED_PK, TEST_CA_NAME))
+                .thenReturn(testCertificationResponseModel);
 
         // When
-        ResponseEntity<CertificationModel> responseCertificationModel =
+        ResponseEntity<CertificationResponseModel> responseCertificationModel =
                 certificationController.signCertificate(TEST_CA_NAME, TEST_ENCODED_CSR, TEST_ENCODED_PK);
 
         // Then
         assertEquals(HttpStatus.OK, responseCertificationModel.getStatusCode());
         assertThat(responseCertificationModel.getBody()
-        ).isEqualToComparingFieldByField(testCertificationModel);
+        ).isEqualToComparingFieldByField(testCertificationResponseModel);
 
     }
 
@@ -101,7 +102,8 @@ class CertificationControllerTest {
             throws DecryptionException, CmpClientException {
         // Given
         String expectedMessage = "Incorrect CSR, decryption failed";
-        when(certificationModelFactory.createCertificationModel(TEST_WRONG_ENCODED_CSR, TEST_ENCODED_PK, TEST_CA_NAME))
+        when(certificationResponseModelFactory
+            .provideCertificationModelFromInitialRequest(TEST_WRONG_ENCODED_CSR, TEST_ENCODED_PK, TEST_CA_NAME))
                 .thenThrow(new CsrDecryptionException(expectedMessage));
 
         // When
@@ -121,7 +123,8 @@ class CertificationControllerTest {
             throws DecryptionException, CmpClientException {
         // Given
         String expectedMessage = "Incorrect PEM, decryption failed";
-        when(certificationModelFactory.createCertificationModel(TEST_ENCODED_CSR, TEST_WRONG_ENCODED_PK, TEST_CA_NAME))
+        when(certificationResponseModelFactory
+            .provideCertificationModelFromInitialRequest(TEST_ENCODED_CSR, TEST_WRONG_ENCODED_PK, TEST_CA_NAME))
                 .thenThrow(new KeyDecryptionException(expectedMessage));
 
         // When
@@ -141,7 +144,8 @@ class CertificationControllerTest {
             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))
+        when(certificationResponseModelFactory
+            .provideCertificationModelFromInitialRequest(TEST_ENCODED_CSR, TEST_ENCODED_PK, TEST_WRONG_CA_NAME))
                 .thenThrow(new Cmpv2ServerNotFoundException(expectedMessage));
 
         // When
@@ -160,20 +164,21 @@ class CertificationControllerTest {
     void shouldUpdateEndpointReturnDataAboutCsrBaseOnEncodedParameters()
         throws DecryptionException, CmpClientException, CertificateDecryptionException {
         // Given
-        CertificationModel testCertificationModel = new CertificationModel(
+        CertificationResponseModel testCertificationResponseModel = new CertificationResponseModel(
                 Arrays.asList("ENTITY_CERT", "INTERMEDIATE_CERT"),
                 Arrays.asList("CA_CERT", "EXTRA_CA_CERT")
         );
-        when(certificationModelFactory.createCertificationModel(TEST_CERTIFICATE_UPDATE_MODEL)).thenReturn(testCertificationModel);
+        when(certificationResponseModelFactory.provideCertificationModelFromUpdateRequest(TEST_CERTIFICATE_UPDATE_MODEL)).thenReturn(
+            testCertificationResponseModel);
 
         // When
-        ResponseEntity<CertificationModel> responseCertificationModel =
+        ResponseEntity<CertificationResponseModel> 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);
+        assertThat(responseCertificationModel.getBody()).isEqualToComparingFieldByField(testCertificationResponseModel);
     }
 
     @Test
@@ -181,7 +186,7 @@ class CertificationControllerTest {
         throws DecryptionException, CertificateDecryptionException, CmpClientException {
         // Given
         String expectedMessage = "Incorrect certificate, decryption failed";
-        when(certificationModelFactory.createCertificationModel(TEST_CERTIFICATE_UPDATE_MODEL))
+        when(certificationResponseModelFactory.provideCertificationModelFromUpdateRequest(TEST_CERTIFICATE_UPDATE_MODEL))
             .thenThrow(new CertificateDecryptionException(expectedMessage));
 
         // When