ce957ab671a356904611ff5ecd71b41146a1b330
[vid.git] / vid-app-common / src / test / java / org / onap / vid / aai / util / HttpsAuthClientTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2018 Nokia. All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.vid.aai.util;
23
24 import org.junit.runner.RunWith;
25 import org.mockito.Mock;
26 import org.mockito.junit.MockitoJUnitRunner;
27
28 import javax.net.ssl.SSLContext;
29
30 @RunWith(MockitoJUnitRunner.class)
31 public class HttpsAuthClientTest {
32     @Mock
33     private SystemPropertyHelper systemPropertyHelper;
34     @Mock
35     private SSLContextProvider sslContextProvider;
36     @Mock
37     private SSLContext sslContext;
38
39     public static final String CERT_FILE_PATH = "any_path";
40
41     /*
42     TO BE IMPLEMENTED
43     
44     private HttpsAuthClient createTestSubject() {
45         return new HttpsAuthClient(systemPropertyHelper, sslContextProvider);
46     }
47
48     @Before
49     public void setUp() throws Exception {
50         when(systemPropertyHelper.getAAITruststoreFilename()).thenReturn(Optional.of("filename"));
51         when(systemPropertyHelper.getEncodedTruststorePassword()).thenReturn("password");
52     }
53
54     @Test(expected = HttpClientBuilderException.class)
55     public void testHttpClientBuilderExceptionOnGetClient() throws HttpClientBuilderException {
56         //when
57         when(systemPropertyHelper.getAAIUseClientCert()).thenReturn(Optional.of("true"));
58         when(sslContextProvider.getSslContext(anyString(), anyString())).thenThrow(new HttpClientBuilderException());
59         createTestSubject().getClient("nonExistingFile");
60     }
61
62     @Test
63     public void testGetSecuredClient() throws Exception {
64         // when
65         when(systemPropertyHelper.getAAIUseClientCert()).thenReturn(Optional.of("true"));
66         when(sslContextProvider.getSslContext(anyString(), anyString())).thenReturn(sslContext);
67         createTestSubject().getClient(CERT_FILE_PATH);
68
69         //then
70         verify(sslContextProvider).getSslContext(anyString(), anyString());
71     }
72
73     @Test
74     public void testGetUnsecuredClient() throws Exception {
75         // when
76         when(systemPropertyHelper.getAAIUseClientCert()).thenReturn(Optional.of("false"));
77         when(sslContextProvider.getSslContext(anyString(), anyString())).thenReturn(sslContext);
78         createTestSubject().getClient(CERT_FILE_PATH);
79
80         //then
81         verify(sslContextProvider, never()).getSslContext(anyString(), anyString());
82     }
83     */
84 }