9fc00a42900d0b1387777e32e02bb975f44e2942
[oom/platform/cert-service.git] / trustStoreMerger / src / test / java / org / onap / oom / truststoremerger / merger / TruststoreFilesProviderTest.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
21 package org.onap.oom.truststoremerger.merger;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24
25 import java.util.Arrays;
26 import java.util.List;
27 import org.junit.jupiter.api.Test;
28 import org.onap.oom.truststoremerger.merger.exception.KeystoreInstanceException;
29 import org.onap.oom.truststoremerger.merger.exception.LoadTruststoreException;
30 import org.onap.oom.truststoremerger.merger.exception.PasswordReaderException;
31 import org.onap.oom.truststoremerger.merger.exception.TruststoreFileFactoryException;
32 import org.onap.oom.truststoremerger.merger.model.Truststore;
33 import org.onap.oom.truststoremerger.merger.model.TruststoreFactory;
34
35 class TruststoreFilesProviderTest {
36
37     private static final String TRUSTSTORE_JKS_PATH = "src/test/resources/truststore-jks.jks";
38     private static final String TRUSTSTORE_JKS_PASS_PATH = "src/test/resources/truststore-jks.pass";
39     private static final String TRUSTSTORE_P12_PATH = "src/test/resources/truststore-p12.p12";
40     private static final String TRUSTSTORE_P12_PASS_PATH = "src/test/resources/truststore-p12.pass";
41     private static final String TRUSTSTORE_PEM_PATH = "src/test/resources/truststore.pem";
42     private static final String EMPTY_PASS_PATH = "";
43
44     @Test
45     void shouldReturnTruststoreFilesList()
46         throws TruststoreFileFactoryException, PasswordReaderException, LoadTruststoreException, KeystoreInstanceException {
47         //given
48         List<String> truststorePaths = Arrays.asList(TRUSTSTORE_JKS_PATH, TRUSTSTORE_P12_PATH, TRUSTSTORE_PEM_PATH);
49         List<String> truststorePasswordPaths = Arrays
50             .asList(TRUSTSTORE_JKS_PASS_PATH, TRUSTSTORE_P12_PASS_PATH, EMPTY_PASS_PATH);
51
52         //when
53         List<Truststore> truststoreFilesList = TruststoreFilesProvider
54             .getTruststoreFiles(truststorePaths, truststorePasswordPaths);
55
56         //then
57         assertThat(truststoreFilesList.size()).isEqualTo(3);
58         TruststoreFactory.create(TRUSTSTORE_JKS_PATH, TRUSTSTORE_JKS_PASS_PATH);
59         TruststoreFactory.create(TRUSTSTORE_P12_PATH, TRUSTSTORE_P12_PASS_PATH);
60         TruststoreFactory.create(TRUSTSTORE_PEM_PATH, EMPTY_PASS_PATH);
61     }
62
63 }