2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 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.portalapp.portal.service;
40 import static org.junit.Assert.assertFalse;
41 import static org.junit.Assert.assertTrue;
43 import java.util.ArrayList;
44 import java.util.List;
46 import javax.servlet.http.HttpServletRequest;
47 import javax.servlet.http.HttpServletResponse;
49 import org.junit.Before;
50 import org.junit.Test;
51 import org.junit.runner.RunWith;
52 import org.mockito.InjectMocks;
53 import org.mockito.Mock;
54 import org.mockito.Mockito;
55 import org.mockito.MockitoAnnotations;
56 import org.onap.portalapp.portal.domain.EPApp;
57 import org.onap.portalapp.portal.framework.MockitoTestSuite;
58 import org.onap.portalapp.service.RemoteWebServiceCallServiceImpl;
59 import org.onap.portalsdk.core.onboarding.util.CipherUtil;
60 import org.onap.portalsdk.core.service.DataAccessService;
61 import org.onap.portalsdk.core.util.SystemProperties;
62 import org.powermock.api.mockito.PowerMockito;
63 import org.powermock.core.classloader.annotations.PrepareForTest;
64 import org.powermock.modules.junit4.PowerMockRunner;
66 @RunWith(PowerMockRunner.class)
67 @PrepareForTest({ CipherUtil.class , SystemProperties.class})
68 public class RemoteWebServiceCallServiceImplTest {
72 RemoteWebServiceCallServiceImpl remoteWebServiceCallServiceImpl = new RemoteWebServiceCallServiceImpl();
75 AppsCacheService appCacheService;
78 DataAccessService dataAccessService;
82 MockitoAnnotations.initMocks(this);
85 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
87 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
88 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
90 NullPointerException nullPointerException = new NullPointerException();
93 public void verifyRESTCredentialTest() throws Exception
95 PowerMockito.mockStatic(CipherUtil.class);
96 PowerMockito.mockStatic(SystemProperties.class);
97 String criteria= " where ueb_key = 'requestUebKey'";
98 List<EPApp> appList = new ArrayList<>();
99 EPApp app = new EPApp();
100 app.setAppBasicAuthPassword("password");
102 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList);
103 String secretKey = null;
104 Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey);
105 Mockito.when(CipherUtil.decryptPKC("password",
106 secretKey == null ? null : secretKey)).thenReturn("pwd");
107 assertFalse(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","requestPassword"));
111 public void verifyRESTCredentialExceptionTest() throws Exception
113 PowerMockito.mockStatic(CipherUtil.class);
114 PowerMockito.mockStatic(SystemProperties.class);
115 String criteria= " where ueb_key = 'requestUebKey'";
116 List<EPApp> appList = new ArrayList<>();
117 EPApp app = new EPApp();
118 app.setAppBasicAuthPassword("password");
119 app.setAppBasicAuthUsername("requestAppName");
121 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList);
122 String secretKey = null;
123 Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey);
124 Mockito.when(CipherUtil.decryptPKC("password",
125 secretKey == null ? null : secretKey)).thenReturn("pwd");
126 assertTrue(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","pwd"));
130 public void verifyRESTCredentialIfAppNullTest() throws Exception
132 PowerMockito.mockStatic(CipherUtil.class);
133 PowerMockito.mockStatic(SystemProperties.class);
134 String criteria= " where ueb_key = 'requestUebKey'";
135 List<EPApp> appList = new ArrayList<>();
136 EPApp app = new EPApp();
137 app.setAppBasicAuthPassword("password");
138 app.setAppBasicAuthUsername("requestAppName");
140 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(null);
141 String secretKey = null;
142 Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey);
143 Mockito.when(CipherUtil.decryptPKC("password",
144 secretKey == null ? null : secretKey)).thenReturn("pwd");
145 assertFalse(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","pwd"));
149 public void verifyAppKeyCredentialIfKeyIsNullTest() throws Exception
151 assertFalse(remoteWebServiceCallServiceImpl.verifyAppKeyCredential(null));
155 public void verifyAppKeyCredentialTest() throws Exception
157 PowerMockito.mockStatic(CipherUtil.class);
158 PowerMockito.mockStatic(SystemProperties.class);
159 StringBuffer criteria = new StringBuffer("where ueb_key = 'requestUebKey'");
160 // String criteria= " where ueb_key = 'requestUebKey'";
161 List<EPApp> appList = new ArrayList<>();
162 EPApp app = new EPApp();
163 app.setAppBasicAuthPassword("password");
164 app.setAppBasicAuthUsername("requestAppName");
166 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(null);
167 assertFalse(remoteWebServiceCallServiceImpl.verifyAppKeyCredential("test"));
171 public void verifyAppKeyCredentialSuccessTest() throws Exception
173 PowerMockito.mockStatic(CipherUtil.class);
174 PowerMockito.mockStatic(SystemProperties.class);
175 String criteria= " where ueb_key = 'test'";
176 List<EPApp> appList = new ArrayList<>();
177 EPApp app = new EPApp();
178 app.setAppBasicAuthPassword("password");
179 app.setAppBasicAuthUsername("requestAppName");
181 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList);
182 assertTrue(remoteWebServiceCallServiceImpl.verifyAppKeyCredential("test"));