diff options
author | 2020-07-08 15:19:33 +0200 | |
---|---|---|
committer | 2020-07-13 10:12:50 +0200 | |
commit | e64680cd62b468a25b763457c2e1d31414081c29 (patch) | |
tree | 21ab8e027a6fb62dc606eca155b719772de29612 /certServiceClient/src/test/java/org/onap/aaf/certservice | |
parent | ed1b24390eaacd5ec869bd1947a2cbcd21f62b63 (diff) |
Add subfolders creation
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>
Diffstat (limited to 'certServiceClient/src/test/java/org/onap/aaf/certservice')
-rw-r--r-- | certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriterTest.java | 48 |
1 files changed, 21 insertions, 27 deletions
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 61c4d835..c45876ec 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 @@ -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(); } + } |