From ffa2b75513bac0ac7aa39bdb6d0b77f751735c5e Mon Sep 17 00:00:00 2001 From: kjaniak Date: Wed, 17 Jun 2020 09:31:08 +0200 Subject: Move ArtifcatsCreationProvider one level higher Code style cleanup (warnings from checkstyle). Issue-ID: AAF-1152 Signed-off-by: kjaniak Change-Id: I0a8bbd998cd6aed4cf818ffe10c7fbffe99e9d22 --- .../certservice/client/CertServiceClientTest.java | 2 + .../ArtifactsCreatorProviderTest.java | 73 ++++++++++++++++++++++ .../client/certification/CsrFactoryTest.java | 3 +- .../client/certification/KeyPairFactoryTest.java | 3 +- .../conversion/ArtifactsCreatorProviderTest.java | 70 --------------------- .../conversion/ConvertedArtifactsCreatorTest.java | 28 ++++----- .../conversion/PemArtifactsCreatorTest.java | 23 +++---- .../certification/conversion/PemConverterTest.java | 53 ++++++++-------- .../conversion/RandomPasswordGeneratorTest.java | 3 +- .../certification/writer/CertFileWriterTest.java | 17 ++--- .../client/configuration/EnvProviderTest.java | 9 +-- .../factory/AbstractConfigurationFactoryTest.java | 1 + .../factory/ClientConfigurationFactoryTest.java | 22 +++---- .../factory/CsrConfigurationFactoryTest.java | 22 +++---- .../client/httpclient/HttpClientTest.java | 8 +-- 15 files changed, 174 insertions(+), 163 deletions(-) create mode 100644 certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/ArtifactsCreatorProviderTest.java delete mode 100644 certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/ArtifactsCreatorProviderTest.java (limited to 'certServiceClient/src/test/java') 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 7e7bf5db..36808941 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,6 +16,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aaf.certservice.client; import org.junit.jupiter.api.Test; @@ -32,6 +33,7 @@ import static org.onap.aaf.certservice.client.api.ExitStatus.SUCCESS; class CertServiceClientTest { @Spy AppExitHandler appExitHandler = new AppExitHandler(); + @Test public void shouldExitWithDefinedExitCode_onRunCallWhenNoEnvsPresent() { // given diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/ArtifactsCreatorProviderTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/ArtifactsCreatorProviderTest.java new file mode 100644 index 00000000..46bacef8 --- /dev/null +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/ArtifactsCreatorProviderTest.java @@ -0,0 +1,73 @@ +/*============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.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; +import org.onap.aaf.certservice.client.certification.conversion.ArtifactsCreator; +import org.onap.aaf.certservice.client.certification.conversion.ConvertedArtifactsCreator; +import org.onap.aaf.certservice.client.certification.conversion.PemArtifactsCreator; + +import static org.assertj.core.api.Assertions.assertThat; + + +class ArtifactsCreatorProviderTest { + + private static final String P12 = "P12"; + private static final String JKS = "JKS"; + private static final String PEM = "PEM"; + private static final String TEST_PATH = "testPath"; + + @ParameterizedTest + @ValueSource(strings = {JKS, P12}) + void artifactsProviderShouldReturnConvertedCreator(String outputType) { + + // when + ArtifactsCreator artifactsCreator = + ArtifactsCreatorProvider.get(outputType, TEST_PATH); + // then + assertThat(artifactsCreator).isInstanceOf(ConvertedArtifactsCreator.class); + } + + @Test + void artifactsProviderShouldReturnPemCreator() { + + // when + ArtifactsCreator artifactsCreator = + ArtifactsCreatorProvider.get(PEM, TEST_PATH); + // then + assertThat(artifactsCreator).isInstanceOf(PemArtifactsCreator.class); + } + + @ParameterizedTest + @CsvSource({ + "JKS, jks", + "P12, p12"}) + void getExtensionShouldProvideExtensionBasedOnArtifactType(String artifactType, String expectedExtension) { + + //when + String actualExtension = ArtifactsCreatorProvider.valueOf(artifactType).getExtension(); + //then + assertThat(actualExtension).isEqualTo(expectedExtension); + } + +} diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/CsrFactoryTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/CsrFactoryTest.java index 809a91f2..e88976bf 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/CsrFactoryTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/CsrFactoryTest.java @@ -37,7 +37,6 @@ public class CsrFactoryTest { CsrConfiguration config = mock(CsrConfiguration.class); - @Test void createEncodedCsr_shouldSucceedWhenAllFieldsAreSetCorrectly() throws KeyPairGenerationException, CsrGenerationException { @@ -53,6 +52,6 @@ public class CsrFactoryTest { when(config.getState()).thenReturn("California"); assertThat(new CsrFactory(config).createCsrInPem(keyPair)).isNotEmpty(); - } + } } 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 6a4741a2..3d3d3c17 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 @@ -16,6 +16,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aaf.certservice.client.certification; import org.junit.jupiter.api.Test; @@ -46,7 +47,7 @@ class KeyPairFactoryTest { KeyPairFactory keyPairFactory = new KeyPairFactory(NOT_EXISTING_ENCRYPTION_ALGORITHM, EncryptionAlgorithmConstants.KEY_SIZE); // when, then - assertThatThrownBy(() -> keyPairFactory.create()).isInstanceOf(KeyPairGenerationException.class); + assertThatThrownBy(keyPairFactory::create).isInstanceOf(KeyPairGenerationException.class); } } \ No newline at end of file diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/ArtifactsCreatorProviderTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/ArtifactsCreatorProviderTest.java deleted file mode 100644 index 8a619991..00000000 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/ArtifactsCreatorProviderTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/*============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.conversion; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; -import org.junit.jupiter.params.provider.ValueSource; - -import static org.assertj.core.api.Assertions.assertThat; - - -class ArtifactsCreatorProviderTest { - - private static final String P12 = "P12"; - private static final String JKS = "JKS"; - private static final String PEM = "PEM"; - private static final String TEST_PATH = "testPath"; - - @ParameterizedTest - @ValueSource(strings = {JKS, P12}) - void artifactsProviderShouldReturnConvertedCreator(String outputType){ - - // when - ArtifactsCreator artifactsCreator = - ArtifactsCreatorProvider.getCreator(outputType, TEST_PATH); - // then - assertThat(artifactsCreator).isInstanceOf(ConvertedArtifactsCreator.class); - } - - @Test - void artifactsProviderShouldReturnPemCreator(){ - - // when - ArtifactsCreator artifactsCreator = - ArtifactsCreatorProvider.getCreator(PEM, TEST_PATH); - // then - assertThat(artifactsCreator).isInstanceOf(PemArtifactsCreator.class); - } - - @ParameterizedTest - @CsvSource({ - "JKS, jks", - "P12, p12"}) - void getExtensionShouldProvideExtensionBasedOnArtifactType(String artifactType, String expectedExtension){ - - //when - String actualExtension = ArtifactsCreatorProvider.valueOf(artifactType).getExtension(); - //then - assertThat(actualExtension).isEqualTo(expectedExtension); - } - -} diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/ConvertedArtifactsCreatorTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/ConvertedArtifactsCreatorTest.java index 2da4ab98..e13f8be8 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/ConvertedArtifactsCreatorTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/ConvertedArtifactsCreatorTest.java @@ -19,20 +19,20 @@ package org.onap.aaf.certservice.client.certification.conversion; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.security.PrivateKey; -import java.util.List; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.onap.aaf.certservice.client.certification.exception.CertFileWriterException; import org.onap.aaf.certservice.client.certification.exception.PemConversionException; import org.onap.aaf.certservice.client.certification.writer.CertFileWriter; +import java.security.PrivateKey; +import java.util.List; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + class ConvertedArtifactsCreatorTest { private static final int PASSWORD_LENGTH = 24; @@ -44,7 +44,7 @@ class ConvertedArtifactsCreatorTest { private static final List SAMPLE_TRUSTED_CERTIFICATE_CHAIN = List.of("c", "d"); private static final byte[] SAMPLE_KEYSTORE_BYTES = "this is a keystore test".getBytes(); private static final byte[] SAMPLE_TRUSTSTORE_BYTES = "this is a truststore test".getBytes(); - private static final String P12_EXTENSION= "p12"; + private static final String P12_EXTENSION = "p12"; private CertFileWriter certFileWriter; private RandomPasswordGenerator passwordGenerator; @@ -64,7 +64,7 @@ class ConvertedArtifactsCreatorTest { @Test void convertedArtifactCreatorShouldTryCreateFileWithGivenExtension() - throws CertFileWriterException, PemConversionException { + throws CertFileWriterException, PemConversionException { //given mockPasswordGeneratorAndPemConverter(); final String keystore = "keystore"; @@ -82,7 +82,7 @@ class ConvertedArtifactsCreatorTest { @Test void convertedArtifactsCreatorShouldCallConverterAndFilesCreatorMethods() - throws PemConversionException, CertFileWriterException { + throws PemConversionException, CertFileWriterException { // given mockPasswordGeneratorAndPemConverter(); final String keystoreP12 = "keystore.p12"; @@ -95,16 +95,16 @@ class ConvertedArtifactsCreatorTest { verify(converter, times(1)) .convertKeystore(SAMPLE_KEYSTORE_CERTIFICATE_CHAIN, SAMPLE_PASSWORD, CERTIFICATE_ALIAS, privateKey); verify(certFileWriter, times(1)) - .saveData(SAMPLE_KEYSTORE_BYTES, keystoreP12); + .saveData(SAMPLE_KEYSTORE_BYTES, keystoreP12); verify(certFileWriter, times(1)) - .saveData(SAMPLE_PASSWORD.getCurrentPassword().getBytes(), keystorePass); + .saveData(SAMPLE_PASSWORD.getCurrentPassword().getBytes(), keystorePass); verify(converter, times(1)) .convertTruststore(SAMPLE_TRUSTED_CERTIFICATE_CHAIN, SAMPLE_PASSWORD, TRUSTED_CERTIFICATE_ALIAS); } @Test void convertedArtifactsCreatorShouldCallPasswordGeneratorTwice() - throws PemConversionException, CertFileWriterException { + throws PemConversionException, CertFileWriterException { // given mockPasswordGeneratorAndPemConverter(); diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/PemArtifactsCreatorTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/PemArtifactsCreatorTest.java index 9963d245..5e79b96f 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/PemArtifactsCreatorTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/PemArtifactsCreatorTest.java @@ -19,23 +19,24 @@ package org.onap.aaf.certservice.client.certification.conversion; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.security.PrivateKey; -import java.util.List; import org.junit.jupiter.api.Test; import org.onap.aaf.certservice.client.api.ExitableException; import org.onap.aaf.certservice.client.certification.PrivateKeyToPemEncoder; import org.onap.aaf.certservice.client.certification.writer.CertFileWriter; +import java.security.PrivateKey; +import java.util.List; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + class PemArtifactsCreatorTest { - private final String KEYSTORE_PEM = "keystore.pem"; - private final String TRUSTSTORE_PEM = "truststore.pem"; - private final String KEY_PEM = "key.pem"; - private final String KEY = "my private key"; + private static final String KEYSTORE_PEM = "keystore.pem"; + private static final String TRUSTSTORE_PEM = "truststore.pem"; + private static final String KEY_PEM = "key.pem"; + private static final String KEY = "my private key"; private CertFileWriter certFileWriter = mock(CertFileWriter.class); private PrivateKey privateKey = mock(PrivateKey.class); private PrivateKeyToPemEncoder pkEncoder = mock(PrivateKeyToPemEncoder.class); diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/PemConverterTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/PemConverterTest.java index 0d67fba7..e3a58c3f 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/PemConverterTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/PemConverterTest.java @@ -19,13 +19,12 @@ package org.onap.aaf.certservice.client.certification.conversion; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.onap.aaf.certservice.client.certification.EncryptionAlgorithmConstants; +import org.onap.aaf.certservice.client.certification.exception.PemConversionException; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -40,12 +39,14 @@ import java.security.UnrecoverableKeyException; import java.security.cert.Certificate; import java.security.cert.CertificateException; import java.util.List; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import org.onap.aaf.certservice.client.certification.EncryptionAlgorithmConstants; -import org.onap.aaf.certservice.client.certification.exception.PemConversionException; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; class PemConverterTest { @@ -72,7 +73,7 @@ class PemConverterTest { @ParameterizedTest @ValueSource(strings = {PKCS12, JKS}) void convertKeystoreShouldReturnKeystoreWithGivenPrivateKeyAndCertificateChain(String conversionTarget) - throws IOException, CertificateException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, PemConversionException { + throws IOException, CertificateException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, PemConversionException { // given final String alias = "keystore-entry"; final Password password = new Password("d9D_u8LooYaXH4G48DtN#vw0"); @@ -80,7 +81,7 @@ class PemConverterTest { final PemConverter converter = new PemConverter(conversionTarget); final KeyStore expectedKeyStore = KeyStore.getInstance(conversionTarget); expectedKeyStore.load(new ByteArrayInputStream(Files.readAllBytes(Path.of(EXPECTED_KEYSTORE_PATH))), - password.toCharArray()); + password.toCharArray()); final Certificate[] expectedChain = expectedKeyStore.getCertificateChain(alias); privateKeyMockSetup(); @@ -109,7 +110,7 @@ class PemConverterTest { // when Exception exception = assertThrows(PemConversionException.class, () -> - converter.convertKeystore(certificateChain, password, alias, privateKey) + converter.convertKeystore(certificateChain, password, alias, privateKey) ); // then @@ -119,7 +120,7 @@ class PemConverterTest { @ParameterizedTest @ValueSource(strings = {PKCS12, JKS}) void convertTruststoreShouldReturnTruststoreWithGivenCertificatesArray(String conversionTarget) - throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException, PemConversionException { + throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException, PemConversionException { // given final PemConverter converter = new PemConverter(conversionTarget); @@ -130,7 +131,7 @@ class PemConverterTest { final List trustedCertificates = getCertificates(); final KeyStore expectedTrustStore = KeyStore.getInstance(conversionTarget); expectedTrustStore.load(new ByteArrayInputStream(Files.readAllBytes(Path.of(EXPECTED_TRUSTSTORE_PATH))), - password.toCharArray()); + password.toCharArray()); // when final byte[] result = converter.convertTruststore(trustedCertificates, password, alias); @@ -156,8 +157,8 @@ class PemConverterTest { // when then assertThatThrownBy(() -> - converter.convertTruststore(trustedCertificates, password, alias)) - .isInstanceOf(PemConversionException.class).hasMessage(PASSWORD_ERROR_MSG); + converter.convertTruststore(trustedCertificates, password, alias)) + .isInstanceOf(PemConversionException.class).hasMessage(PASSWORD_ERROR_MSG); } @Test @@ -170,7 +171,7 @@ class PemConverterTest { // when then assertThatThrownBy(() -> converter.convertKeystore(certificateChain, password, alias, privateKey)) - .isInstanceOf(PemConversionException.class).hasMessage(KEY_ERROR_MSG); + .isInstanceOf(PemConversionException.class).hasMessage(KEY_ERROR_MSG); } @ParameterizedTest @@ -185,7 +186,7 @@ class PemConverterTest { // when then assertThatThrownBy(() -> converter.convertKeystore(certificateChain, password, alias, privateKey)) - .isInstanceOf(PemConversionException.class).hasMessage(CERTIFICATES_ERROR_MSG); + .isInstanceOf(PemConversionException.class).hasMessage(CERTIFICATES_ERROR_MSG); } private void privateKeyMockSetup() { @@ -196,10 +197,10 @@ class PemConverterTest { private List getCertificates() throws IOException { return List.of( - Files.readString( - Path.of(CERT1_PATH), StandardCharsets.UTF_8), - Files.readString( - Path.of(CERT2_PATH), StandardCharsets.UTF_8) + Files.readString( + Path.of(CERT1_PATH), StandardCharsets.UTF_8), + Files.readString( + Path.of(CERT2_PATH), StandardCharsets.UTF_8) ); } } diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/RandomPasswordGeneratorTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/RandomPasswordGeneratorTest.java index 169ce98a..483e35e0 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/RandomPasswordGeneratorTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/RandomPasswordGeneratorTest.java @@ -19,9 +19,10 @@ package org.onap.aaf.certservice.client.certification.conversion; -import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertTrue; + class RandomPasswordGeneratorTest { @Test diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriterTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriterTest.java index 443f5627..e7ebb32b 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriterTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriterTest.java @@ -19,18 +19,19 @@ package org.onap.aaf.certservice.client.certification.writer; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onap.aaf.certservice.client.certification.exception.CertFileWriterException; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.onap.aaf.certservice.client.certification.exception.CertFileWriterException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; class CertFileWriterTest { @@ -54,7 +55,7 @@ class CertFileWriterTest { @Test void certFileWriterShouldCreateFilesWithDataInGivenLocation() - throws IOException, CertFileWriterException { + throws IOException, CertFileWriterException { // given final byte[] data = new byte[]{-128, 1, 2, 3, 127}; File truststore = new File(OUTPUT_PATH + TRUSTSTORE_P12); @@ -76,6 +77,6 @@ class CertFileWriterTest { // when then assertThatThrownBy(() -> certFileWriter.saveData(data, TRUSTSTORE_P12)) - .isInstanceOf(CertFileWriterException.class).hasMessage(ERROR_MESSAGE); + .isInstanceOf(CertFileWriterException.class).hasMessage(ERROR_MESSAGE); } } diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvProviderTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvProviderTest.java index 7ef921a1..af6b2d9f 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvProviderTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvProviderTest.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aaf.certservice.client.configuration; import org.junit.jupiter.api.BeforeEach; @@ -35,12 +36,12 @@ class EnvProviderTest { private EnvProvider envProvider; @BeforeEach - public void setUp(){ - envProvider = Mockito.spy(EnvProvider.class); + public void setUp() { + envProvider = Mockito.spy(EnvProvider.class); } @Test - public void shouldReturnSystemEnvVariableWhenItWasDefined(){ + public void shouldReturnSystemEnvVariableWhenItWasDefined() { // given when(envProvider.getSystemEnv(TEST_ENV)).thenReturn(TEST_ENV_VALUE); @@ -53,7 +54,7 @@ class EnvProviderTest { } @Test - public void shouldReportThatSystemEnvVariableIsNotPresentWhenItWasNotDefined(){ + public void shouldReportThatSystemEnvVariableIsNotPresentWhenItWasNotDefined() { // when final Optional testEnv = envProvider.readEnvVariable(TEST_ENV); diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactoryTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactoryTest.java index 6273e2a6..9c0b9d8f 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactoryTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactoryTest.java @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aaf.certservice.client.configuration.factory; import org.junit.jupiter.params.ParameterizedTest; diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/ClientConfigurationFactoryTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/ClientConfigurationFactoryTest.java index 7239b21a..20a6c7ef 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/ClientConfigurationFactoryTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/ClientConfigurationFactoryTest.java @@ -35,16 +35,16 @@ import static org.mockito.Mockito.when; public class ClientConfigurationFactoryTest { - private final String CA_NAME_VALID = "caaaftest2"; - private final String TIME_OUT_VALID = "30000"; - private final String OUTPUT_PATH_VALID = "/opt/app/osaaf"; - private final String URL_TO_CERT_SERVICE_VALID = "https://cert-service:8443/v1/certificate/"; - private final String URL_TO_CERT_SERVICE_DEFAULT = "https://aaf-cert-service:8443/v1/certificate/"; - private final String CA_NAME_INVALID = "caaaftest2#$"; - private final String OUTPUT_PATH_INVALID = "/opt//app/osaaf"; - private final String OUTPUT_TYPE_VALID = "JKS"; - private final String OUTPUT_TYPE_INVALID = "JKSS"; - private final String OUTPUT_TYPE_DEFAULT = "P12"; + private static final String CA_NAME_VALID = "caaaftest2"; + private static final String TIME_OUT_VALID = "30000"; + private static final String OUTPUT_PATH_VALID = "/opt/app/osaaf"; + private static final String URL_TO_CERT_SERVICE_VALID = "https://cert-service:8443/v1/certificate/"; + private static final String URL_TO_CERT_SERVICE_DEFAULT = "https://aaf-cert-service:8443/v1/certificate/"; + private static final String CA_NAME_INVALID = "caaaftest2#$"; + private static final String OUTPUT_PATH_INVALID = "/opt//app/osaaf"; + private static final String OUTPUT_TYPE_VALID = "JKS"; + private static final String OUTPUT_TYPE_INVALID = "JKSS"; + private static final String OUTPUT_TYPE_DEFAULT = "P12"; private EnvsForClient envsForClient = mock(EnvsForClient.class); @@ -102,7 +102,7 @@ public class ClientConfigurationFactoryTest { } @Test - void create_shouldReturnClientExceptionWhenCANameContainsSpecialCharacters() { + void create_shouldReturnClientExceptionWhenCaNameContainsSpecialCharacters() { // given when(envsForClient.getCaName()).thenReturn(Optional.of(CA_NAME_INVALID)); when(envsForClient.getOutputPath()).thenReturn(Optional.of(OUTPUT_PATH_VALID)); diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/CsrConfigurationFactoryTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/CsrConfigurationFactoryTest.java index 2edff2f1..5abd0b13 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/CsrConfigurationFactoryTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/CsrConfigurationFactoryTest.java @@ -38,20 +38,20 @@ import static org.onap.aaf.certservice.client.api.ExitStatus.CSR_CONFIGURATION_E public class CsrConfigurationFactoryTest { - private final String COMMON_NAME_VALID = "onap.org"; - private final String SANS_VALID = "test-name"; - private final String COUNTRY_VALID = "US"; - private final String LOCATION_VALID = "San-Francisco"; - private final String ORGANIZATION_VALID = "Linux-Foundation"; - private final String ORGANIZATION_UNIT_VALID = "ONAP"; - private final String STATE_VALID = "California"; - private final String COMMON_NAME_INVALID = "onap.org*&"; - private final String COUNTRY_INVALID = "PLA"; - private final String ORGANIZATION_INVALID = "Linux?Foundation"; + private static final String COMMON_NAME_VALID = "onap.org"; + private static final String SANS_VALID = "test-name"; + private static final String COUNTRY_VALID = "US"; + private static final String LOCATION_VALID = "San-Francisco"; + private static final String ORGANIZATION_VALID = "Linux-Foundation"; + private static final String ORGANIZATION_UNIT_VALID = "ONAP"; + private static final String STATE_VALID = "California"; + private static final String COMMON_NAME_INVALID = "onap.org*&"; + private static final String COUNTRY_INVALID = "PLA"; + private static final String ORGANIZATION_INVALID = "Linux?Foundation"; private EnvsForCsr envsForCsr = mock(EnvsForCsr.class); private CsrConfigurationFactory testedFactory; - private Condition expectedExitCodeCondition = new Condition<>("Correct exit code"){ + private Condition expectedExitCodeCondition = new Condition<>("Correct exit code") { @Override public boolean matches(CsrConfigurationException e) { return e.applicationExitStatus() == CSR_CONFIGURATION_EXCEPTION; diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/httpclient/HttpClientTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/httpclient/HttpClientTest.java index 60c2e93d..a109749b 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/httpclient/HttpClientTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/httpclient/HttpClientTest.java @@ -106,18 +106,18 @@ class HttpClientTest { //when //then assertThatExceptionOfType(CertServiceApiResponseException.class) - .isThrownBy(()->httpClient.retrieveCertServiceData(CA_NAME, CSR, "")); + .isThrownBy(() -> httpClient.retrieveCertServiceData(CA_NAME, CSR, "")); } @Test - void shouldThrowHttpClientException_WhenCannotExecuteRequestToAPI() throws Exception { + void shouldThrowHttpClientException_WhenCannotExecuteRequestToApi() throws Exception { //given when(closeableHttpClient.execute(any(HttpGet.class))).thenThrow(IOException.class); //when //then assertThatExceptionOfType(HttpClientException.class) - .isThrownBy(()->httpClient.retrieveCertServiceData(CA_NAME, CSR, "")); + .isThrownBy(() -> httpClient.retrieveCertServiceData(CA_NAME, CSR, "")); } @Test @@ -129,7 +129,7 @@ class HttpClientTest { //when //then assertThatExceptionOfType(HttpClientException.class) - .isThrownBy(()->httpClient.retrieveCertServiceData(CA_NAME, CSR, "")); + .isThrownBy(() -> httpClient.retrieveCertServiceData(CA_NAME, CSR, "")); } private void mockServerResponse(int serverCodeResponse, String stringResponse) -- cgit 1.2.3-korg