2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
26 * https://creativecommons.org/licenses/by/4.0/
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.
34 * ============LICENSE_END============================================
38 package org.onap.portalsdk.core.service;
40 import java.util.ArrayList;
41 import java.util.List;
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;
56 @RunWith(PowerMockRunner.class)
57 @PrepareForTest({CipherUtil.class, SystemProperties.class})
58 public class WebServiceCallServiceImplTest {
61 private WebServiceCallServiceImpl webServiceCallServiceImpl;
64 private DataAccessService dataAccessService;
67 private AppService appService;
71 public void verifyRESTCredentialTrueTest() throws Exception {
72 String secretKey = "Key";
73 String requestAppName = "App";
74 String requestPassword = "Password";
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);
88 public void verifyRESTCredentialFalseTest() throws Exception {
89 String secretKey = "Key";
90 String requestAppName = "App";
91 String requestPassword = "Password";
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);
105 public void findAppWithNullTest() {
106 App app = webServiceCallServiceImpl.findApp();
107 Assert.assertNull(app);
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);
118 public void findAppTest() {
119 List list = new ArrayList();
122 Mockito.when(dataAccessService.getList(App.class, " where id = 1", null, null)).thenReturn(list);
123 App returnApp = webServiceCallServiceImpl.findApp();
124 Assert.assertNotNull(returnApp);