Move ArtifcatsCreationProvider one level higher
authorkjaniak <kornel.janiak@nokia.com>
Wed, 17 Jun 2020 07:31:08 +0000 (09:31 +0200)
committerkjaniak <kornel.janiak@nokia.com>
Tue, 23 Jun 2020 14:11:57 +0000 (16:11 +0200)
Code style cleanup (warnings from checkstyle).

Issue-ID: AAF-1152
Signed-off-by: kjaniak <kornel.janiak@nokia.com>
Change-Id: I0a8bbd998cd6aed4cf818ffe10c7fbffe99e9d22

45 files changed:
certServiceClient/pom.xml
certServiceClient/src/main/java/org/onap/aaf/certservice/client/AppExitHandler.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/CertServiceClient.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitStatus.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitableException.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/ArtifactsCreatorProvider.java [moved from certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/ArtifactsCreatorProvider.java with 83% similarity]
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/CsrFactory.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/EncryptionAlgorithmConstants.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/KeyPairFactory.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/PrivateKeyToPemEncoder.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/ArtifactsCreator.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/ConvertedArtifactsCreator.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/ConvertedArtifactsCreatorFactory.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/Password.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/PemArtifactsCreator.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/PemConverter.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/RandomPasswordGenerator.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/StoreEntryOperation.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/exception/KeyPairGenerationException.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/exception/PemConversionException.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriter.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/common/Base64Encoder.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvProvider.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvsForClient.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvsForCsr.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/exception/ClientConfigurationException.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/exception/CsrConfigurationException.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactory.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/exception/CertServiceApiResponseException.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/exception/HttpClientException.java
certServiceClient/src/main/resources/log4j2.xml
certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/ArtifactsCreatorProviderTest.java [moved from certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/ArtifactsCreatorProviderTest.java with 80% similarity]
certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/CsrFactoryTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/KeyPairFactoryTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/ConvertedArtifactsCreatorTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/PemArtifactsCreatorTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/PemConverterTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/conversion/RandomPasswordGeneratorTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriterTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/EnvProviderTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactoryTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/ClientConfigurationFactoryTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/CsrConfigurationFactoryTest.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/httpclient/HttpClientTest.java

index d2e5cb2..2698e50 100644 (file)
@@ -68,7 +68,8 @@
                                         </filter>
                                     </filters>
                                     <transformers>
-                                        <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+                                        <transformer
+                                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                             <mainClass>org.onap.aaf.certservice.client.MainApp</mainClass>
                                         </transformer>
                                     </transformers>
index 0bb983e..af30ff3 100644 (file)
@@ -16,6 +16,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aaf.certservice.client;
 
 import org.onap.aaf.certservice.client.api.ExitStatus;
index 27e8a4f..56c355e 100644 (file)
 package org.onap.aaf.certservice.client;
 
 import org.onap.aaf.certservice.client.api.ExitableException;
+import org.onap.aaf.certservice.client.certification.ArtifactsCreatorProvider;
 import org.onap.aaf.certservice.client.certification.CsrFactory;
 import org.onap.aaf.certservice.client.certification.KeyPairFactory;
 import org.onap.aaf.certservice.client.certification.PrivateKeyToPemEncoder;
-import org.onap.aaf.certservice.client.certification.conversion.ArtifactsCreatorProvider;
 import org.onap.aaf.certservice.client.common.Base64Encoder;
 import org.onap.aaf.certservice.client.configuration.EnvsForClient;
 import org.onap.aaf.certservice.client.configuration.EnvsForCsr;
@@ -78,7 +78,7 @@ public class CertServiceClient {
                             base64Encoder.encode(pkEncoder.encodePrivateKeyToPem(keyPair.getPrivate())));
 
             ArtifactsCreatorProvider
