diff options
Diffstat (limited to 'certServiceClient/src/test')
-rw-r--r-- | certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java | 21 | ||||
-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) | 16 | ||||
-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) | 15 |
5 files changed, 113 insertions, 26 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..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 @@ -16,7 +16,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.onap.aaf.certservice.client; import org.junit.jupiter.api.Test; @@ -26,23 +25,23 @@ import org.mockito.junit.jupiter.MockitoExtension; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.verify; +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 { @Spy - CertServiceClient certServiceClient = new CertServiceClient(); - - // 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. + AppExitHandler appExitHandler = new AppExitHandler(); @Test - public void shouldExitWithZero_onApplicationSuccessfulFinish() { //NOSONAR + public void shouldExitWithDefinedExitCode_onRunCallWhenNoEnvsPresent() { // given - String[] params = {""}; - doNothing().when(certServiceClient).exit(0); + doNothing().when(appExitHandler).exit(CLIENT_CONFIGURATION_EXCEPTION.getValue()); + doNothing().when(appExitHandler).exit(SUCCESS_EXIT_CODE.getValue()); + CertServiceClient certServiceClient = new CertServiceClient(appExitHandler); // when - certServiceClient.run(params); + certServiceClient.run(); // then - verify(certServiceClient).exit(0); + 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/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..6a4741a2 --- /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() throws KeyPairGenerationException { + // 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..f355de1a 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,9 +42,8 @@ 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/model/CsrConfigurationFactoryTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/model/CsrConfigurationFactoryTest.java index 39d44592..d6bf431b 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; @@ -45,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); @@ -69,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); |