03eeea773a17aad0400cf069e372fc5aee0af351
[portal/sdk.git] /
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalsdk.core.service;
39
40 import java.util.ArrayList;
41 import java.util.List;
42
43 import org.junit.Assert;
44 import org.junit.Test;
45 import org.junit.runner.RunWith;
46 import org.mockito.InjectMocks;
47 import org.mockito.Mock;
48 import org.mockito.Mockito;
49 import org.onap.portalsdk.core.domain.App;
50 import org.onap.portalsdk.core.onboarding.util.CipherUtil;
51 import org.onap.portalsdk.core.util.SystemProperties;
52 import org.powermock.api.mockito.PowerMockito;
53 import org.powermock.core.classloader.annotations.PrepareForTest;
54 import org.powermock.modules.junit4.PowerMockRunner;
55
56 @RunWith(PowerMockRunner.class)
57 @PrepareForTest({CipherUtil.class, SystemProperties.class})
58 public class WebServiceCallServiceImplTest {
59
60         @InjectMocks
61         private WebServiceCallServiceImpl webServiceCallServiceImpl;
62         
63         @Mock
64         private DataAccessService dataAccessService;
65
66         @Mock
67         private AppService appService;
68         
69
70         @Test
71         public void verifyRESTCredentialTrueTest() throws Exception {
72                 String secretKey =  "Key";
73                 String requestAppName = "App";
74                 String requestPassword = "Password";
75                 App app = new App();
76                 app.setAppPassword(requestPassword);
77                 app.setUsername(requestAppName);
78                 Mockito.when(appService.getDefaultApp()).thenReturn(app);
79                 PowerMockito.mockStatic(CipherUtil.class);
80                 PowerMockito.mockStatic(SystemProperties.class);
81                 Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey);
82                 Mockito.when(CipherUtil.decryptPKC(Mockito.anyString(), Mockito.anyString())).thenReturn(requestPassword);
83                 webServiceCallServiceImpl.verifyRESTCredential(secretKey, requestAppName, requestPassword);
84                 Assert.assertTrue(true);
85         }
86         
87         @Test
88         public void verifyRESTCredentialFalseTest() throws Exception {
89                 String secretKey =  "Key";
90                 String requestAppName = "App";
91                 String requestPassword = "Password";
92                 App app = new App();
93                 app.setAppPassword("Password");
94                 app.setUsername("USER");
95                 Mockito.when(appService.getDefaultApp()).thenReturn(app);
96                 PowerMockito.mockStatic(CipherUtil.class);
97                 PowerMockito.mockStatic(SystemProperties.class);
98                 Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn("Key");
99                 Mockito.when(CipherUtil.decryptPKC(Mockito.anyString(), Mockito.anyString())).thenReturn("Key");
100                 webServiceCallServiceImpl.verifyRESTCredential(secretKey, requestAppName, requestPassword);
101                 Assert.assertFalse(false);
102         }
103         
104         @Test
105         public void findAppWithNullTest() {
106                 App app = webServiceCallServiceImpl.findApp();
107                 Assert.assertNull(app);
108         }
109         
110         @Test
111         public void findAppWithEmptyTest() {
112                 Mockito.when(dataAccessService.getList(App.class, " where id = 1", null, null)).thenReturn(new ArrayList());
113                 App app = webServiceCallServiceImpl.findApp();
114                 Assert.assertNull(app);
115         }
116
117         @Test
118         public void findAppTest() {
119                 List list = new ArrayList();
120                 App app = new App();
121                 list.add(app);
122                 Mockito.when(dataAccessService.getList(App.class, " where id = 1", null, null)).thenReturn(list);
123                 App returnApp = webServiceCallServiceImpl.findApp();
124                 Assert.assertNotNull(returnApp);
125         }
126         
127 }