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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
14 * ============LICENSE_END========================================================================
16 package org.onap.dcaegen2.collectors.datafile.http;
18 import static org.junit.jupiter.api.Assertions.assertNotNull;
19 import static org.junit.jupiter.api.Assertions.assertThrows;
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;
26 @ExtendWith(MockitoExtension.class)
27 public class HttpsClientConnectionManagerUtilTest {
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";
36 public void emptyManager_shouldThrowException() {
37 assertThrows(DatafileTaskException.class, () -> HttpsClientConnectionManagerUtil.instance());
41 public void creatingManager_successfulCase() throws Exception {
42 HttpsClientConnectionManagerUtil.setupOrUpdate(KEY_PATH, KEY_PASSWORD, TRUSTED_CA_PATH, TRUSTED_CA_PASSWORD, //
44 assertNotNull(HttpsClientConnectionManagerUtil.instance());
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());