Add of config for copier
[oom/platform/cert-service.git] / trustStoreMerger / src / test / java / org / onap / oom / truststoremerger / configuration / path / validation / ValidationFunctionsTest.java
1 /*============LICENSE_START=======================================================
2  * oom-truststore-merger
3  * ================================================================================
4  * Copyright (C) 2020 Nokia. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  * ============LICENSE_END=========================================================
18  */
19
20 package org.onap.oom.truststoremerger.configuration.path.validation;
21
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.onap.oom.truststoremerger.configuration.path.validation.ValidationFunctions.doesItContainValidCertificatesPaths;
25 import static org.onap.oom.truststoremerger.configuration.path.validation.ValidationFunctions.doesItContainValidPasswordPaths;
26
27 import java.util.Arrays;
28 import java.util.List;
29 import org.junit.jupiter.api.Test;
30
31 class ValidationFunctionsTest {
32
33     @Test
34     void shouldValidateWithSuccessCorrectCertificatesPaths() {
35         // given
36         List<String> certPaths = Arrays.asList("/opt/app/certificates/truststore.p12");
37         // when
38         boolean result = doesItContainValidCertificatesPaths().test(certPaths);
39         // then
40         assertThat(result).isTrue();
41     }
42
43     @Test
44     void shouldValidateWithFailureCertificatesPathsWithOneEmptyPath() {
45         // given
46         List<String> certPaths = Arrays.asList("/opt/app/certificates/truststore.p12", "");
47         // when
48         boolean result = doesItContainValidCertificatesPaths().test(certPaths);
49         // then
50         assertThat(result).isFalse();
51     }
52
53     @Test
54     void shouldValidateWithFailureCertificatesPathsWithOnePathWhichHasIncorrectExtension() {
55         // given
56         List<String> certPaths = Arrays.asList("/opt/app/certificates/truststore.txt", "/opt/cert.p12");
57         // when
58         boolean result = doesItContainValidCertificatesPaths().test(certPaths);
59         // then
60         assertThat(result).isFalse();
61     }
62
63     @Test
64     void shouldValidateWithSuccessCertificatesPasswordPaths() {
65         // given
66         List<String> passwordPaths = Arrays.asList("/opt/app/certificates/truststore.pass", "");
67         // when
68         boolean result = doesItContainValidPasswordPaths().test(passwordPaths);
69         // then
70         assertThat(result).isTrue();
71     }
72
73     @Test
74     void shouldValidateWithSuccessCertificatePasswordsPathsWhichContainsEmptyPathsInTheMiddle() {
75         // given
76         List<String> passwordPaths = Arrays.asList("/opt/app/certificates/truststore.pass", "", "/etc/truststore.pass");
77         // when
78         boolean result = doesItContainValidPasswordPaths().test(passwordPaths);
79         // then
80         assertThat(result).isTrue();
81     }
82
83     @Test
84     void shouldValidateWithFailureCertificatesPasswordsPathsWithIncorrectExtension() {
85         // given
86         List<String> passwordPaths = Arrays.asList("/pass.txt");
87         // when
88         boolean result = doesItContainValidPasswordPaths().test(passwordPaths);
89         // then
90         assertThat(result).isFalse();
91     }
92
93     @Test
94     void shouldValidateWithFailureCertificatesPasswordPathsWithMissingPrecedingSlash() {
95         // given
96         List<String> passwordPaths = Arrays.asList("jks.pass");
97         // when
98         boolean result = doesItContainValidPasswordPaths().test(passwordPaths);
99         // then
100         assertThat(result).isFalse();
101     }
102
103     @Test
104     void shouldValidateWithSuccessSourcePathsToCopyFiles() {
105         // given
106         List<String> sourcePaths = Arrays.asList("/opt/dcae/cacert/external/keystore.p12",
107             "/opt/dcae/cacert/external/keystore.pass");
108         // when
109         boolean result = ValidationFunctions.doesItContainValidPathsToCopy().test(sourcePaths);
110         // then
111         assertThat(result).isTrue();
112     }
113
114     @Test
115     void shouldValidateWithSuccessDestinationPathsToCopyFiles() {
116         // given
117         List<String> sourcePaths = Arrays.asList("/opt/dcae/cacert/cert.p12","/opt/dcae/cacert/p12.pass");
118         // when
119         boolean result = ValidationFunctions.doesItContainValidPathsToCopy().test(sourcePaths);
120         // then
121         assertThat(result).isTrue();
122     }
123
124     @Test
125     void shouldValidateWithFailureDestinationPathsWithIncorrectExtension() {
126         // given
127         List<String> sourcePaths = Arrays.asList("/opt/dcae/cacert/cert.txt","/opt/dcae/cacert/p12.other");
128         // when
129         boolean result = ValidationFunctions.doesItContainValidPathsToCopy().test(sourcePaths);
130         // then
131         assertThat(result).isFalse();
132     }
133
134 }