Merge "UI Feature flagging support"
[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.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.Mock;
28 import org.mockito.Mockito;
29 import org.mockito.runners.MockitoJUnitRunner;
30 import org.onap.vid.aai.exceptions.HttpClientBuilderException;
31
32 import javax.net.ssl.SSLContext;
33 import java.util.Optional;
34
35 import static org.mockito.Matchers.anyString;
36 import static org.mockito.Mockito.never;
37 import static org.mockito.Mockito.verify;
38 import static org.mockito.Mockito.when;
39
40 @RunWith(MockitoJUnitRunner.class)
41 public class HttpsAuthClientTest {
42     @Mock
43     private SystemPropertyHelper systemPropertyHelper;
44     @Mock
45     private SSLContextProvider sslContextProvider;
46     @Mock
47     private SSLContext sslContext;
48
49     public static final String CERT_FILE_PATH = "any_path";
50
51     /*
52     TO BE IMPLEMENTED
53     
54     private HttpsAuthClient createTestSubject() {
55         return new HttpsAuthClient(systemPropertyHelper, sslContextProvider);
56     }
57
58     @Before
59     public void setUp() throws Exception {
60         when(systemPropertyHelper.getAAITruststoreFilename()).thenReturn(Optional.of("filename"));
61         when(systemPropertyHelper.getEncodedTruststorePassword()).thenReturn("password");
62     }
63
64     @Test(expected = HttpClientBuilderException.class)
65     public void testHttpClientBuilderExceptionOnGetClient() throws HttpClientBuilderException {
66         //when
67         when(systemPropertyHelper.getAAIUseClientCert()).thenReturn(Optional.of("true"));
68         when(sslContextProvider.getSslContext(anyString(), anyString())).thenThrow(new HttpClientBuilderException());
69         createTestSubject().getClient("nonExistingFile");
70     }
71
72     @Test
73     public void testGetSecuredClient() throws Exception {
74         // when
75         when(systemPropertyHelper.getAAIUseClientCert()).thenReturn(Optional.of("true"));
76         when(sslContextProvider.getSslContext(anyString(), anyString())).thenReturn(sslContext);
77         createTestSubject().getClient(CERT_FILE_PATH);
78
79         //then
80         verify(sslContextProvider).getSslContext(anyString(), anyString());
81     }
82
83     @Test
84     public void testGetUnsecuredClient() throws Exception {
85         // when
86         when(systemPropertyHelper.getAAIUseClientCert()).thenReturn(Optional.of("false"));
87         when(sslContextProvider.getSslContext(anyString(), anyString())).thenReturn(sslContext);
88         createTestSubject().getClient(CERT_FILE_PATH);
89
90         //then
91         verify(sslContextProvider, never()).getSslContext(anyString(), anyString());
92     }
93     */
94 }