2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia. 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.openecomp.sdc.common.http.client.api;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.Mock;
26 import org.mockito.Mockito;
27 import org.mockito.junit.MockitoJUnitRunner;
28 import org.onap.sdc.security.SecurityUtil;
29 import org.openecomp.sdc.common.http.config.BasicAuthorization;
30 import org.openecomp.sdc.common.http.config.ClientCertificate;
31 import org.openecomp.sdc.common.http.config.HttpClientConfig;
32 import org.openecomp.sdc.common.http.config.Timeouts;
34 import java.util.Collections;
37 import static junit.framework.TestCase.assertNotNull;
39 @RunWith(MockitoJUnitRunner.class)
40 public class HttpClientFactoryTest {
43 HttpConnectionMngFactory httpConnectionMngFactory;
46 public void validateNewClientCreationReturnsValidClient() throws HttpExecuteException {
47 HttpClient httpClient = new HttpClientFactory(httpConnectionMngFactory).createClient("Http",prepareTestClientConfigImmutable());
48 assertNotNull(httpClient);
52 private HttpClientConfigImmutable prepareTestClientConfigImmutable() {
53 final String testUserName = "testUser";
54 final String testUserPassword = SecurityUtil.encrypt("testPassword").left().value();
55 final int timeouts = 10;
56 final String testKeyStore = "testKeyStore";
57 final String testKeyStorePassword = SecurityUtil.encrypt("testKeyStorePassword").left().value();
59 int testNumOfRetries = 10;
60 ComparableHttpRequestRetryHandler testRetryHandler = Mockito.mock(ComparableHttpRequestRetryHandler.class);
61 Map<String, String> testHeaders = Collections.emptyMap();
62 Timeouts testTimeouts = new Timeouts(timeouts, timeouts);
63 testTimeouts.setConnectPoolTimeoutMs(timeouts);
64 BasicAuthorization testBasicAuthorization = new BasicAuthorization();
65 testBasicAuthorization.setUserName(testUserName);
66 testBasicAuthorization.setPassword(testUserPassword);
67 ClientCertificate testClientCertificate = new ClientCertificate();
68 testClientCertificate.setKeyStore(testKeyStore);
69 testClientCertificate.setKeyStorePassword(testKeyStorePassword);
71 HttpClientConfig httpClientConfig = new HttpClientConfig();
72 httpClientConfig.setNumOfRetries(testNumOfRetries);
73 httpClientConfig.setTimeouts(testTimeouts);
74 httpClientConfig.setBasicAuthorization(testBasicAuthorization);
75 httpClientConfig.setClientCertificate(testClientCertificate);
76 httpClientConfig.setRetryHandler(testRetryHandler);
77 httpClientConfig.setHeaders(testHeaders);
79 return new HttpClientConfigImmutable(httpClientConfig);