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