diff options
Diffstat (limited to 'certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java')
-rw-r--r-- | certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java index 12c2db06..22baab50 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java @@ -16,33 +16,54 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.onap.aaf.certservice.client; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.aaf.certservice.client.certification.KeyPairFactory; + +import java.security.KeyPair; +import java.util.Optional; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.onap.aaf.certservice.client.certification.EncryptionAlgorithmConstants.KEY_SIZE; +import static org.onap.aaf.certservice.client.certification.EncryptionAlgorithmConstants.RSA_ENCRYPTION_ALGORITHM; @ExtendWith(MockitoExtension.class) class CertServiceClientTest { + private static final int DUMMY_EXIT_CODE = 888; @Spy - CertServiceClient certServiceClient = new CertServiceClient(); + AppExitHandler appExitHandler = new AppExitHandler(); + + @Test + public void shouldExitWithDefinedExitCode_onGenerateKeyPairCallWhereExitableExceptionIsThrown() { + // given + KeyPairFactory keyPairFactory = mock(KeyPairFactory.class); + when(keyPairFactory.create()).thenThrow(new DummyExitableException()); + doNothing().when(appExitHandler).exit(DUMMY_EXIT_CODE); + CertServiceClient certServiceClient = new CertServiceClient(appExitHandler); + // when + Optional<KeyPair> keyPair = certServiceClient.generateKeyPair(keyPairFactory); + // then + verify(appExitHandler).exit(DUMMY_EXIT_CODE); + assertThat(keyPair).isEmpty(); + } - // Sonar check for this test disabled due to lack of assertion in test. - // Intention of this test is to check if app runs without exiting Java. @Test - public void shouldExitWithZero_onApplicationSuccessfulFinish() { //NOSONAR + public void shouldReturnKeyPair_onGenerateKeyPairCall() { // given - String[] params = {""}; - doNothing().when(certServiceClient).exit(0); + KeyPairFactory keyPairFactory = new KeyPairFactory(RSA_ENCRYPTION_ALGORITHM, KEY_SIZE); + CertServiceClient certServiceClient = new CertServiceClient(appExitHandler); // when - certServiceClient.run(params); + Optional<KeyPair> keyPair = certServiceClient.generateKeyPair(keyPairFactory); // then - verify(certServiceClient).exit(0); + assertThat(keyPair).hasValueSatisfying(value -> assertThat(value).isInstanceOf(KeyPair.class)); } }
\ No newline at end of file |