-                    .getCreator(clientConfiguration.getOutputType(),
+                    .get(clientConfiguration.getOutputType(),
                             clientConfiguration.getCertsOutputPath())
                     .create(certServiceData.getCertificateChain(),
                             certServiceData.getTrustedCertificates(),
index 1d32168..a84485e 100644 (file)
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aaf.certservice.client.api;
 
 public enum ExitStatus {
 
     SUCCESS(0, "Success"),
-    CLIENT_CONFIGURATION_EXCEPTION(1,"Invalid client configuration"),
-    CSR_CONFIGURATION_EXCEPTION(2,"Invalid CSR configuration"),
-    KEY_PAIR_GENERATION_EXCEPTION(3,"Fail in key pair generation"),
-    CSR_GENERATION_EXCEPTION(4,"Fail in CSR generation"),
-    CERT_SERVICE_API_CONNECTION_EXCEPTION(5,"CertService HTTP unsuccessful response"),
-    HTTP_CLIENT_EXCEPTION(6,"Internal HTTP Client connection problem"),
-    PEM_CONVERSION_EXCEPTION(7,"Fail in PEM conversion"),
-    PK_TO_PEM_ENCODING_EXCEPTION(8,"Fail in Private Key to PEM Encoding"),
+    CLIENT_CONFIGURATION_EXCEPTION(1, "Invalid client configuration"),
+    CSR_CONFIGURATION_EXCEPTION(2, "Invalid CSR configuration"),
+    KEY_PAIR_GENERATION_EXCEPTION(3, "Fail in key pair generation"),
+    CSR_GENERATION_EXCEPTION(4, "Fail in CSR generation"),
+    CERT_SERVICE_API_CONNECTION_EXCEPTION(5, "CertService HTTP unsuccessful response"),
+    HTTP_CLIENT_EXCEPTION(6, "Internal HTTP Client connection problem"),
+    PEM_CONVERSION_EXCEPTION(7, "Fail in PEM conversion"),
+    PK_TO_PEM_ENCODING_EXCEPTION(8, "Fail in Private Key to PEM Encoding"),
     TLS_CONFIGURATION_EXCEPTION(9, "Invalid TLS configuration"),
     FILE_CREATION_EXCEPTION(10, "File could not be created");
 
@@ -44,7 +45,7 @@ public enum ExitStatus {
         return value;
     }
 
-    public String getMessage(){
+    public String getMessage() {
         return message;
     }
 }
index fc1bc76..439c048 100644 (file)
@@ -16,6 +16,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aaf.certservice.client.api;
 
 public abstract class ExitableException extends Exception {
@@ -26,5 +27,6 @@ public abstract class ExitableException extends Exception {
     public ExitableException(String message) {
         super(message);
     }
+
     public abstract ExitStatus applicationExitStatus();
 }
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
-package org.onap.aaf.certservice.client.certification.conversion;
 
-import org.onap.aaf.certservice.client.certification.PrivateKeyToPemEncoder;
+package org.onap.aaf.certservice.client.certification;
+
+import org.onap.aaf.certservice.client.certification.conversion.ArtifactsCreator;
+import org.onap.aaf.certservice.client.certification.conversion.ConvertedArtifactsCreatorFactory;
+import org.onap.aaf.certservice.client.certification.conversion.PemArtifactsCreator;
 import org.onap.aaf.certservice.client.certification.writer.CertFileWriter;
 
 public enum ArtifactsCreatorProvider {
@@ -34,18 +37,20 @@ public enum ArtifactsCreatorProvider {
             return ConvertedArtifactsCreatorFactory.createConverter(destPath, getExtension(), getKeyStoreType());
         }
     },
-    PEM("PEM"){
+    PEM("PEM") {
         @Override
         ArtifactsCreator create(String destPath) {
             return new PemArtifactsCreator(new CertFileWriter(destPath), new PrivateKeyToPemEncoder());
         }
     };
+
     private final String keyStoreType;
+
     ArtifactsCreatorProvider(String keyStoreType) {
         this.keyStoreType = keyStoreType;
     }
 
-    public static ArtifactsCreator getCreator(String outputType, String destPath) {
+    public static ArtifactsCreator get(String outputType, String destPath) {
         return valueOf(outputType).create(destPath);
     }
 
index a7fb3f3..e381a8c 100644 (file)
@@ -31,7 +31,6 @@ import org.bouncycastle.operator.OperatorCreationException;
 import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
 import org.bouncycastle.pkcs.PKCS10CertificationRequest;
 import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequestBuilder;
-
 import org.onap.aaf.certservice.client.certification.exception.CsrGenerationException;
 import org.onap.aaf.certservice.client.configuration.model.CsrConfiguration;
 import org.slf4j.Logger;
index 96b3650..63ede56 100644 (file)
@@ -21,7 +21,8 @@ package org.onap.aaf.certservice.client.certification;
 
 public final class EncryptionAlgorithmConstants {
 
-    private EncryptionAlgorithmConstants() {}
+    private EncryptionAlgorithmConstants() {
+    }
 
     public static final String RSA_ENCRYPTION_ALGORITHM = "RSA";
     public static final String SIGN_ALGORITHM = "SHA1withRSA";
index e7d63e2..e997cd0 100644 (file)
@@ -16,6 +16,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aaf.certservice.client.certification;
 
 import org.onap.aaf.certservice.client.certification.exception.KeyPairGenerationException;
index 7391b11..fa6485e 100644 (file)
 package org.onap.aaf.certservice.client.certification;
 
 
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.security.PrivateKey;
-
 import org.bouncycastle.openssl.jcajce.JcaPEMWriter;
 import org.bouncycastle.util.io.pem.PemObject;
 import org.onap.aaf.certservice.client.certification.exception.PkEncodingException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.IOException;
+import java.io.StringWriter;
+import java.security.PrivateKey;
+
 public class PrivateKeyToPemEncoder {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(PrivateKeyToPemEncoder.class);
index 8907c48..428b85a 100644 (file)
@@ -16,6 +16,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aaf.certservice.client.certification.conversion;
 
 import org.onap.aaf.certservice.client.api.ExitableException;
@@ -24,6 +25,6 @@ import java.security.PrivateKey;
 import java.util.List;
 
 public interface ArtifactsCreator {
-     void create(List<String> keystoreData, List<String> truststoreData, PrivateKey privateKey)
+    void create(List<String> keystoreData, List<String> truststoreData, PrivateKey privateKey)
             throws ExitableException;
 }
index 4e30007..0ecee79 100644 (file)
 
 package org.onap.aaf.certservice.client.certification.conversion;
 
-import java.security.PrivateKey;
-import java.util.List;
 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 org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.security.PrivateKey;
+import java.util.List;
+
 public class ConvertedArtifactsCreator implements ArtifactsCreator {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(ConvertedArtifactsCreator.class);
@@ -42,8 +43,8 @@ public class ConvertedArtifactsCreator implements ArtifactsCreator {
     private final PemConverter converter;
     private final CertFileWriter fileWriter;
 
-    public ConvertedArtifactsCreator(CertFileWriter fileWriter, RandomPasswordGenerator passwordGenerator,
-                                     PemConverter converter, String fileExtension) {
+    ConvertedArtifactsCreator(CertFileWriter fileWriter, RandomPasswordGenerator passwordGenerator,
+                              PemConverter converter, String fileExtension) {
         this.passwordGenerator = passwordGenerator;
         this.converter = converter;
         this.fileWriter = fileWriter;
@@ -52,13 +53,13 @@ public class ConvertedArtifactsCreator implements ArtifactsCreator {
 
     @Override
     public void create(List<String> keystoreData, List<String> truststoreData, PrivateKey privateKey)
-        throws PemConversionException, CertFileWriterException {
-        createKeystore(keystoreData,privateKey);
+            throws PemConversionException, CertFileWriterException {
+        createKeystore(keystoreData, privateKey);
         createTruststore(truststoreData);
     }
 
     private void createKeystore(List<String> data, PrivateKey privateKey)
-        throws PemConversionException, CertFileWriterException {
+            throws PemConversionException, CertFileWriterException {
         Password password = passwordGenerator.generate(PASSWORD_LENGTH);
         String keystoreArtifactName = String.format("%s.%s", KEYSTORE, fileExtension);
         String keystorePass = String.format("%s.%s", KEYSTORE, PASS_EXT);
@@ -70,7 +71,7 @@ public class ConvertedArtifactsCreator implements ArtifactsCreator {
     }
 
     private void createTruststore(List<String> data)
-        throws PemConversionException, CertFileWriterException {
+            throws PemConversionException, CertFileWriterException {
         Password password = passwordGenerator.generate(PASSWORD_LENGTH);
         String truststoreArtifactName = String.format("%s.%s", TRUSTSTORE, fileExtension);
         String truststorePass = String.format("%s.%s", TRUSTSTORE, PASS_EXT);
index 5a37482..586e295 100644 (file)
@@ -23,7 +23,8 @@ import org.onap.aaf.certservice.client.certification.writer.CertFileWriter;
 
 public class ConvertedArtifactsCreatorFactory {
 
-    private ConvertedArtifactsCreatorFactory() { }
+    private ConvertedArtifactsCreatorFactory() {
+    }
 
     public static ConvertedArtifactsCreator createConverter(String destPath, String fileExtension, String keyStoreType) {
         return new ConvertedArtifactsCreator(
index 7a4cbfa..4bec222 100644 (file)
@@ -19,8 +19,6 @@
 
 package org.onap.aaf.certservice.client.certification.conversion;
 
-import java.security.PrivateKey;
-import java.util.List;
 import org.onap.aaf.certservice.client.certification.PrivateKeyToPemEncoder;
 import org.onap.aaf.certservice.client.certification.exception.CertFileWriterException;
 import org.onap.aaf.certservice.client.certification.exception.PkEncodingException;
@@ -28,6 +26,9 @@ import org.onap.aaf.certservice.client.certification.writer.CertFileWriter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.security.PrivateKey;
+import java.util.List;
+
 public class PemArtifactsCreator implements ArtifactsCreator {
     private static final Logger LOGGER = LoggerFactory.getLogger(PemArtifactsCreator.class);
 
@@ -45,7 +46,7 @@ public class PemArtifactsCreator implements ArtifactsCreator {
 
     @Override
     public void create(List<String> keystoreData, List<String> truststoreData, PrivateKey privateKey)
-        throws PkEncodingException, CertFileWriterException {
+            throws PkEncodingException, CertFileWriterException {
         LOGGER.debug("Attempt to create PEM private key file and saving data. File name: {}", KEY_PEM);
         writer.saveData(pkEncoder.encodePrivateKeyToPem(privateKey).getBytes(), KEY_PEM);
 
index 083e4bc..5e82c17 100644 (file)
 
 package org.onap.aaf.certservice.client.certification.conversion;
 
+import org.bouncycastle.cert.X509CertificateHolder;
+import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.openssl.PEMParser;
+import org.onap.aaf.certservice.client.certification.exception.PemConversionException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.StringReader;
@@ -31,19 +39,12 @@ import java.security.cert.Certificate;
 import java.security.cert.CertificateException;
 import java.util.List;
 import java.util.Optional;
-import org.bouncycastle.cert.X509CertificateHolder;
-import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import org.bouncycastle.openssl.PEMParser;
-import org.onap.aaf.certservice.client.certification.exception.PemConversionException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 class PemConverter {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(PemConverter.class);
     private static final String PASSWORD_ERROR_MSG = "Password should be min. 16 chars long and should contain only alphanumeric characters and special characters like Underscore (_), Dollar ($) and Pound (#)";
-    private final LoadStoreParameter EMPTY_KEYSTORE_CONFIGURATION = null;
+    private static final LoadStoreParameter EMPTY_KEYSTORE_CONFIGURATION = null;
     private final String keyStoreType;
 
     public PemConverter(String keyStoreType) {
@@ -51,19 +52,19 @@ class PemConverter {
     }
 
     byte[] convertKeystore(List<String> certificateChain, Password password, String alias, PrivateKey privateKey)
-    throws PemConversionException {
+            throws PemConversionException {
         LOGGER.info("Conversion of PEM certificates to " + keyStoreType + " keystore");
         return convert(certificateChain, password, certs -> getKeyStore(alias, password, certs, privateKey));
     }
 
     byte[] convertTruststore(List<String> trustAnchors, Password password, String alias)
-    throws PemConversionException {
+            throws PemConversionException {
         LOGGER.info("Conversion of PEM certificates to " + keyStoreType + " truststore");
         return convert(trustAnchors, password, certs -> getTrustStore(alias, certs));
     }
 
     private byte[] convert(List<String> certificates, Password password, StoreEntryOperation operation)
-        throws PemConversionException {
+            throws PemConversionException {
         checkPassword(password);
         final Certificate[] X509Certificates = convertToCertificateArray(certificates);
         return getKeyStoreBytes(password, operation, X509Certificates);
@@ -77,7 +78,7 @@ class PemConverter {
     }
 
     private byte[] getKeyStoreBytes(Password password, StoreEntryOperation op, Certificate[] x509Certificates)
-        throws PemConversionException {
+            throws PemConversionException {
         try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
             KeyStore ks = op.getStore(x509Certificates);
             ks.store(bos, password.toCharArray());
@@ -89,31 +90,31 @@ class PemConverter {
     }
 
     private KeyStore getKeyStore(String alias, Password password, Certificate[] certificates, PrivateKey privateKey)
-        throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
+            throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
         KeyStore ks = getKeyStoreInstance();
         ks.setKeyEntry(alias, privateKey, password.toCharArray(), certificates);
         return ks;
     }
 
     private KeyStore getTrustStore(String alias, Certificate[] certificates)
-        throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
+            throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
         KeyStore ks = getKeyStoreInstance();
-        long i = 1L;
+        long index = 1L;
         for (Certificate c : certificates) {
-            ks.setCertificateEntry(alias + i++, c);
+            ks.setCertificateEntry(alias + index++, c);
         }
         return ks;
     }
 
     private KeyStore getKeyStoreInstance()
-        throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
+            throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
         KeyStore ks = KeyStore.getInstance(keyStoreType);
         ks.load(EMPTY_KEYSTORE_CONFIGURATION);
         return ks;
     }
 
     private Certificate[] convertToCertificateArray(List<String> certificates)
-        throws PemConversionException {
+            throws PemConversionException {
         Certificate[] parsedCertificates = new Certificate[certificates.size()];
         for (String certificate : certificates) {
             parsedCertificates[certificates.indexOf(certificate)] = parseCertificate(certificate);
@@ -124,11 +125,11 @@ class PemConverter {
     private Certificate parseCertificate(String certificate) throws PemConversionException {
         try (PEMParser pem = new PEMParser(new StringReader(certificate))) {
             X509CertificateHolder certHolder = Optional.ofNullable((X509CertificateHolder) pem.readObject())
-                .orElseThrow(
-                    () -> new PemConversionException("The certificate couldn't be parsed correctly. " + certificate));
+                    .orElseThrow(
+                            () -> new PemConversionException("The certificate couldn't be parsed correctly. " + certificate));
             return new JcaX509CertificateConverter()
-                .setProvider(new BouncyCastleProvider())
-                .getCertificate(certHolder);
+                    .setProvider(new BouncyCastleProvider())
+                    .getCertificate(certHolder);
         } catch (IOException | CertificateException e) {
             LOGGER.error("Certificates conversion failed, exception message: {}", e.getMessage());
             throw new PemConversionException(e);
index 6515ea5..8ad85d2 100644 (file)
 
 package org.onap.aaf.certservice.client.certification.conversion;
 
-import java.security.SecureRandom;
-
 import org.apache.commons.lang3.RandomStringUtils;
 
+import java.security.SecureRandom;
+
 class RandomPasswordGenerator {
 
     private static final String ALPHA = "abcdefghijklmnopqrstuvwxyz";
index 6ee7817..7a41d1f 100644 (file)
@@ -30,5 +30,5 @@ import java.security.cert.CertificateException;
 public interface StoreEntryOperation {
 
     KeyStore getStore(Certificate[] certificates)
-        throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException;
+            throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException;
 }
index 11c448e..4d1cdaa 100644 (file)
@@ -28,6 +28,7 @@ public class PemConversionException extends ExitableException {
     public PemConversionException(Throwable e) {
         super(e);
     }
+
     public PemConversionException(String message) {
         super(message);
     }
index 400c0b7..2829517 100644 (file)
 
 package org.onap.aaf.certservice.client.certification.writer;
 
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-import java.nio.file.Path;
 import org.onap.aaf.certservice.client.certification.exception.CertFileWriterException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.file.Path;
+
 public class CertFileWriter {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(CertFileWriter.class);
@@ -36,11 +36,11 @@ public class CertFileWriter {
         this.destPath = destPath;
     }
 
-public void saveData(byte[] data, String filename) throws CertFileWriterException {
+    public void saveData(byte[] data, String filename) throws CertFileWriterException {
         LOGGER.debug("Attempt to save file {} in path {}", filename, destPath);
         try (FileOutputStream outputStream = new FileOutputStream(Path.of(destPath, filename).toString())) {
             outputStream.write(data);
-            } catch (IOException e) {
+        } catch (IOException e) {
             LOGGER.error("File creation failed, exception message: {}", e.getMessage());
             throw new CertFileWriterException(e);
         }
index 1f90db1..bfa4307 100644 (file)
@@ -22,7 +22,7 @@ package org.onap.aaf.certservice.client.common;
 import org.bouncycastle.util.encoders.Base64;
 
 public class Base64Encoder {
-    public String encode(String string){
+    public String encode(String string) {
         return new String(Base64.encode(string.getBytes()));
     }
 }
\ No newline at end of file
index 1b8c360..15339bb 100644 (file)
@@ -17,6 +17,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aaf.certservice.client.configuration;
 
 import java.util.Optional;
index dedd4d6..9321964 100644 (file)
@@ -17,6 +17,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aaf.certservice.client.configuration;
 
 import java.util.Optional;
index 06225d6..9a892b2 100644 (file)
@@ -17,6 +17,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aaf.certservice.client.configuration;
 
 import java.util.Optional;
index a54c926..24ed8b0 100644 (file)
@@ -21,7 +21,7 @@
 package org.onap.aaf.certservice.client.configuration.factory;
 
 
-import org.onap.aaf.certservice.client.certification.conversion.ArtifactsCreatorProvider;
+import org.onap.aaf.certservice.client.certification.ArtifactsCreatorProvider;
 import org.onap.aaf.certservice.client.configuration.exception.ClientConfigurationException;
 import org.onap.aaf.certservice.client.configuration.exception.CsrConfigurationException;
 import org.onap.aaf.certservice.client.configuration.model.ConfigurationModel;
@@ -43,10 +43,10 @@ public abstract class AbstractConfigurationFactory<T extends ConfigurationModel>
     }
 
     public boolean isCommonNameValid(String commonName) {
-        return !isSpecialCharsPresent(commonName) &&
-                !isHttpProtocolsPresent(commonName) &&
-                !isIpAddressPresent(commonName) &&
-                !isPortNumberPresent(commonName);
+        return !isSpecialCharsPresent(commonName)
+                && !isHttpProtocolsPresent(commonName)
+                && !isIpAddressPresent(commonName)
+                && !isPortNumberPresent(commonName);
     }
 
     public boolean isSpecialCharsPresent(String stringToCheck) {
index 151c2a1..ad5a5f1 100644 (file)
@@ -26,11 +26,11 @@ import org.onap.aaf.certservice.client.api.ExitableException;
 public class CertServiceApiResponseException extends ExitableException {
     private static final ExitStatus EXIT_STATUS = ExitStatus.CERT_SERVICE_API_CONNECTION_EXCEPTION;
 
-    public CertServiceApiResponseException(int responseCode, String messageFromAPI) {
+    public CertServiceApiResponseException(int responseCode, String messageFromApi) {
 
         super(String.format("CertService HTTP unsuccessful response. Response code: %d . Message from Service: %s",
                 responseCode,
-                messageFromAPI));
+                messageFromApi));
     }
 
     @Override
index 697d152..bc48554 100644 (file)
@@ -26,7 +26,7 @@ import org.onap.aaf.certservice.client.api.ExitableException;
 public class HttpClientException extends ExitableException {
     private static final ExitStatus EXIT_STATUS = ExitStatus.HTTP_CLIENT_EXCEPTION;
 
-    public HttpClientException(Throwable e){
+    public HttpClientException(Throwable e) {
         super(e);
     }
 
index 37eb078..bf4b623 100644 (file)
@@ -8,7 +8,8 @@
                     pattern="%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} %highlight{${LOG_LEVEL_PATTERN:-%5p}}{FATAL=red blink, ERROR=red, WARN=yellow bold, INFO=green, DEBUG=green bold, TRACE=blue} %style{%pid}{magenta} [%15.15t] %style{%-40.40C{1.}}{cyan} : %m%n%throwable"/>
         </Console>
 
-        <RollingFile fileName="var/log/onap/aaf/certservice-client/certservice-client.log" filePattern="logs/certservice-client-%d{yyyy-MM-dd}-%i.log" name="ROLLING_FILE">
+        <RollingFile fileName="var/log/onap/aaf/certservice-client/certservice-client.log"
+                     filePattern="logs/certservice-client-%d{yyyy-MM-dd}-%i.log" name="ROLLING_FILE">
             <PatternLayout pattern="[%d{ISO8601}][%-5p][%-5c] %m%n"/>
             <Policies>
                 <SizeBasedTriggeringPolicy size="64 MB"/>
index 7e7bf5d..3680894 100644 (file)
@@ -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
  * ============LICENSE_END=========================================================
  */
 
-package org.onap.aaf.certservice.client.certification.conversion;
+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;
 
@@ -36,21 +39,21 @@ class ArtifactsCreatorProviderTest {
 
     @ParameterizedTest
     @ValueSource(strings = {JKS, P12})
-    void artifactsProviderShouldReturnConvertedCreator(String outputType){
+    void artifactsProviderShouldReturnConvertedCreator(String outputType) {
 
         // when
         ArtifactsCreator artifactsCreator =
-                ArtifactsCreatorProvider.getCreator(outputType, TEST_PATH);
+                ArtifactsCreatorProvider.get(outputType, TEST_PATH);
         // then
         assertThat(artifactsCreator).isInstanceOf(ConvertedArtifactsCreator.class);
     }
 
     @Test
-    void artifactsProviderShouldReturnPemCreator(){
+    void artifactsProviderShouldReturnPemCreator() {
 
         // when
         ArtifactsCreator artifactsCreator =
-            ArtifactsCreatorProvider.getCreator(PEM, TEST_PATH);
+                ArtifactsCreatorProvider.get(PEM, TEST_PATH);
         // then
         assertThat(artifactsCreator).isInstanceOf(PemArtifactsCreator.class);
     }
@@ -59,7 +62,7 @@ class ArtifactsCreatorProviderTest {
     @CsvSource({
             "JKS,       jks",
             "P12,       p12"})
-    void getExtensionShouldProvideExtensionBasedOnArtifactType(String artifactType, String expectedExtension){
+    void getExtensionShouldProvideExtensionBasedOnArtifactType(String artifactType, String expectedExtension) {
 
         //when
         String actualExtension = ArtifactsCreatorProvider.valueOf(artifactType).getExtension();
index 809a91f..e88976b 100644 (file)
@@ -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();
-     }
+    }
 }
 
index 6a4741a..3d3d3c1 100644 (file)
@@ -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
index 2da4ab9..e13f8be 100644 (file)
 
 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<String> 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();
 
index 9963d24..5e79b96 100644 (file)
 
 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);
index 0d67fba..e3a58c3 100644 (file)
 
 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<String> 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<String> 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)
         );
     }
 }
index 169ce98..483e35e 100644 (file)
 
 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
index 443f562..e7ebb32 100644 (file)
 
 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);
     }
 }
index 7ef921a..af6b2d9 100644 (file)
@@ -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<String> testEnv = envProvider.readEnvVariable(TEST_ENV);
 
index 7239b21..20a6c7e 100644 (file)
@@ -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));
index 2edff2f..5abd0b1 100644 (file)
@@ -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<CsrConfigurationException> expectedExitCodeCondition = new Condition<>("Correct exit code"){
+    private Condition<CsrConfigurationException> expectedExitCodeCondition = new Condition<>("Correct exit code") {
         @Override
         public boolean matches(CsrConfigurationException e) {
             return e.applicationExitStatus() == CSR_CONFIGURATION_EXCEPTION;
index 60c2e93..a109749 100644 (file)
@@ -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)