aboutsummaryrefslogtreecommitdiffstats
path: root/trustStoreMerger/src/test
diff options
context:
space:
mode:
authorkjaniak <kornel.janiak@nokia.com>2020-09-10 22:03:53 +0200
committerkjaniak <kornel.janiak@nokia.com>2020-09-14 10:57:59 +0200
commit9f597ecbf18bbda75317926c35066b9571736054 (patch)
treec524613ee646d5d8bf482df6172a83b021cbdd46 /trustStoreMerger/src/test
parent4ad0fafc796a7b65b9d653863d0f57a62eca5fa9 (diff)
[OOM-CPMv2] Allow optional input parameters
Bug fix in merger to allow KEYSTORE paths to be optional. Issue-ID: DCAEGEN2-2253 Signed-off-by: kjaniak <kornel.janiak@nokia.com> Change-Id: I9176d7fdb0e714d849a4ea617ccc4f8eb6a233e1
Diffstat (limited to 'trustStoreMerger/src/test')
-rw-r--r--trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/common/ExtensionResolverTest.java1
-rw-r--r--trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/AppConfigurationProviderTest.java141
-rw-r--r--trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationProviderTest.java172
-rw-r--r--trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/path/DelimitedPathsReaderFactoryTest.java39
-rw-r--r--trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/path/DelimitedPathsReaderTest.java144
-rw-r--r--trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/path/DelimitedPathsSplitterTest.java107
-rw-r--r--trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/path/env/EnvReaderTest.java62
7 files changed, 310 insertions, 356 deletions
diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/common/ExtensionResolverTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/common/ExtensionResolverTest.java
index e59a7671..0ed17d0c 100644
--- a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/common/ExtensionResolverTest.java
+++ b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/common/ExtensionResolverTest.java
@@ -17,7 +17,6 @@
* ============LICENSE_END=========================================================
*/
-
package org.onap.oom.truststoremerger.common;
import org.junit.jupiter.params.ParameterizedTest;
diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/AppConfigurationProviderTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/AppConfigurationProviderTest.java
new file mode 100644
index 00000000..a8da405d
--- /dev/null
+++ b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/AppConfigurationProviderTest.java
@@ -0,0 +1,141 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * 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.oom.truststoremerger.configuration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.mockito.Mockito.when;
+import static org.onap.oom.truststoremerger.configuration.model.EnvVariable.KEYSTORE_DESTINATION_PATHS_ENV;
+import static org.onap.oom.truststoremerger.configuration.model.EnvVariable.KEYSTORE_SOURCE_PATHS_ENV;
+import static org.onap.oom.truststoremerger.configuration.model.EnvVariable.TRUSTSTORES_PASSWORDS_PATHS_ENV;
+import static org.onap.oom.truststoremerger.configuration.model.EnvVariable.TRUSTSTORES_PATHS_ENV;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.onap.oom.truststoremerger.configuration.exception.CertificatesPathsValidationException;
+import org.onap.oom.truststoremerger.configuration.exception.ConfigurationException;
+import org.onap.oom.truststoremerger.configuration.model.AppConfiguration;
+import org.onap.oom.truststoremerger.configuration.path.DelimitedPathsSplitter;
+import org.onap.oom.truststoremerger.configuration.path.env.EnvReader;
+
+@ExtendWith(MockitoExtension.class)
+class AppConfigurationProviderTest {
+
+ private static final String BASE_TRUSTSTORE_PATH = "/opt/app/truststore_";
+ private static final String JKS_EXTENSION = ".jks";
+ private static final String PASS_EXTENSION = ".pass";
+ private static final String TRUSTSTORES_PATHS = "/opt/app/certificates/truststore.jks:/opt/app/certificates/truststore.pem";
+ private static final String TRUSTSTORES_PASSWORDS_PATHS = "/opt/app/certificates/truststore.pass:/trust.pass";
+
+ @Mock
+ private DelimitedPathsSplitter pathsSplitter;
+ @Mock
+ private EnvReader envReader;
+ private AppConfigurationProvider provider;
+
+ @BeforeEach
+ void setUp() {
+ provider = new AppConfigurationProvider(pathsSplitter, envReader);
+ }
+
+ @Test
+ void shouldThrowExceptionWhenMandatoryEnvNotPresent() {
+ // given
+ when(envReader.getEnv(TRUSTSTORES_PATHS_ENV.name())).thenReturn(Optional.empty());
+ // when, then
+ assertThatExceptionOfType(ConfigurationException.class).isThrownBy(() -> provider.createConfiguration())
+ .withMessageContaining(TRUSTSTORES_PATHS_ENV + " mandatory environment variable is not defined");
+ }
+
+ @Test
+ void shouldThrowExceptionWhenTrustorePathsSizesDoNotMatch() {
+ // given
+ List<String> truststores = createListOfPathsWithExtension(2, JKS_EXTENSION);
+ List<String> truststoresPasswords = createListOfPathsWithExtension(1, PASS_EXTENSION);
+
+ mockTruststorePaths(truststores, truststoresPasswords);
+ // when
+ assertThatExceptionOfType(ConfigurationException.class)
+ .isThrownBy(() -> provider.createConfiguration())
+ .withMessageContaining("Size of " + TRUSTSTORES_PATHS_ENV
+ + " does not match size of " + TRUSTSTORES_PASSWORDS_PATHS_ENV + " environment variables");
+ }
+
+ @Test
+ void shouldReturnEmptyListWhenOptionalEnvNotPresent() {
+ // given
+ List<String> truststores = createListOfPathsWithExtension(2, JKS_EXTENSION);
+ List<String> truststoresPasswords = createListOfPathsWithExtension(2, PASS_EXTENSION);
+ mockTruststorePaths(truststores, truststoresPasswords);
+ mockKeystorePaths(Optional.empty(), Optional.empty());
+ // when
+ AppConfiguration paths = provider.createConfiguration();
+ // then
+ assertThat(paths.getDestinationKeystorePaths()).isEmpty();
+ assertThat(paths.getSourceKeystorePaths()).isEmpty();
+ }
+
+ private void mockTruststorePaths(List<String> truststores, List<String> truststoresPasswords) {
+ mockTruststores(truststores);
+ mockTruststoresPasswords(truststoresPasswords);
+ }
+
+ private void mockKeystorePaths(Optional<String> sourceKeystoresPairPaths, Optional<String> destKeystoresPairPaths) {
+ mockKeystoreCopierSourcePaths(sourceKeystoresPairPaths);
+ mockKeystoreCopierDestinationPaths(destKeystoresPairPaths);
+ }
+
+ private void mockTruststores(List<String> truststores) throws CertificatesPathsValidationException {
+ when(envReader.getEnv(TRUSTSTORES_PATHS_ENV.name())).thenReturn(Optional.of(TRUSTSTORES_PATHS));
+ when(pathsSplitter.getValidatedPaths(TRUSTSTORES_PATHS_ENV, Optional.of(TRUSTSTORES_PATHS)))
+ .thenReturn(truststores);
+ }
+
+ private void mockTruststoresPasswords(List<String> truststoresPasswords)
+ throws CertificatesPathsValidationException {
+ Optional<String> passwordsPaths = Optional.of(TRUSTSTORES_PASSWORDS_PATHS);
+ when(envReader.getEnv(TRUSTSTORES_PASSWORDS_PATHS_ENV.name())).thenReturn(passwordsPaths);
+ when(pathsSplitter.getValidatedPaths(TRUSTSTORES_PASSWORDS_PATHS_ENV, passwordsPaths))
+ .thenReturn(truststoresPasswords);
+ }
+
+ private void mockKeystoreCopierSourcePaths(Optional<String> paths) {
+ when(envReader.getEnv(KEYSTORE_SOURCE_PATHS_ENV.name())).thenReturn(paths);
+ }
+
+ private void mockKeystoreCopierDestinationPaths(Optional<String> paths) {
+ when(envReader.getEnv(KEYSTORE_DESTINATION_PATHS_ENV.name())).thenReturn(paths);
+ }
+
+ private List<String> createListOfPathsWithExtension(int numberOfPaths, String passwordExtension) {
+ List<String> paths = new ArrayList<>();
+ while (numberOfPaths-- > 0) {
+ paths.add(BASE_TRUSTSTORE_PATH + numberOfPaths + passwordExtension);
+ }
+ return paths;
+ }
+
+}
diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationProviderTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationProviderTest.java
deleted file mode 100644
index 026199f4..00000000
--- a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationProviderTest.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*============LICENSE_START=======================================================
- * oom-truststore-merger
- * ================================================================================
- * 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.oom.truststoremerger.configuration;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
-import static org.mockito.Mockito.when;
-import static org.onap.oom.truststoremerger.configuration.ConfigurationEnvs.KEYSTORE_DESTINATION_PATHS_ENV;
-import static org.onap.oom.truststoremerger.configuration.ConfigurationEnvs.KEYSTORE_SOURCE_PATHS_ENV;
-import static org.onap.oom.truststoremerger.configuration.ConfigurationEnvs.TRUSTSTORES_PASSWORDS_PATHS_ENV;
-import static org.onap.oom.truststoremerger.configuration.ConfigurationEnvs.TRUSTSTORES_PATHS_ENV;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-import org.onap.oom.truststoremerger.configuration.exception.MergerConfigurationException;
-import org.onap.oom.truststoremerger.configuration.exception.TruststoresPathsProviderException;
-import org.onap.oom.truststoremerger.configuration.model.AppConfiguration;
-import org.onap.oom.truststoremerger.configuration.path.DelimitedPathsReader;
-
-@ExtendWith(MockitoExtension.class)
-class MergerConfigurationProviderTest {
-
- private static final String BASE_TRUSTSTORE_PATH = "/opt/app/truststore_";
- private static final String KEYSTORE_PATH = "/opt/app/keystore_";
- private static final String ANOTHER_KEYSTORE_PATH = "/opt/app/external/keystore_";
- private static final String JKS_EXTENSION = ".jks";
- private static final String PEM_EXTENSION = ".pem";
- private static final String PASS_EXTENSION = ".pass";
-
- @Mock
- private DelimitedPathsReader certificatesPathsProvider;
- @Mock
- private DelimitedPathsReader passwordsPathsProvider;
- @Mock
- private DelimitedPathsReader copierPathsReader;
- private AppConfigurationProvider factory;
-
- @BeforeEach
- void setUp() {
- factory = new AppConfigurationProvider(certificatesPathsProvider, passwordsPathsProvider, copierPathsReader);
- }
-
- @Test
- void shouldReturnConfigurationWithCorrectPaths()
- throws TruststoresPathsProviderException, MergerConfigurationException {
- int numberOfPaths = 5;
- List<String> truststoresPaths = createListOfPathsWithExtension(numberOfPaths, JKS_EXTENSION);
- List<String> truststorePasswordPaths = createListOfPathsWithExtension(numberOfPaths, PASS_EXTENSION);
- mockTruststorePaths(truststoresPaths, truststorePasswordPaths);
-
- List<String> sourceKeystoresPairPaths = createListOfKeystorePairsPathsWithExtension(KEYSTORE_PATH,
- numberOfPaths, PEM_EXTENSION);
- List<String> destKeystoresPairPaths = createListOfKeystorePairsPathsWithExtension(ANOTHER_KEYSTORE_PATH,
- numberOfPaths, PEM_EXTENSION);
- mockKeystorePaths(sourceKeystoresPairPaths, destKeystoresPairPaths);
-
- AppConfiguration configuration = factory.createConfiguration();
-
- assertThat(configuration.getTruststoreFilePaths()).containsAll(truststoresPaths);
- assertThat(configuration.getTruststoreFilePasswordPaths()).containsAll(truststorePasswordPaths);
- assertThat(configuration.getSourceKeystorePaths()).containsAll(sourceKeystoresPairPaths);
- assertThat(configuration.getDestinationKeystorePaths()).containsAll(destKeystoresPairPaths);
- }
-
- @Test
- void shouldThrowExceptionWhenTruststoresLengthDifferentThanTruststoresPasswordsLength()
- throws TruststoresPathsProviderException {
- int numberOfCertificates = 5;
- int numberOfTruststoresPasswords = 4;
- List<String> truststoresPaths = createListOfPathsWithExtension(numberOfCertificates, JKS_EXTENSION);
- List<String> truststorePasswordPaths = createListOfPathsWithExtension(numberOfTruststoresPasswords, PASS_EXTENSION);
- mockTruststorePaths(truststoresPaths, truststorePasswordPaths);
-
- List<String> sourceKeystoresPairPaths = createListOfKeystorePairsPathsWithExtension(KEYSTORE_PATH,
- numberOfCertificates, PEM_EXTENSION);
- List<String> destKeystoresPairPaths = createListOfKeystorePairsPathsWithExtension(ANOTHER_KEYSTORE_PATH,
- numberOfCertificates, PEM_EXTENSION);
- mockKeystorePaths(sourceKeystoresPairPaths, destKeystoresPairPaths);
-
- assertThatExceptionOfType(MergerConfigurationException.class)
- .isThrownBy(factory::createConfiguration);
- }
-
- @Test
- void shouldThrowExceptionWhenSourceLengthDifferentThanDestinationLength()
- throws TruststoresPathsProviderException {
- int numberOfCertificates = 5;
- int anotherNumberOfCertificates = 1;
- List<String> truststoresPaths = createListOfPathsWithExtension(numberOfCertificates, JKS_EXTENSION);
- List<String> truststorePasswordPaths = createListOfPathsWithExtension(numberOfCertificates, PASS_EXTENSION);
- mockTruststorePaths(truststoresPaths, truststorePasswordPaths);
-
- List<String> sourceKeystoresPairPaths = createListOfKeystorePairsPathsWithExtension(KEYSTORE_PATH,
- numberOfCertificates, PEM_EXTENSION);
- List<String> destKeystoresPairPaths = createListOfKeystorePairsPathsWithExtension(ANOTHER_KEYSTORE_PATH,
- anotherNumberOfCertificates, PEM_EXTENSION);
- mockKeystorePaths(sourceKeystoresPairPaths, destKeystoresPairPaths);
-
- assertThatExceptionOfType(MergerConfigurationException.class)
- .isThrownBy(factory::createConfiguration);
- }
-
- private void mockTruststorePaths(List<String> truststores, List<String> truststoresPasswords)
- throws TruststoresPathsProviderException {
- mockTruststores(truststores);
- mockTruststoresPasswords(truststoresPasswords);
- }
-
- private void mockKeystorePaths(List<String> sourceKeystoresPairPaths, List<String> destKeystoresPairPaths)
- throws TruststoresPathsProviderException {
- mockKeystoreCopierSourcePaths(sourceKeystoresPairPaths);
- mockKeystoreCopierDestinationPaths(destKeystoresPairPaths);
- }
-
- private void mockTruststores(List<String> truststores) throws TruststoresPathsProviderException {
- when(certificatesPathsProvider.get(TRUSTSTORES_PATHS_ENV)).thenReturn(truststores);
- }
-
- private void mockTruststoresPasswords(List<String> truststoresPasswords) throws TruststoresPathsProviderException {
- when(passwordsPathsProvider.get(TRUSTSTORES_PASSWORDS_PATHS_ENV)).thenReturn(truststoresPasswords);
- }
-
- private void mockKeystoreCopierSourcePaths(List<String> paths) throws TruststoresPathsProviderException {
- when(copierPathsReader.get(KEYSTORE_SOURCE_PATHS_ENV)).thenReturn(paths);
- }
-
- private void mockKeystoreCopierDestinationPaths(List<String> paths) throws TruststoresPathsProviderException {
- when(copierPathsReader.get(KEYSTORE_DESTINATION_PATHS_ENV)).thenReturn(paths);
- }
-
- private List<String> createListOfPathsWithExtension(int numberOfPaths, String passwordExtension) {
- List<String> paths = new ArrayList<>();
- while (numberOfPaths-- > 0) {
- paths.add(BASE_TRUSTSTORE_PATH + numberOfPaths + passwordExtension);
- }
- return paths;
- }
-
- private List<String> createListOfKeystorePairsPathsWithExtension(String path, int numberOfPaths,
- String certExtension) {
- List<String> paths = new ArrayList<>();
- String passExtension = certExtension.equalsIgnoreCase(".pem") ? certExtension : ".pass";
- while (numberOfPaths-- > 0) {
- paths.add(path + numberOfPaths + certExtension);
- paths.add(ANOTHER_KEYSTORE_PATH + numberOfPaths + passExtension);
- }
- return paths;
- }
-
-}
diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/path/DelimitedPathsReaderFactoryTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/path/DelimitedPathsReaderFactoryTest.java
deleted file mode 100644
index 5a7e9cd0..00000000
--- a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/path/DelimitedPathsReaderFactoryTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*============LICENSE_START=======================================================
- * oom-truststore-merger
- * ================================================================================
- * 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.oom.truststoremerger.configuration.path;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.jupiter.api.Test;
-import org.onap.oom.truststoremerger.configuration.path.env.EnvProvider;
-
-class DelimitedPathsReaderFactoryTest {
-
- @Test
- void shouldReturnObjectOfDelimitedPathsReaderType() {
- // given
- DelimitedPathsReaderFactory readerFactory = new DelimitedPathsReaderFactory(new EnvProvider());
- //when, then
- assertThat(readerFactory.createPasswordPathsReader()).isInstanceOf(DelimitedPathsReader.class);
- assertThat(readerFactory.createCertificatePathsReader()).isInstanceOf(DelimitedPathsReader.class);
- assertThat(readerFactory.createKeystoreCopierPathsReader()).isInstanceOf(DelimitedPathsReader.class);
- }
-
-}
diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/path/DelimitedPathsReaderTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/path/DelimitedPathsReaderTest.java
deleted file mode 100644
index 408a7d6d..00000000
--- a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/path/DelimitedPathsReaderTest.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*============LICENSE_START=======================================================
- * oom-truststore-merger
- * ================================================================================
- * 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.oom.truststoremerger.configuration.path;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
-import static org.mockito.Mockito.when;
-import static org.onap.oom.truststoremerger.configuration.ConfigurationEnvs.TRUSTSTORES_PASSWORDS_PATHS_ENV;
-import static org.onap.oom.truststoremerger.configuration.ConfigurationEnvs.TRUSTSTORES_PATHS_ENV;
-import static org.onap.oom.truststoremerger.configuration.path.validation.ValidationFunctions.doesItContainValidCertificatesPaths;
-import static org.onap.oom.truststoremerger.configuration.path.validation.ValidationFunctions.doesItContainValidPasswordPaths;
-
-import java.util.Optional;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-import org.onap.oom.truststoremerger.configuration.exception.TruststoresPathsProviderException;
-import org.onap.oom.truststoremerger.configuration.path.env.EnvProvider;
-
-@ExtendWith(MockitoExtension.class)
-class DelimitedPathsReaderTest {
-
- private static final String VALID_TRUSTSTORES = "/opt/app/certificates/truststore.jks:/opt/app/certificates/truststore.pem";
- private static final String VALID_TRUSTSTORES_PASSWORDS = "/opt/app/certificates/truststore.pass:";
- private static final String VALID_TRUSTSTORES_PASSWORDS_WITH_EMPTY_IN_THE_MIDDLE = "/opt/app/certificates/truststore.pass::/etc/truststore.pass";
- private static final String INVALID_TRUSTSTORES = "/opt/app/certificates/truststore.jks:/opt/app/certificates/truststore.invalid";
- private static final String INVALID_TRUSTSTORES_PASSWORDS = "/opt/app/certificates/truststore.pass:/.pass";
-
- @Mock
- private EnvProvider envProvider;
- private DelimitedPathsReader delimitedPathsReader;
-
- @Test
- void shouldReturnCorrectListWhenTruststoresValid() throws TruststoresPathsProviderException {
- // given
- delimitedPathsReader = new DelimitedPathsReader(envProvider, doesItContainValidCertificatesPaths());
- mockTruststoresEnv(VALID_TRUSTSTORES);
-
- // when, then
- assertThat(delimitedPathsReader.get(TRUSTSTORES_PATHS_ENV))
- .containsSequence("/opt/app/certificates/truststore.jks",
- "/opt/app/certificates/truststore.pem");
- }
-
- @Test
- void shouldThrowExceptionWhenTruststoresPathsEnvIsEmpty() {
- // given
- delimitedPathsReader = new DelimitedPathsReader(envProvider, doesItContainValidCertificatesPaths());
- mockTruststoresEnv("");
-
- // when, then
- assertThatExceptionOfType(TruststoresPathsProviderException.class)
- .isThrownBy(() -> delimitedPathsReader.get(TRUSTSTORES_PATHS_ENV));
- }
-
- @Test
- void shouldThrowExceptionWhenOneOfTruststoresPathsInvalid() {
- // given
- delimitedPathsReader = new DelimitedPathsReader(envProvider, doesItContainValidCertificatesPaths());
- mockTruststoresEnv(INVALID_TRUSTSTORES);
-
- // when, then
- assertThatExceptionOfType(TruststoresPathsProviderException.class)
- .isThrownBy(() -> delimitedPathsReader.get(TRUSTSTORES_PATHS_ENV));
- }
-
- @Test
- void shouldReturnCorrectListWhenTruststoresPasswordsValid() throws TruststoresPathsProviderException {
- // given
- delimitedPathsReader = new DelimitedPathsReader(envProvider, doesItContainValidPasswordPaths());
- mockTruststoresPasswordsEnv(VALID_TRUSTSTORES_PASSWORDS);
-
- // when, then
- assertThat(delimitedPathsReader.get(TRUSTSTORES_PASSWORDS_PATHS_ENV))
- .containsSequence("/opt/app/certificates/truststore.pass", "");
- }
-
- @Test
- void shouldReturnCorrectListWhenTruststoresPasswordsContainsEmptyPathsInTheMiddle()
- throws TruststoresPathsProviderException {
- // given
- delimitedPathsReader = new DelimitedPathsReader(envProvider, doesItContainValidPasswordPaths());
- mockTruststoresPasswordsEnv(VALID_TRUSTSTORES_PASSWORDS_WITH_EMPTY_IN_THE_MIDDLE);
-
- // when, then
- assertThat(delimitedPathsReader.get(TRUSTSTORES_PASSWORDS_PATHS_ENV)).containsSequence(
- "/opt/app/certificates/truststore.pass",
- "",
- "/etc/truststore.pass"
- );
- }
-
- @Test
- void shouldThrowExceptionWhenTruststoresPasswordsPathEnvIsEmpty() {
- // given
- delimitedPathsReader = new DelimitedPathsReader(envProvider, doesItContainValidPasswordPaths());
- mockTruststoresPasswordsEnv("");
-
- // when, then
- assertThatExceptionOfType(TruststoresPathsProviderException.class)
- .isThrownBy(() -> delimitedPathsReader.get(TRUSTSTORES_PASSWORDS_PATHS_ENV));
- }
-
- @Test
- void shouldThrowExceptionWhenOneOfTruststorePasswordPathsInvalid() {
- // given
- delimitedPathsReader = new DelimitedPathsReader(envProvider, doesItContainValidPasswordPaths());
- mockTruststoresPasswordsEnv(INVALID_TRUSTSTORES_PASSWORDS);
-
- // when, then
- assertThatExceptionOfType(TruststoresPathsProviderException.class)
- .isThrownBy(() -> delimitedPathsReader.get(TRUSTSTORES_PASSWORDS_PATHS_ENV));
- }
-
- private void mockTruststoresEnv(String truststores) {
- mockEnv(TRUSTSTORES_PATHS_ENV, truststores);
- }
-
- private void mockTruststoresPasswordsEnv(String truststoresPasswords) {
- mockEnv(TRUSTSTORES_PASSWORDS_PATHS_ENV, truststoresPasswords);
- }
-
- private void mockEnv(String envName, String truststores) {
- when(envProvider.getEnv(envName)).thenReturn(Optional.of(truststores));
- }
-}
diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/path/DelimitedPathsSplitterTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/path/DelimitedPathsSplitterTest.java
new file mode 100644
index 00000000..22b5a7fc
--- /dev/null
+++ b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/path/DelimitedPathsSplitterTest.java
@@ -0,0 +1,107 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * 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.oom.truststoremerger.configuration.path;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.onap.oom.truststoremerger.configuration.model.EnvVariable.TRUSTSTORES_PASSWORDS_PATHS_ENV;
+import static org.onap.oom.truststoremerger.configuration.model.EnvVariable.TRUSTSTORES_PATHS_ENV;
+
+import java.util.Optional;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.onap.oom.truststoremerger.configuration.exception.CertificatesPathsValidationException;
+
+@ExtendWith(MockitoExtension.class)
+class DelimitedPathsSplitterTest {
+
+ private static final String VALID_TRUSTSTORES = "/opt/app/certificates/truststore.jks:/opt/app/certificates/truststore.pem";
+ private static final String VALID_TRUSTSTORES_PASSWORDS = "/opt/app/certificates/truststore.pass:";
+ private static final String VALID_TRUSTSTORES_PASSWORDS_WITH_EMPTY_IN_THE_MIDDLE = "/opt/app/certificates/truststore.pass::/etc/truststore.pass";
+ private static final String INVALID_TRUSTSTORES = "/opt/app/certificates/truststore.jks:/opt/app/certificates/truststore.invalid";
+ private static final String INVALID_TRUSTSTORES_PASSWORDS = "/opt/app/certificates/truststore.pass:/.pass";
+
+ private DelimitedPathsSplitter delimitedPathsSplitter;
+
+ @BeforeEach
+ void setUp() {
+ delimitedPathsSplitter = new DelimitedPathsSplitter();
+ }
+
+ @Test
+ void shouldReturnCorrectListWhenTruststoresValid() {
+ // when, then
+ assertThat(delimitedPathsSplitter.getValidatedPaths(TRUSTSTORES_PATHS_ENV, Optional.of(VALID_TRUSTSTORES)))
+ .containsSequence("/opt/app/certificates/truststore.jks",
+ "/opt/app/certificates/truststore.pem");
+ }
+
+ @Test
+ void shouldThrowExceptionWhenTruststoresPathsEnvIsEmpty() {
+ // when, then
+ assertThatExceptionOfType(CertificatesPathsValidationException.class)
+ .isThrownBy(() -> delimitedPathsSplitter.getValidatedPaths(TRUSTSTORES_PATHS_ENV, Optional.of("")));
+ }
+
+ @Test
+ void shouldThrowExceptionWhenOneOfTruststoresPathsInvalid() {
+ // when, then
+ assertThatExceptionOfType(CertificatesPathsValidationException.class)
+ .isThrownBy(() -> delimitedPathsSplitter
+ .getValidatedPaths(TRUSTSTORES_PATHS_ENV, Optional.of(INVALID_TRUSTSTORES)));
+ }
+
+ @Test
+ void shouldReturnCorrectListWhenTruststoresPasswordsValid() {
+ // when, then
+ assertThat(delimitedPathsSplitter
+ .getValidatedPaths(TRUSTSTORES_PASSWORDS_PATHS_ENV, Optional.of(VALID_TRUSTSTORES_PASSWORDS)))
+ .containsSequence("/opt/app/certificates/truststore.pass", "");
+ }
+
+ @Test
+ void shouldReturnCorrectListWhenTruststoresPasswordsContainsEmptyPathsInTheMiddle() {
+ // when, then
+ assertThat(delimitedPathsSplitter.getValidatedPaths(TRUSTSTORES_PASSWORDS_PATHS_ENV,
+ Optional.of(VALID_TRUSTSTORES_PASSWORDS_WITH_EMPTY_IN_THE_MIDDLE))).containsSequence(
+ "/opt/app/certificates/truststore.pass",
+ "",
+ "/etc/truststore.pass"
+ );
+ }
+
+ @Test
+ void shouldThrowExceptionWhenTruststoresPasswordsPathEnvIsEmpty() {
+ // when, then
+ assertThatExceptionOfType(CertificatesPathsValidationException.class)
+ .isThrownBy(
+ () -> delimitedPathsSplitter.getValidatedPaths(TRUSTSTORES_PASSWORDS_PATHS_ENV, Optional.of("")));
+ }
+
+ @Test
+ void shouldThrowExceptionWhenOneOfTruststorePasswordPathsInvalid() {
+ // when, then
+ assertThatExceptionOfType(CertificatesPathsValidationException.class)
+ .isThrownBy(() -> delimitedPathsSplitter
+ .getValidatedPaths(TRUSTSTORES_PASSWORDS_PATHS_ENV, Optional.of(INVALID_TRUSTSTORES_PASSWORDS)));
+ }
+}
diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/path/env/EnvReaderTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/path/env/EnvReaderTest.java
new file mode 100644
index 00000000..0a654fe8
--- /dev/null
+++ b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/configuration/path/env/EnvReaderTest.java
@@ -0,0 +1,62 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * 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.oom.truststoremerger.configuration.path.env;
+
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.when;
+import static org.onap.oom.truststoremerger.configuration.model.EnvVariable.TRUSTSTORES_PASSWORDS_PATHS_ENV;
+
+import java.util.Optional;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+class EnvReaderTest {
+
+ private static final String SAMPLE_PASS_PATH = "/sample/path/trust.pass";
+ EnvReader provider;
+
+ @BeforeEach
+ void setUp() {
+ provider = Mockito.spy(EnvReader.class);
+ }
+
+ @Test
+ void shouldReturnOptionalWithEnv() {
+ // given
+ String envName = TRUSTSTORES_PASSWORDS_PATHS_ENV.name();
+ when(provider.getSystemEnv(envName)).thenReturn(Optional.of(SAMPLE_PASS_PATH));
+ // when
+ Optional<String> result = provider.getEnv(envName);
+ // then
+ assertThat(result).isEqualTo(Optional.of(SAMPLE_PASS_PATH));
+ }
+
+ @Test
+ void shouldReturnEmptyOptional() {
+ // given
+ String envName = TRUSTSTORES_PASSWORDS_PATHS_ENV.name();
+ // when
+ Optional<String> result = provider.getEnv(envName);
+ // then
+ assertThat(result).isEmpty();
+ }
+}