diff options
Diffstat (limited to 'certServiceClient/src/test')
-rw-r--r-- | certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java | 39 | ||||
-rw-r--r-- | certServiceClient/src/test/java/org/onap/aaf/certservice/client/DummyExitableException.java | 35 | ||||
-rw-r--r-- | certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/KeyPairFactoryTest.java | 52 | ||||
-rw-r--r-- | certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java (renamed from certServiceClient/src/test/java/org/onap/aaf/certservice/client/model/ClientConfigurationFactoryTest.java) | 12 | ||||
-rw-r--r-- | certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/CsrConfigurationFactoryTest.java (renamed from certServiceClient/src/test/java/org/onap/aaf/certservice/client/model/CsrConfigurationFactoryTest.java) | 11 |
5 files changed, 129 insertions, 20 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 diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/DummyExitableException.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/DummyExitableException.java new file mode 100644 index 00000000..80a2f723 --- /dev/null +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/DummyExitableException.java @@ -0,0 +1,35 @@ +/*============LICENSE_START======================================================= + * aaf-certservice-client + * ================================================================================ + * Copyright (C) 2020 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.aaf.certservice.client; + +import org.onap.aaf.certservice.client.api.ExitableException; + +class DummyExitableException extends ExitableException { + private static final int EXIT_CODE = 888; + + DummyExitableException() { + super("This is Test Exitable Exception"); + } + + @Override + public int applicationExitCode() { + return EXIT_CODE; + } + +} 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 new file mode 100644 index 00000000..b92660fa --- /dev/null +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/KeyPairFactoryTest.java @@ -0,0 +1,52 @@ +/*============LICENSE_START======================================================= + * aaf-certservice-client + * ================================================================================ + * Copyright (C) 2020 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.aaf.certservice.client.certification; + +import org.junit.jupiter.api.Test; +import org.onap.aaf.certservice.client.certification.exception.KeyPairGenerationException; + +import java.security.KeyPair; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +class KeyPairFactoryTest { + private static final String NOT_EXISTING_ENCRYPTION_ALGORITHM = "FAKE_ALGORITHM"; + + @Test + public void shouldProvideKeyPair_whenCreateKeyPairCalledWithCorrectArguments() { + // given + KeyPairFactory keyPairFactory = new KeyPairFactory(EncryptionAlgorithmConstants.RSA_ENCRYPTION_ALGORITHM, + EncryptionAlgorithmConstants.KEY_SIZE); + // when + KeyPair keyPair = keyPairFactory.create(); + // then + assertThat(keyPair).isInstanceOf(KeyPair.class); + } + + @Test + public void shouldThrowKeyPairGenerationException_whenCreateTryCalledOnNotExistingAlgorithm() { + // given + KeyPairFactory keyPairFactory = new KeyPairFactory(NOT_EXISTING_ENCRYPTION_ALGORITHM, + EncryptionAlgorithmConstants.KEY_SIZE); + // when, then + assertThatThrownBy(() -> keyPairFactory.create()).isInstanceOf(KeyPairGenerationException.class); + } + +}
\ No newline at end of file diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/model/ClientConfigurationFactoryTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java index e21f2510..7cf9e0ce 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/model/ClientConfigurationFactoryTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/ClientConfigurationFactoryTest.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * PROJECT + * aaf-certservice-client * ================================================================================ * Copyright (C) 2020 Nokia. All rights reserved. * ================================================================================ @@ -18,12 +18,13 @@ * ============LICENSE_END========================================================= */ -package org.onap.aaf.certservice.client.model; +package org.onap.aaf.certservice.client.configuration.model; import org.junit.jupiter.api.Test; -import org.onap.aaf.certservice.client.common.ClientConfigurationEnvs; -import org.onap.aaf.certservice.client.common.EnvsForClient; -import org.onap.aaf.certservice.client.exceptions.ClientConfigurationException; +import org.onap.aaf.certservice.client.configuration.ClientConfigurationEnvs; +import org.onap.aaf.certservice.client.configuration.EnvsForClient; +import org.onap.aaf.certservice.client.configuration.exception.ClientConfigurationException; +import org.onap.aaf.certservice.client.configuration.factory.ClientConfigurationFactory; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -41,7 +42,6 @@ public class ClientConfigurationFactoryTest { private EnvsForClient envsForClient = mock(EnvsForClient.class); - @Test void create_shouldReturnSuccessWhenAllVariablesAreSetAndValid() { // given diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/model/CsrConfigurationFactoryTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/CsrConfigurationFactoryTest.java index 39d44592..4a4eb247 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/model/CsrConfigurationFactoryTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/CsrConfigurationFactoryTest.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * PROJECT + * aaf-certservice-client * ================================================================================ * Copyright (C) 2020 Nokia. All rights reserved. * ================================================================================ @@ -18,12 +18,13 @@ * ============LICENSE_END========================================================= */ -package org.onap.aaf.certservice.client.model; +package org.onap.aaf.certservice.client.configuration.model; import org.junit.jupiter.api.Test; -import org.onap.aaf.certservice.client.common.CsrConfigurationEnvs; -import org.onap.aaf.certservice.client.common.EnvsForCsr; -import org.onap.aaf.certservice.client.exceptions.CsrConfigurationException; +import org.onap.aaf.certservice.client.configuration.CsrConfigurationEnvs; +import org.onap.aaf.certservice.client.configuration.EnvsForCsr; +import org.onap.aaf.certservice.client.configuration.exception.CsrConfigurationException; +import org.onap.aaf.certservice.client.configuration.factory.CsrConfigurationFactory; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |