Add subfolders creation
authorkjaniak <kornel.janiak@nokia.com>
Wed, 8 Jul 2020 13:19:33 +0000 (15:19 +0200)
committerPiotr Marcinkiewicz <piotr.marcinkiewicz@nokia.com>
Mon, 13 Jul 2020 08:12:50 +0000 (10:12 +0200)
Added new not existing subfolders creation in output path to allow CMPv2 integration.
Top up version to 1.2.0

Issue-ID: DCAEGEN2-2252
Change-Id: I59f8dfa7fddc5eb3a3fdd80ce18eb3e2272e1bfb
Signed-off-by: kjaniak <kornel.janiak@nokia.com>
12 files changed:
certService/pom.xml
certService/version.properties
certServiceClient/README.md
certServiceClient/pom.xml
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/ArtifactsCreatorProvider.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/ConvertedArtifactsCreatorFactory.java
certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriter.java
certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriterTest.java
certServiceClient/version.properties
docs/sections/release-notes.rst
pom.xml
version.properties

index 5cc45cd..9febd16 100644 (file)
     <parent>
         <groupId>org.onap.aaf.certservice</groupId>
         <artifactId>aaf-certservice</artifactId>
-        <version>1.1.0-SNAPSHOT</version>
+        <version>1.2.0-SNAPSHOT</version>
     </parent>
     <artifactId>aaf-certservice-api</artifactId>
-    <version>1.1.0-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
     <name>aaf-certservice-api</name>
     <description>AAF Certification Service Api</description>
     <packaging>jar</packaging>
index 7b8b963..00ef564 100644 (file)
@@ -1,5 +1,5 @@
 major=1
-minor=1
+minor=2
 patch=0
 base_version=${major}.${minor}.${patch}
 release_version=${base_version}
index adb5d4f..b300534 100644 (file)
@@ -26,7 +26,7 @@ CertService API and client must be running in same network.
 
 You need certificate and trust anchors (in JKS format) to connect to CertService API via HTTPS. Information how to generate truststore and keystore files you can find in CertService main README.
 
-Information how to run you can find in CertService main README and official documentation, see [Read The Docs](https://onap-doc.readthedocs.io/projects/onap-aaf-certservice/en/latest/sections/usage.html)
+Information how to run you can find in CertService main README and official documentation, see [Read The Docs](https://docs.onap.org/projects/onap-aaf-certservice/en/latest/sections/usage.html)
 
 
 ### Logs locally
index 50ae677..e176b18 100644 (file)
@@ -5,12 +5,12 @@
     <parent>
         <artifactId>aaf-certservice</artifactId>
         <groupId>org.onap.aaf.certservice</groupId>
-        <version>1.1.0-SNAPSHOT</version>
+        <version>1.2.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
     <artifactId>aaf-certservice-client</artifactId>
-    <version>1.1.0-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
     <name>aaf-certservice-client</name>
     <description>AAF Certification Service Api Client</description>
     <packaging>jar</packaging>
index 06a4cc6..954f3d3 100644 (file)
@@ -40,7 +40,7 @@ public enum ArtifactsCreatorProvider {
     PEM("PEM") {
         @Override
         ArtifactsCreator create(String destPath) {
-            return new PemArtifactsCreator(new CertFileWriter(destPath), new PrivateKeyToPemEncoder());
+            return new PemArtifactsCreator(CertFileWriter.createWithDir(destPath), new PrivateKeyToPemEncoder());
         }
     };
 
index 586e295..bda796e 100644 (file)
@@ -28,7 +28,7 @@ public class ConvertedArtifactsCreatorFactory {
 
     public static ConvertedArtifactsCreator createConverter(String destPath, String fileExtension, String keyStoreType) {
         return new ConvertedArtifactsCreator(
-                new CertFileWriter(destPath),
+                CertFileWriter.createWithDir(destPath),
                 new RandomPasswordGenerator(),
                 new PemConverter(keyStoreType),
                 fileExtension);
index 2829517..fec3ebd 100644 (file)
@@ -23,6 +23,7 @@ import org.onap.aaf.certservice.client.certification.exception.CertFileWriterExc
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.nio.file.Path;
@@ -32,10 +33,15 @@ public class CertFileWriter {
     private static final Logger LOGGER = LoggerFactory.getLogger(CertFileWriter.class);
     private final String destPath;
 
-    public CertFileWriter(String destPath) {
+    private CertFileWriter(String destPath) {
         this.destPath = destPath;
     }
 
+    public static CertFileWriter createWithDir(String destPath) {
+        createDirIfNotExists(destPath);
+        return new CertFileWriter(destPath);
+    }
+
     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())) {
@@ -45,4 +51,12 @@ public class CertFileWriter {
             throw new CertFileWriterException(e);
         }
     }
+
+    private static void createDirIfNotExists(String destPath) {
+        File destFolderPath = new File(destPath);
+        if (!destFolderPath.exists()) {
+            LOGGER.debug("Destination path not exists, subdirectories are created");
+            destFolderPath.mkdirs();
+        }
+    }
 }
index 61c4d83..c45876e 100644 (file)
@@ -20,8 +20,8 @@
 package org.onap.aaf.certservice.client.certification.writer;
 
 import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-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.exception.CertFileWriterException;
 
 import java.io.File;
@@ -35,48 +35,42 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 class CertFileWriterTest {
 
-    private static final String RESOURCES_PATH = "src/test/resources";
-    private static final String OUTPUT_PATH = RESOURCES_PATH + "/generatedFiles/";
+    private static final String RESOURCES_PATH = "src/test/resources/";
+    private static final String OUTPUT_PATH = RESOURCES_PATH + "generatedFiles/";
+    private static final String NOT_EXISTING_OUTPUT_PATH = OUTPUT_PATH + "directoryDoesNotExist/";
     private static final String TRUSTSTORE_P12 = "truststore.p12";
-    private static final String ERROR_MESSAGE = "java.io.FileNotFoundException: src/test/resources/generatedFiles/thisPathDoesNotExist/truststore.p12 (No such file or directory)";
-
     private File outputDirectory = new File(OUTPUT_PATH);
 
-    @BeforeEach
-    void createDirectory() {
-        outputDirectory.mkdir();
-    }
-
     @AfterEach
     void cleanUpFiles() {
-        List.of(outputDirectory.listFiles()).forEach(f -> f.delete());
-        outputDirectory.delete();
+        deleteDirectoryRecursive(outputDirectory);
     }
 
-    @Test
-    void certFileWriterShouldCreateFilesWithDataInGivenLocation()
+    @ParameterizedTest
+    @ValueSource(strings = {OUTPUT_PATH, NOT_EXISTING_OUTPUT_PATH})
+    void certFileWriterShouldCreateFilesWithDataInGivenLocation(String outputPath)
             throws IOException, CertFileWriterException {
         // given
+        File truststore = new File(outputPath + TRUSTSTORE_P12);
+        CertFileWriter certFileWriter = CertFileWriter.createWithDir(outputPath);
         final byte[] data = new byte[]{-128, 1, 2, 3, 127};
-        File truststore = new File(OUTPUT_PATH + TRUSTSTORE_P12);
-        CertFileWriter certFileWriter = new CertFileWriter(OUTPUT_PATH);
 
         // when
         certFileWriter.saveData(data, TRUSTSTORE_P12);
 
         // then
         assertThat(truststore.exists()).isTrue();
-        assertThat(Files.readAllBytes(Path.of(OUTPUT_PATH + TRUSTSTORE_P12))).isEqualTo(data);
+        assertThat(Files.readAllBytes(Path.of(outputPath + TRUSTSTORE_P12))).isEqualTo(data);
     }
 
-    @Test
-    void certFileWriterShouldThrowCertFileWriterExceptionWhenOutputDirectoryDoesNotExist() {
-        // given
-        final byte[] data = new byte[]{-128, 1, 2, 3, 0};
-        CertFileWriter certFileWriter = new CertFileWriter(OUTPUT_PATH + "thisPathDoesNotExist/");
-
-        // when then
-        assertThatThrownBy(() -> certFileWriter.saveData(data, TRUSTSTORE_P12))
-                .isInstanceOf(CertFileWriterException.class).hasMessage(ERROR_MESSAGE);
+    private void deleteDirectoryRecursive(File dirForDeletion) {
+        List.of(dirForDeletion.listFiles()).forEach(file -> {
+            if (file.isDirectory()) {
+                deleteDirectoryRecursive(file);
+            }
+            file.delete();
+        });
+        dirForDeletion.delete();
     }
+
 }
index 7b8b963..00ef564 100644 (file)
@@ -1,5 +1,5 @@
 major=1
-minor=1
+minor=2
 patch=0
 base_version=${major}.${minor}.${patch}
 release_version=${base_version}
index 7d32480..daeab0f 100644 (file)
@@ -6,6 +6,47 @@
 Release Notes
 ==============
 
+Version: 1.2.0
+--------------
+
+:Release Date:
+
+**New Features**
+
+        - Client creates subdirectories in given OUTPUT_PATH and place certificate into it.
+
+**Bug Fixes**
+
+        N/A
+
+**Known Issues**
+
+        N/A
+
+**Security Notes**
+
+        N/A
+
+*Fixed Security Issues*
+
+        N/A
+
+*Known Security Issues*
+
+        N/A
+
+*Known Vulnerabilities in Used Modules*
+
+        N/A
+
+**Upgrade Notes**
+
+**Deprecation Notes**
+
+**Other**
+
+===========
+
 Version: 1.1.0
 --------------
 
diff --git a/pom.xml b/pom.xml
index b5ca7ef..8126ee9 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     </parent>
     <groupId>org.onap.aaf.certservice</groupId>
     <artifactId>aaf-certservice</artifactId>
-    <version>1.1.0-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
     <name>aaf-certservice</name>
     <description>AAF Certification Service</description>
     <packaging>pom</packaging>
index 7b8b963..00ef564 100644 (file)
@@ -1,5 +1,5 @@
 major=1
-minor=1
+minor=2
 patch=0
 base_version=${major}.${minor}.${patch}
 release_version=${base_version}