af77349a8e0b3c89dbd6c5621c6c4da55625576f
[nonrtric/plt/ranpm.git] / datafilecollector / src / test / java / org / oran / datafile / http / HttpsClientConnectionManagerUtilTest.java
1 /*-
2  * ============LICENSE_START======================================================================
3  * Copyright (C) 2018-2023 Nordix Foundation. All rights reserved.
4  * Copyright (C) 2021 Nokia. All rights reserved.
5  * ===============================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7  * in compliance with the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software distributed under the License
12  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13  * or implied. See the License for the specific language governing permissions and limitations under
14  * the License.
15  * ============LICENSE_END========================================================================
16  */
17 package org.oran.datafile.http;
18
19 import static org.junit.jupiter.api.Assertions.assertNotNull;
20 import static org.junit.jupiter.api.Assertions.assertThrows;
21
22 import org.junit.jupiter.api.Test;
23 import org.junit.jupiter.api.extension.ExtendWith;
24 import org.mockito.junit.jupiter.MockitoExtension;
25 import org.oran.datafile.exceptions.DatafileTaskException;
26
27 @ExtendWith(MockitoExtension.class)
28 public class HttpsClientConnectionManagerUtilTest {
29
30     private static final String KEY_PATH = "src/test/resources/keystore.p12";
31     private static final String KEY_PASSWORD = "src/test/resources/keystore.pass";
32     private static final String KEY_IMPROPER_PASSWORD = "src/test/resources/dfc.jks.pass";
33     private static final String TRUSTED_CA_PATH = "src/test/resources/trust.jks";
34     private static final String TRUSTED_CA_PASSWORD = "src/test/resources/trust.pass";
35
36     @Test
37     public void emptyManager_shouldThrowException() {
38         assertThrows(DatafileTaskException.class, () -> HttpsClientConnectionManagerUtil.instance());
39     }
40
41     @Test
42     public void creatingManager_successfulCase() throws Exception {
43         HttpsClientConnectionManagerUtil.setupOrUpdate(KEY_PATH, KEY_PASSWORD, TRUSTED_CA_PATH, TRUSTED_CA_PASSWORD, //
44             true);
45         assertNotNull(HttpsClientConnectionManagerUtil.instance());
46     }
47
48     @Test
49     public void creatingManager_improperSecretShouldThrowException() {
50         assertThrows(DatafileTaskException.class, () -> HttpsClientConnectionManagerUtil.setupOrUpdate(KEY_PATH, //
51             KEY_IMPROPER_PASSWORD, TRUSTED_CA_PATH, TRUSTED_CA_PASSWORD, true));
52         assertThrows(DatafileTaskException.class, () -> HttpsClientConnectionManagerUtil.instance());
53     }
54
55 }