diff options
Diffstat (limited to 'certServiceClient/src/test/java/org/onap/aaf')
4 files changed, 13 insertions, 35 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 22baab50..9e733017 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 @@ -22,48 +22,26 @@ 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; +import static org.onap.aaf.certservice.client.api.ExitCode.CLIENT_CONFIGURATION_EXCEPTION; +import static org.onap.aaf.certservice.client.api.ExitCode.SUCCESS_EXIT_CODE; @ExtendWith(MockitoExtension.class) class CertServiceClientTest { - private static final int DUMMY_EXIT_CODE = 888; @Spy 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(); - } - @Test - public void shouldReturnKeyPair_onGenerateKeyPairCall() { + public void shouldExitWithDefinedExitCode_onRunCallWhenNoEnvsPresent() { // given - KeyPairFactory keyPairFactory = new KeyPairFactory(RSA_ENCRYPTION_ALGORITHM, KEY_SIZE); + doNothing().when(appExitHandler).exit(CLIENT_CONFIGURATION_EXCEPTION.getValue()); + doNothing().when(appExitHandler).exit(SUCCESS_EXIT_CODE.getValue()); CertServiceClient certServiceClient = new CertServiceClient(appExitHandler); // when - Optional<KeyPair> keyPair = certServiceClient.generateKeyPair(keyPairFactory); + certServiceClient.run(); // then - assertThat(keyPair).hasValueSatisfying(value -> assertThat(value).isInstanceOf(KeyPair.class)); + verify(appExitHandler).exit(CLIENT_CONFIGURATION_EXCEPTION.getValue()); + verify(appExitHandler).exit(SUCCESS_EXIT_CODE.getValue()); } - }
\ No newline at end of file diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/KeyPairFactoryTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/KeyPairFactoryTest.java index b92660fa..6a4741a2 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/KeyPairFactoryTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/KeyPairFactoryTest.java @@ -30,7 +30,7 @@ class KeyPairFactoryTest { private static final String NOT_EXISTING_ENCRYPTION_ALGORITHM = "FAKE_ALGORITHM"; @Test - public void shouldProvideKeyPair_whenCreateKeyPairCalledWithCorrectArguments() { + public void shouldProvideKeyPair_whenCreateKeyPairCalledWithCorrectArguments() throws KeyPairGenerationException { // given KeyPairFactory keyPairFactory = new KeyPairFactory(EncryptionAlgorithmConstants.RSA_ENCRYPTION_ALGORITHM, EncryptionAlgorithmConstants.KEY_SIZE); diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java index 7cf9e0ce..f355de1a 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java @@ -43,7 +43,7 @@ public class ClientConfigurationFactoryTest { private EnvsForClient envsForClient = mock(EnvsForClient.class); @Test - void create_shouldReturnSuccessWhenAllVariablesAreSetAndValid() { + void create_shouldReturnSuccessWhenAllVariablesAreSetAndValid() throws ClientConfigurationException { // given when(envsForClient.getCaName()).thenReturn(CA_NAME_VALID); when(envsForClient.getOutputPath()).thenReturn(OUTPUT_PATH_VALID); @@ -61,7 +61,7 @@ public class ClientConfigurationFactoryTest { } @Test - void create_shouldReturnSuccessWhenDefaultVariablesAreNotSet() { + void create_shouldReturnSuccessWhenDefaultVariablesAreNotSet() throws ClientConfigurationException { // given when(envsForClient.getCaName()).thenReturn(CA_NAME_VALID); when(envsForClient.getOutputPath()).thenReturn(OUTPUT_PATH_VALID); diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/CsrConfigurationFactoryTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/CsrConfigurationFactoryTest.java index 4a4eb247..d6bf431b 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/CsrConfigurationFactoryTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/CsrConfigurationFactoryTest.java @@ -46,7 +46,7 @@ public class CsrConfigurationFactoryTest { @Test - void create_shouldReturnSuccessWhenAllVariablesAreSetAndValid() { + void create_shouldReturnSuccessWhenAllVariablesAreSetAndValid() throws CsrConfigurationException { // given when(envsForCsr.getCommonName()).thenReturn(COMMON_NAME_VALID); when(envsForCsr.getSubjectAlternativesName()).thenReturn(SANS_VALID); @@ -70,7 +70,7 @@ public class CsrConfigurationFactoryTest { } @Test - void create_shouldReturnSuccessWhenNotRequiredVariablesAreNotSet() { + void create_shouldReturnSuccessWhenNotRequiredVariablesAreNotSet() throws CsrConfigurationException { // given when(envsForCsr.getCommonName()).thenReturn(COMMON_NAME_VALID); when(envsForCsr.getState()).thenReturn(STATE_VALID); |