2 * ============LICENSE_START=======================================================
3 * PNF-REGISTRATION-HANDLER
4 * ================================================================================
5 * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.dcaegen2.services.prh.service;
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.verify;
25 import static org.mockito.Mockito.when;
27 import javax.net.ssl.SSLException;
28 import org.junit.jupiter.api.Assertions;
29 import org.junit.jupiter.api.Test;
30 import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
31 import org.onap.dcaegen2.services.prh.ssl.SslFactory;
34 class AaiReactiveWebClientFactoryTest {
36 private static final String TRUST_STORE_PATH = "trust_store_path";
37 private static final String TRUST_STORE_PASS_PATH = "trust_store_pass_path";
38 private static final String KEY_STORE_PATH = "key_store_path";
39 private static final String KEY_STORE_PASS_PATH = "key_store_pass_path";
40 private SslFactory sslFactory = mock(SslFactory.class);
41 private AaiClientConfiguration aaiClientConfiguration = mock(AaiClientConfiguration.class);
42 private AaiReactiveWebClientFactory aaiReactiveWebClientFactory;
45 void shouldCreateWebClientWithSecureSslContext() throws SSLException {
46 givenEnabledAaiCertAuthConfiguration();
47 aaiReactiveWebClientFactory = new AaiReactiveWebClientFactory(sslFactory, aaiClientConfiguration);
49 Assertions.assertNotNull(aaiReactiveWebClientFactory.build());
50 verify(sslFactory).createSecureContext(KEY_STORE_PATH, KEY_STORE_PASS_PATH,
51 TRUST_STORE_PATH, TRUST_STORE_PASS_PATH);
55 void shouldCreateWebClientWithInsecureSslContext() throws SSLException {
56 when(aaiClientConfiguration.enableAaiCertAuth()).thenReturn(false);
57 aaiReactiveWebClientFactory = new AaiReactiveWebClientFactory(sslFactory, aaiClientConfiguration);
59 Assertions.assertNotNull(aaiReactiveWebClientFactory.build());
60 verify(sslFactory).createInsecureContext();
63 private void givenEnabledAaiCertAuthConfiguration() {
64 when(aaiClientConfiguration.enableAaiCertAuth()).thenReturn(true);
65 when(aaiClientConfiguration.trustStorePath()).thenReturn(TRUST_STORE_PATH);
66 when(aaiClientConfiguration.trustStorePasswordPath()).thenReturn(TRUST_STORE_PASS_PATH);
67 when(aaiClientConfiguration.keyStorePath()).thenReturn(KEY_STORE_PATH);
68 when(aaiClientConfiguration.keyStorePasswordPath()).thenReturn(KEY_STORE_PASS_PATH);