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
10 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.oom.certservice.postprocessor.merger.model;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
26 import org.junit.jupiter.api.Test;
27 import org.junit.jupiter.api.extension.ExtendWith;
28 import org.mockito.junit.jupiter.MockitoExtension;
29 import org.onap.oom.certservice.postprocessor.merger.exception.KeystoreInstanceException;
30 import org.onap.oom.certservice.postprocessor.merger.exception.LoadTruststoreException;
31 import org.onap.oom.certservice.postprocessor.merger.exception.PasswordReaderException;
32 import org.onap.oom.certservice.postprocessor.merger.exception.TruststoreFileFactoryException;
34 @ExtendWith(MockitoExtension.class)
35 class TruststoreFactoryTest {
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 private static final String TRUSTSTORE_UNKNOWN_EXTENSION_PATH = "src/test/resources/truststore-jks.unknown";
44 private static final String NON_EXISTING_TRUSTSTORE_PATH = "src/test/resources/non-existing-truststore.jks";
47 void shouldReturnCorrectJksTruststoreForJksFile()
48 throws LoadTruststoreException, PasswordReaderException, TruststoreFileFactoryException, KeystoreInstanceException {
50 Truststore truststore = TruststoreFactory
51 .create(TRUSTSTORE_JKS_PATH, TRUSTSTORE_JKS_PASS_PATH);
54 assertThat(truststore).isInstanceOf(Truststore.class);
58 void shouldReturnCorrectP12TruststoreForP12File()
59 throws LoadTruststoreException, PasswordReaderException, TruststoreFileFactoryException, KeystoreInstanceException {
61 Truststore truststore = TruststoreFactory
62 .create(TRUSTSTORE_P12_PATH, TRUSTSTORE_P12_PASS_PATH);
65 assertThat(truststore).isInstanceOf(Truststore.class);
69 void shouldReturnCorrectPemTruststoreForPemFile()
70 throws LoadTruststoreException, PasswordReaderException, TruststoreFileFactoryException, KeystoreInstanceException {
72 Truststore truststore = TruststoreFactory
73 .create(TRUSTSTORE_PEM_PATH,
77 assertThat(truststore).isInstanceOf(Truststore.class);
81 void shouldThrowExceptionForInvalidP12PassPath() {
82 assertThatExceptionOfType(PasswordReaderException.class).isThrownBy(
83 () -> TruststoreFactory.create(TRUSTSTORE_P12_PATH, EMPTY_PASS_PATH)
88 void shouldThrowExceptionForInvalidJksPassPath() {
89 assertThatExceptionOfType(PasswordReaderException.class).isThrownBy(
90 () -> TruststoreFactory.create(TRUSTSTORE_JKS_PATH, EMPTY_PASS_PATH)
95 void shouldThrowExceptionForUnknownTruststoreExtension() {
96 assertThatExceptionOfType(TruststoreFileFactoryException.class).isThrownBy(
97 () -> TruststoreFactory
98 .create(TRUSTSTORE_UNKNOWN_EXTENSION_PATH, TRUSTSTORE_JKS_PASS_PATH)
103 void shouldThrowExceptionForNonExistingTruststoreFile() {
104 assertThatExceptionOfType(TruststoreFileFactoryException.class).isThrownBy(
105 () -> TruststoreFactory.create(NON_EXISTING_TRUSTSTORE_PATH, TRUSTSTORE_JKS_PASS_PATH)